Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2008
    Posts
    3

    Unanswered: Running a SQL script

    Hi,

    I'm looking for a way to execute a sql script with another sql script. In Oracle databases the '@' is used but what about DB2?

    DB2-Version: 8.2.3

    regards

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    In DB2, it is the usual shell approach to use '!' to leave the CLP and enter system commands.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Oct 2008
    Posts
    3
    Thank you for responding. But it didn't work the way I want.

    I don't want a solution like batch files. I'm trying to migrate scripts from oracle to db2, but it is important that the file aren't changed two much...

    Here is the scenario (for oracle):

    I have two sql scripts:
    1. test.sql
    contains: @inside.sql
    2. inside.sql
    contains: SELECT * FROM USERS;

    Is there no symbol for '@' in db2 with the same functionality?

  4. #4
    Join Date
    Oct 2008
    Posts
    1
    sqlplus is a lot more powerful than DB2 clp but you can do simple script calls with clp.

    $ cat inside.sql
    connect to smdb;

    select * from users;
    $ cat test.sql

    ECHO Running inside.sql;

    !db2 -tf inside.sql;

    $ db2 -tf inside.sql

    Database Connection Information

    Database server = DB2/AIX64 8.2.7
    SQL authorization ID = IDCSVDV4
    Local database alias = SMDB



    LNAME FNAME SERIAL
    --------------- --------------- -----------
    Smithe Frank 100101
    Jones Richard 330101
    Nguyen Susan 870401

    3 record(s) selected.



    Robert Cooke
    AMD

  5. #5
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    My suggestion would be to do something like that in a shell script from the start. That's portable to a wide range of DBMS because you don't introduce such system-dependencies. But it really depends on the environment you're working in...
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  6. #6
    Join Date
    Oct 2008
    Posts
    3
    Thank you for responding.

    I've decided to use a solution with jdbc. Now new code is necessary but a script can be omitted. And changing the driver for other databases is the only system dependent in the future.


    regards

Posting Permissions

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