Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2004
    Posts
    3

    Unanswered: 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

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Your "variables" are standard SQL features called views.

    -PatP

  3. #3
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

  5. #5
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •