Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2012
    Posts
    28

    Unanswered: problem with this function?

    create function f2()
    returns decimal(10,2)
    language sql
    begin atomic
    declare v3 decimal(10,2);
    select sum(sal) into v3 from emp where deptno=20;
    return v3;
    end


    Function is not getting created in command line processor.

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    it would help if more details would be published
    the command to create ?
    the error you get ?
    many samples are available in sample directory below sqllib
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    you cannot use SELECT ... INTO in CLP. Try instead:
    SET v3 = (SELECT SUM(sal) FROM emp WHERE deptno = 20);
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  4. #4
    Join Date
    Jul 2012
    Posts
    28
    thanks a lot florin, it worked.

  5. #5
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    If you don't need procedural SQL, try to avoid it. You'd make the life of the DB2 optimizer much easier:
    Code:
    create function f2()
       returns decimal(10,2)
       language sql
       return DECIMAL(sum(sal), 10, 2) from emp where deptno=20;
    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
  •