Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6661543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:17:34+00:00 2026-05-26T02:17:34+00:00

I have to convert a shell script from Oracle to db2. I found on

  • 0

I have to convert a shell script from Oracle to db2. I found on this forum a sample of Oracle script I used ; it looks like this

#!/bin/bash
OUT=`$ORACLE_HOME/bin/sqlplus -s user/pass@instance   << EOF
select sysdate from dual;
exit success
EOF`
echo $OUT

This will output “03-OCT-11” (Oracle sysdate). My db2 script looks like this

#!/bin/bash
db2bin="/users/db2inst1/sqllib/bin"
#connect
$db2bin/db2 connect to myschema;
#query
$db2bin/db2 "SELECT CURRENT_DATE FROM SYSIBM.SYSDUMMY1 WITH UR";
#debug
echo $?
#check
if [ $? = "0" ] then         echo "found-do something"
else        echo "not found-good bye"
fi
#terminate
$db2bin/db2 quit;

It works but does not retrieve the date ; only “0” or “1” (true/false). How can I retrieve the date from my Db2 query result??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:17:34+00:00Added an answer on May 26, 2026 at 2:17 am

    Chris, your environment variables and your DB2 command path should be set by sourcing db2profile. The quit command is unnecessary when calling the db2 command with either a SQL file or a single statement specified as part of the command-line.

    #!/bin/bash
    . ~db2inst1/sqllib/db2profile
    OUT=`db2 connect to myschema >/dev/null 2>&1; db2 -x values current date`
    

    Your database connection will remain available until the script ends, so you can run successive statements without reconnecting.

    #!/bin/bash
    . ~db2inst1/sqllib/db2profile
    db2 connect to myschema >/dev/null 
    OUT=`db2 -x values current date`
    AAA=`db2 -x " select a from sometable where b = 'c' " `
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date like this:- 20091023 i have to convert it to a
How can I convert a shell script into a Perl script? I have a
I am planning to convert a rather long shell script I have into an
I have a shell script (.sh) that works in Unix but I'd like to
I have to convert several full PAL videos (720x576@25) from YUV 4:2:2 to RGB,
I have a file, someFile , like this: $cat someFile hdisk1 active hdisk2 active
I have a process I spawn with a Cygwin shell script, and I am
How can I convert this string to have a space every 8th digit using
I have some ksh scripts which I'd like to convert to run with bash
I have shell scripting knowledge. I have written a small shell script which will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.