Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2007
    Posts
    21

    Cool Unanswered: 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!

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

  3. #3
    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!

  4. #4
    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)
    ...
    @
    !!

  5. #5
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

Posting Permissions

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