dbTalk Databases Forums  

Static Select statements

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Static Select statements in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
sybrandb@hccnet.nl
 
Posts: n/a

Default Re: Static Select statements - 04-03-2008 , 05:28 PM






On Mon, 31 Mar 2008 05:03:21 -0400, Ubiquitous <weberm (AT) polaris (DOT) net>
wrote:

Quote:
bigbuck714 (AT) aol (DOT) com wrote:
On Mar 28, 3:19*pm, Ubiquitous <web... (AT) polaris (DOT) net> wrote:

Is there a way to force a static row in a SELECT statement?

For example, I have a SELECT statement which is a UNION of two identical
tables, "A" and "B". How would one create a column which identifies the
source table?

TABLE NAME REC#
----- ---- ----
A * * Bob *001
A * * Tim *002
B * * Joe *001
A * * Sue *003

This should work:

Select 'A' as 'TABLE', name, recno
from a
UNION
select 'B' as 'TABLE', name, recno
from b

Thank you! That's exactly what I was seeking!
The 'TABLE' literal should be enclosed with double quoyes ("), however.
Incorrect.

Sybrand Bakker
Senior Oracle DBA


Reply With Quote
  #12  
Old   
sybrandb@hccnet.nl
 
Posts: n/a

Default Re: Static Select statements - 04-03-2008 , 05:28 PM






On Mon, 31 Mar 2008 05:03:21 -0400, Ubiquitous <weberm (AT) polaris (DOT) net>
wrote:

Quote:
bigbuck714 (AT) aol (DOT) com wrote:
On Mar 28, 3:19*pm, Ubiquitous <web... (AT) polaris (DOT) net> wrote:

Is there a way to force a static row in a SELECT statement?

For example, I have a SELECT statement which is a UNION of two identical
tables, "A" and "B". How would one create a column which identifies the
source table?

TABLE NAME REC#
----- ---- ----
A * * Bob *001
A * * Tim *002
B * * Joe *001
A * * Sue *003

This should work:

Select 'A' as 'TABLE', name, recno
from a
UNION
select 'B' as 'TABLE', name, recno
from b

Thank you! That's exactly what I was seeking!
The 'TABLE' literal should be enclosed with double quoyes ("), however.
Incorrect.

Sybrand Bakker
Senior Oracle DBA


Reply With Quote
  #13  
Old   
sybrandb@hccnet.nl
 
Posts: n/a

Default Re: Static Select statements - 04-03-2008 , 05:28 PM



On Mon, 31 Mar 2008 05:03:21 -0400, Ubiquitous <weberm (AT) polaris (DOT) net>
wrote:

Quote:
bigbuck714 (AT) aol (DOT) com wrote:
On Mar 28, 3:19*pm, Ubiquitous <web... (AT) polaris (DOT) net> wrote:

Is there a way to force a static row in a SELECT statement?

For example, I have a SELECT statement which is a UNION of two identical
tables, "A" and "B". How would one create a column which identifies the
source table?

TABLE NAME REC#
----- ---- ----
A * * Bob *001
A * * Tim *002
B * * Joe *001
A * * Sue *003

This should work:

Select 'A' as 'TABLE', name, recno
from a
UNION
select 'B' as 'TABLE', name, recno
from b

Thank you! That's exactly what I was seeking!
The 'TABLE' literal should be enclosed with double quoyes ("), however.
Incorrect.

Sybrand Bakker
Senior Oracle DBA


Reply With Quote
  #14  
Old   
Shakespeare
 
Posts: n/a

Default Re: Static Select statements - 04-04-2008 , 02:52 AM




<sybrandb (AT) hccnet (DOT) nl> schreef in bericht
news:ifmav3thsi29mtldvscrpdr85a6ccs624s (AT) 4ax (DOT) com...
Quote:
On Mon, 31 Mar 2008 05:03:21 -0400, Ubiquitous <weberm (AT) polaris (DOT) net
wrote:

bigbuck714 (AT) aol (DOT) com wrote:
On Mar 28, 3:19 pm, Ubiquitous <web... (AT) polaris (DOT) net> wrote:

Is there a way to force a static row in a SELECT statement?

For example, I have a SELECT statement which is a UNION of two
identical
tables, "A" and "B". How would one create a column which identifies the
source table?

TABLE NAME REC#
----- ---- ----
A Bob 001
A Tim 002
B Joe 001
A Sue 003

This should work:

Select 'A' as 'TABLE', name, recno
from a
UNION
select 'B' as 'TABLE', name, recno
from b

Thank you! That's exactly what I was seeking!
The 'TABLE' literal should be enclosed with double quoyes ("), however.

Incorrect.

Sybrand Bakker
Senior Oracle DBA
No, it is correct.

"TABLE" should be in double qoutes indeed, because it is a reserved word.
Normally, the column alias should be either without quotes, or with double
quotes. Single quotes don't work here.

SQL> select 'a' as "table", 1 from dual;

t 1
- ----------
a 1

SQL> select 'a' as table, 1 from dual;
select 'a' as table, 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL> select 'a' as 'table', 1 from dual;
select 'a' as 'table', 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL> select 'a' as non_reserved_word, 1 from dual;

N 1
- ----------
a 1

SQL> select 'a' as "non_reserved_word", 1 from dual;

n 1
- ----------
a 1

SQL> select 'a' as 'non_reserved_word', 1 from dual;
select 'a' as 'non_reserved_word', 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL>

Shakespeare




Reply With Quote
  #15  
Old   
Shakespeare
 
Posts: n/a

Default Re: Static Select statements - 04-04-2008 , 02:52 AM




<sybrandb (AT) hccnet (DOT) nl> schreef in bericht
news:ifmav3thsi29mtldvscrpdr85a6ccs624s (AT) 4ax (DOT) com...
Quote:
On Mon, 31 Mar 2008 05:03:21 -0400, Ubiquitous <weberm (AT) polaris (DOT) net
wrote:

bigbuck714 (AT) aol (DOT) com wrote:
On Mar 28, 3:19 pm, Ubiquitous <web... (AT) polaris (DOT) net> wrote:

Is there a way to force a static row in a SELECT statement?

For example, I have a SELECT statement which is a UNION of two
identical
tables, "A" and "B". How would one create a column which identifies the
source table?

TABLE NAME REC#
----- ---- ----
A Bob 001
A Tim 002
B Joe 001
A Sue 003

This should work:

Select 'A' as 'TABLE', name, recno
from a
UNION
select 'B' as 'TABLE', name, recno
from b

Thank you! That's exactly what I was seeking!
The 'TABLE' literal should be enclosed with double quoyes ("), however.

Incorrect.

Sybrand Bakker
Senior Oracle DBA
No, it is correct.

"TABLE" should be in double qoutes indeed, because it is a reserved word.
Normally, the column alias should be either without quotes, or with double
quotes. Single quotes don't work here.

SQL> select 'a' as "table", 1 from dual;

t 1
- ----------
a 1

SQL> select 'a' as table, 1 from dual;
select 'a' as table, 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL> select 'a' as 'table', 1 from dual;
select 'a' as 'table', 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL> select 'a' as non_reserved_word, 1 from dual;

N 1
- ----------
a 1

SQL> select 'a' as "non_reserved_word", 1 from dual;

n 1
- ----------
a 1

SQL> select 'a' as 'non_reserved_word', 1 from dual;
select 'a' as 'non_reserved_word', 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL>

Shakespeare




Reply With Quote
  #16  
Old   
Shakespeare
 
Posts: n/a

Default Re: Static Select statements - 04-04-2008 , 02:52 AM




<sybrandb (AT) hccnet (DOT) nl> schreef in bericht
news:ifmav3thsi29mtldvscrpdr85a6ccs624s (AT) 4ax (DOT) com...
Quote:
On Mon, 31 Mar 2008 05:03:21 -0400, Ubiquitous <weberm (AT) polaris (DOT) net
wrote:

bigbuck714 (AT) aol (DOT) com wrote:
On Mar 28, 3:19 pm, Ubiquitous <web... (AT) polaris (DOT) net> wrote:

Is there a way to force a static row in a SELECT statement?

For example, I have a SELECT statement which is a UNION of two
identical
tables, "A" and "B". How would one create a column which identifies the
source table?

TABLE NAME REC#
----- ---- ----
A Bob 001
A Tim 002
B Joe 001
A Sue 003

This should work:

Select 'A' as 'TABLE', name, recno
from a
UNION
select 'B' as 'TABLE', name, recno
from b

Thank you! That's exactly what I was seeking!
The 'TABLE' literal should be enclosed with double quoyes ("), however.

Incorrect.

Sybrand Bakker
Senior Oracle DBA
No, it is correct.

"TABLE" should be in double qoutes indeed, because it is a reserved word.
Normally, the column alias should be either without quotes, or with double
quotes. Single quotes don't work here.

SQL> select 'a' as "table", 1 from dual;

t 1
- ----------
a 1

SQL> select 'a' as table, 1 from dual;
select 'a' as table, 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL> select 'a' as 'table', 1 from dual;
select 'a' as 'table', 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL> select 'a' as non_reserved_word, 1 from dual;

N 1
- ----------
a 1

SQL> select 'a' as "non_reserved_word", 1 from dual;

n 1
- ----------
a 1

SQL> select 'a' as 'non_reserved_word', 1 from dual;
select 'a' as 'non_reserved_word', 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL>

Shakespeare




Reply With Quote
  #17  
Old   
Shakespeare
 
Posts: n/a

Default Re: Static Select statements - 04-04-2008 , 02:52 AM




<sybrandb (AT) hccnet (DOT) nl> schreef in bericht
news:ifmav3thsi29mtldvscrpdr85a6ccs624s (AT) 4ax (DOT) com...
Quote:
On Mon, 31 Mar 2008 05:03:21 -0400, Ubiquitous <weberm (AT) polaris (DOT) net
wrote:

bigbuck714 (AT) aol (DOT) com wrote:
On Mar 28, 3:19 pm, Ubiquitous <web... (AT) polaris (DOT) net> wrote:

Is there a way to force a static row in a SELECT statement?

For example, I have a SELECT statement which is a UNION of two
identical
tables, "A" and "B". How would one create a column which identifies the
source table?

TABLE NAME REC#
----- ---- ----
A Bob 001
A Tim 002
B Joe 001
A Sue 003

This should work:

Select 'A' as 'TABLE', name, recno
from a
UNION
select 'B' as 'TABLE', name, recno
from b

Thank you! That's exactly what I was seeking!
The 'TABLE' literal should be enclosed with double quoyes ("), however.

Incorrect.

Sybrand Bakker
Senior Oracle DBA
No, it is correct.

"TABLE" should be in double qoutes indeed, because it is a reserved word.
Normally, the column alias should be either without quotes, or with double
quotes. Single quotes don't work here.

SQL> select 'a' as "table", 1 from dual;

t 1
- ----------
a 1

SQL> select 'a' as table, 1 from dual;
select 'a' as table, 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL> select 'a' as 'table', 1 from dual;
select 'a' as 'table', 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL> select 'a' as non_reserved_word, 1 from dual;

N 1
- ----------
a 1

SQL> select 'a' as "non_reserved_word", 1 from dual;

n 1
- ----------
a 1

SQL> select 'a' as 'non_reserved_word', 1 from dual;
select 'a' as 'non_reserved_word', 1 from dual
*
FOUT in regel 1:
..ORA-00923: FROM-sleutelwoord is niet gevonden waar verwacht.


SQL>

Shakespeare




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.