Results 1 to 3 of 3
  1. #1
    Join Date
    May 2003
    Posts
    27

    Unanswered: can I pass a system variable into a sql file executed by db2?

    eg.
    I have a sql file called step1.sql and its connent as follows:

    step1.sql
    -------------------------------------------------------------------
    connect to mydb;

    select * from myschema.mytable
    where myname = 'xyz';

    connect reset;
    --------------------------------------------------------------------

    i run this file thru the command:
    db2 -tvf step1.sql


    I wonder if I can use the system variable for the database name and the value of myname......as follows.. ( of course, the following stuff in not working), what I want is to pass a value from the system in to the db2 command line processor.........

    ie. in unix platform for example

    in unix console,
    -------------------------------------------------------------------
    export dbname=mydb
    export myvalue=xyz

    step1.sql
    -------------------------------------------------------------------
    connect to $dbname;

    select * from myschema.mytable
    where myname = $myvalue;

    connect reset;
    --------------------------------------------------------------------

    is there any way to do thing like the above??
    use stored procedural ??

  2. #2
    Join Date
    Jul 2003
    Location
    Switzerland, Basle
    Posts
    10
    on unix you can use a shell-script with embedded SQL-input

    example
    -------------------------------------------
    #!/bin/ksh
    # or whatever shell you like

    dbname=mydb
    myvalue="'xyz'"
    # note the double-quote followd by single-quote surrounding the value

    db2 +p -tf- <<.EOFSQL
    -- START of SQL
    connect to $dbname;

    select * from myschema.mytable
    where myname = $myvalue;

    connect reset;
    .EOFSQL
    # here continues the shell-script
    # instead of .EOFSQL you can use any other string to begin/terminate
    # the inline input (NO leading spaces! for the terminating line)

  3. #3
    Join Date
    May 2003
    Posts
    27

    thanks....

    thanks.... jammann

Posting Permissions

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