Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    11

    Unanswered: Direct assignment using SQL statement?

    Can I accomplish following thing in DB2 stored procedure or functions?

    Code:
    DECLARE count INTEGER;
    ..
    ..
    ..
    
    SET count = SELECT COUNT(*) from USER_TABLE;
    Basically I want to assign the value of number of rows present in USER_TABLE to variable "count". Above statement of course is not working.

    Please advise.

    Thanks
    rpkulkarni

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    SET count = (SELECT COUNT(*) from USER_TABLE);

    (SELECT .....) is a scalar full-select. And, scalar full-select is an expression.

  3. #3
    Join Date
    Nov 2009
    Posts
    11

    Thanks for the advise

    Thanks for your advise. It worked correctly.

    Regards,
    rpkulkarni

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Another alternative is a SELECT ... INTO ... statement. It is described in the manual, too.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

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