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 > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > db2 stored proc using script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-07, 20:08
usc usc is offline
Registered User
 
Join Date: Apr 2007
Posts: 21
Cool db2 stored proc using script

I am new to AIX DB2.

I need to create db2 stored procedure using shell script. Can anyone provide a sample script that connects to db2 database and does the create/

Thanks!
Reply With Quote
  #2 (permalink)  
Old 04-14-07, 08:53
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Code:
#!/bin/sh

db2 "connect to <db-name>"
db2 "create procedure proc() begin ... end"
db2 "connect reset"
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 04-16-07, 12:52
usc usc is offline
Registered User
 
Join Date: Apr 2007
Posts: 21
the id i use is a dba id. i need to create the stored proc with a different schema. how do i accomplish this.

Thanks!
Reply With Quote
  #4 (permalink)  
Old 04-19-07, 15:37
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Your SP will likely contain several delimited statements, so you would need to use a different delimiter when creating the SP.

e.g.

db2 -td@ << !!
create procedure myschema.myproc(in var1 int, in var2 int)
...
@
!!
Reply With Quote
  #5 (permalink)  
Old 04-21-07, 04:37
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Code:
#!/bin/sh

PROC_SCHEMA=$1
if [ -z "${PROC_SCHEMA}" ]; then
    echo "Usage: $0 <schema-name>"
    exit 1
fi

db2 "connect to <db-name>"
db2 "create procedure ${PROC_SCHEMA}.proc() begin ... end"
db2 "connect reset"
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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