Call Anonymous block from DB2


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Call Anonymous block from DB2
# 1  
Old 10-31-2013
Call Anonymous block from DB2

Hi,
I have a shell script and im trying to call a .sql file. The sql file has a simple Anonymous block.
The code is

shell script
Code:
db2 -tvf query.sql


the sql file contains
Code:
SET SERVEROUTPUT ON;
BEGIN
 call dbms_output.put_line( 'Hello' );
END;

I get the following error
Code:
BEGIN
call  dbms_output.put_line( 'Hello' )
DB21034E  The command was processed as an SQL statement because it was not a valid Command Line Processor command.  During SQL processing it returned: SQL0104N  An unexpected token "END-OF-STATEMENT" was found following ".PUT_LINE( 'Hello' )".  Expected tokens may include:  "<psm_semicolon>". LINE NUMBER=2.  SQLSTATE=42601

END
DB21034E  The command was processed as an SQL statement because it was not a valid Command Line Processor command.  During SQL processing it returned: SQL0104N  An unexpected token "END-OF-STATEMENT" was found following "END". Expected tokens may include:  "JOIN <joined_table>".  SQLSTATE=42601

Kindly let me know if there is any way to run blocks from db2 via shell script

Thanks

Last edited by Don Cragun; 10-31-2013 at 02:56 AM.. Reason: Add CODE tags.
# 2  
Old 10-31-2013
You have to use a different statement terminator for the CLP or the semicolon within the block will be consumed by the CLP. You could use the slash instead for example:

Code:
SET SERVEROUTPUT ON /
BEGIN
call dbms_output.put_line('Hello');
END /

and then run
Code:
$ db2 -td/ -vf  query.sql
SET SERVEROUTPUT ON
DB20000I  The SET SERVEROUTPUT command completed successfully.

BEGIN
call dbms_output.put_line('Hello');
END
DB20000I  The SQL command completed successfully.

Hello

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing the result of an anonymous pl/sql block to a shell script

Hello, Here is the code i have written to get the count of a plsql query back to the unix. function checkforCOIDs { countcheck=`sqlplus -s $1/$2@$3 whenever oserror exit sql.oscode rollback whenever sqlerror exit sql.sqlcode rollback set serverout on size 2000; set head off feedback off... (2 Replies)
Discussion started by: santosh2eee
2 Replies

2. Shell Programming and Scripting

Calling an Anonymous Block through shell script

Hi, My requirement is to load a LONG datatype data value from one table to another as direct access does not work (DB: ORACLE). eg. SELECT *FROM ALL_VIEWS WHERE TEXT LIKE '%<SEARCH_STRING>%'; As an alternate we are creating a table and trying to insert in it from ALL_VIEWS as direct insert... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

3. Shell Programming and Scripting

Invoking SP through Anonymous Block

Hi, I'm writing a Shell script to run a stored procedure through SQL*Plus using the below script and it works well. Test.sh $ORACLE_HOME/bin/sqlplus connect user/pwd@dbname @Test.sql Test.sql call sp_test_procedure() Now, similarly I want to run the below PL/SQL anonymous block... (1 Reply)
Discussion started by: Dev_Dev
1 Replies

4. Shell Programming and Scripting

call shell script from pl/sql block

Hi Experts, I want to call script_name.ksh as many time as id in customer table and also pass it as a parameter to script. someting Like below. for i in select id from customer do ./script_name.ksh $i & done I have figured out how to have ID from customer but now how to call... (3 Replies)
Discussion started by: Opamps123
3 Replies

5. Shell Programming and Scripting

How to call shell script from db2 triggger

Is there a way to call a shell script via db2 trigger? I want to wake up a shell script to perform some action if there is a insert action on a db2 table. (1 Reply)
Discussion started by: prasperl
1 Replies

6. Linux

How to call a DB2 SP from Solaris machine.

Hi, Can some one give me the syntax, how to call a DB2 SP from a Solaris machine. Thanks and Regards, Preetham R. (0 Replies)
Discussion started by: preethgideon
0 Replies

7. Shell Programming and Scripting

To get value from Oracle Anonymous PLSQL block

Hi All, i need you help while accessing the value from anonymous PL/SQL block. Initially our requirement was to get the value from SQL statement. I was doing like... But now i need to use dbms_application_info.set_module in it. So i have planned to use anonymous block instead of SQL... (2 Replies)
Discussion started by: Amit.Sagpariya
2 Replies

8. UNIX for Dummies Questions & Answers

Exception while loading DB2 driver Class.forName("com.ibm.db2.jcc.DB2Driver")

Hi... I m working on UNIX z/OS. Actually i have to pass the parameters from the JCL to java-db2 program thru PARM. I am able to pass the arguments but the problem occured is, it is throwing an exception while loading the db2 driver as 'Javaclassnotfound:com.ibm.db2.jcc.DB2Driver'... (0 Replies)
Discussion started by: Sujatha Gowda
0 Replies

9. UNIX for Dummies Questions & Answers

How to block an anonymous ftp user?

Could anyone provide information on how to block a specific client machine from being able to log onto anonymous ftp? (10 Replies)
Discussion started by: dennisheazle
10 Replies
Login or Register to Ask a Question