If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > why we can't assign an SQL query to a variable?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-01-05, 11:01
hristo hristo is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
why we can't assign an SQL query to a variable?

heya,
To what i have read so far, we can't assign an SQl query statement to a variable that can be used afterwards, i.e.
A=select ...from... where...
then,
select...from A where...

thus we end up using nesting queries which i found so cumbersome

is there any reason behind this implementation decision which i can't see especially when the nesting queries are not dependent

thanks
Reply With Quote
  #2 (permalink)  
Old 03-01-05, 11:40
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Your "variables" are standard SQL features called views.

-PatP
Reply With Quote
  #3 (permalink)  
Old 03-01-05, 13:05
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool

If you are using Oracle, then the variable would be a reference cursor:
Code:
var rc refcursor;
...etc...
begin
  open :rc for 'select * from MyTable';
...etc...
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #4 (permalink)  
Old 03-01-05, 15:13
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally Posted by LKBrwn_DBA
[COLOR=Blue][SIZE=3]If you are using Oracle, then the variable would be a reference cursor:
Most of the different SQL and SQL-like dialects have a way of doing this. I just presented the view because it is pure SQL-89 (and earlier) standard. A view ought to work on any product that claims to be compatible with the SQL standard.

-PatP
Reply With Quote
  #5 (permalink)  
Old 03-02-05, 13:37
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Thumbs up

True, best solution is views; maybe I should have said: 'the variable could also be a reference cursor'. Cheers.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On