Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2003
    Posts
    1

    Red face Unanswered: select into dynamic query

    Hi,

    I am rather new to DB2. I am having trouble converting a select into dynamic query from oracle to DB2 .Is there any equivalent in Db2?

    My statement is
    excute immediate 'select max(id) into l_max from t1'

    Also is there any way of declaring a dynamic cursor in db2?

    eg declare cursor c1 is select * from L_user.l_var;

    Thanks,
    Manoj

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: select into dynamic query

    AFAIK, both these are possible in DB2 ..

    Do you want to read Application Dev guide(s) relevent to your db2 version ?

    Cheers

    Sathyaram

    Originally posted by galaxy_2000
    Hi,

    I am rather new to DB2. I am having trouble converting a select into dynamic query from oracle to DB2 .Is there any equivalent in Db2?

    My statement is
    excute immediate 'select max(id) into l_max from t1'

    Also is there any way of declaring a dynamic cursor in db2?

    eg declare cursor c1 is select * from L_user.l_var;

    Thanks,
    Manoj
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Aug 2003
    Location
    austin,tx
    Posts
    104
    I can't seem to find an equivalent of 'SELECT INTO' in DB2. I've been looking. Is there one?

    For those unfamiliar with SELECT INTO in SQL Server, they allow you to create a new table dynamically from the result set of a select statement.

    Ex) SELECT name, id INTO Name_ID_TABLE FROM employeeTable
    Would create a new table called Name_ID_TABLE which would contain two columns, name and id, whose definitions matched that of the same columns in employeeTable.

    Sure is a handy feature.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    That would be
    Code:
    CREATE TABLE MY.TABLEA AS (SELECT ...)

  5. #5
    Join Date
    Oct 2005
    Posts
    109
    you can explicitely work with cursors using the declare cursor statement and processing that.

    Please see the samples on how to do that and for fetching the data, but this is rather simple and standard.

    http://publib.boulder.ibm.com/infoce...n/r0000937.htm

    Another way to do things is the SELECT INTO statement, and from what I see is that you also want to work the standard way and fetch something into a host variable.

    Yes, that can be done in DB2 as well, please see the reference:
    http://publib.boulder.ibm.com/infoce...n/r0000994.htm
    Juliane

Posting Permissions

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