Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    27

    Question Unanswered: declare statement in db2

    Can we use
    declare ......
    begin
    ..............
    end
    alone without create procedure (like in Oracle) in db2?
    My query is:

    can i use this:

    declare countValue integer;
    begin
    SET countValue=(select count(*) from SYSIBM.SQLTABLES where table_name=upper('vivek'));
    if countValue=1
    then
    alter table dbo.vivek;
    drop column dbo.name;
    end if;
    end


    Plesae give me a solution
    Thanks in advance
    Vivek

  2. #2
    Join Date
    May 2007
    Location
    somewhere in dbforums
    Posts
    221
    nope.... you'll have to create a proc... this would have been possible in MSSQL but not in DB2
    IBM Certified Database Associate, DB2 9 for LUW

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Yes, you can use atomic compound statements on the command line:
    Code:
    $ db2 "create table t ( a int )"
    DB20000I  The SQL command completed successfully.
    $ db2 "begin atomic declare i int default 0; while ( i < 10 ) do insert into t values ( i ); set i = i + 1; end while; end"
    DB20000I  The SQL command completed successfully.
    364 local:~/ $ db2 "select * from t"
    
    A
    -----------
              0
              1
              2
              3
              4
              5
              6
              7
              8
              9
    
      10 record(s) selected.
    You may want to have a look at the SQL statements that you can place into such a compound statement.
    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
  •