If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Running a SQL script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-01-08, 10:24
mmsUser mmsUser is offline
Registered User
 
Join Date: Oct 2008
Posts: 3
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
Reply With Quote
  #2 (permalink)  
Old 10-02-08, 01:49
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #3 (permalink)  
Old 10-02-08, 02:51
mmsUser mmsUser is offline
Registered User
 
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?
Reply With Quote
  #4 (permalink)  
Old 10-02-08, 10:19
rwcooke rwcooke is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 10-04-08, 06:45
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #6 (permalink)  
Old 10-06-08, 01:46
mmsUser mmsUser is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On