Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    Posts
    13

    Unanswered: how to put the result of a query into a variable??

    DEFINE invoice_count = SELECT COUNT(Invoice#) from INVOICE NUMBER;

    This doesnt work. What's the correct syntax or method for doing this in SQL*Plus?

  2. #2
    Join Date
    Jan 2003
    Posts
    10
    Hi,

    you have to use a sql*plus variable.

    Example:
    <SQL>
    -- Declare the variable INVOICE_COUNT as number
    variable invoice_count number

    -- fill the variable in a anonym-plsql-block
    begin
    SELECT COUNT(Invoice#)
    into :invoice_count
    from INVOICE NUMBER;
    end;
    /

    -- now you can output the Value
    print invoice_count

    -- or us it in a subsequence select
    select * from test_table where column1=:invoice_count;

    </SQL>

Posting Permissions

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