Pass value from sqlplus to shell on AIX


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Pass value from sqlplus to shell on AIX
# 1  
Old 07-26-2019
Pass value from sqlplus to shell on AIX

hello friend good morning
I have a problem, how can I take the value that the PROCEDURE returns to me in the variable "CodError", when the connection to the bbdd is closed I lose the value and I need it in the shell

Code:
#AIX
cat <<EOF | sqlplus -s ${ORA_LOGIN}/${ORA_PASSWORD} > $logftmp
   set feedback off;
   set serveroutput on size 1000000
   set line 500;
   DECLARE
     coderror    NUMBER;
     desc_error  varchar2(200);
     fecha_ini   VARCHAR2(10);
     fecha_aux    varchar2(10);
   BEGIN
      coderror   :=0;
      desc_error :=null;
       RPY_OMSJSOSTKPTG(coderror,desc_error);
       dbms_output.put_line('CodError:' || CodError);
       dbms_output.put_line('Desc Error:' || desc_error);

   EXCEPTION
     WHEN OTHERS THEN
       dbms_output.put_line('Error '||TO_CHAR(SQLCODE)||': '||SQLERRM);
   END;
/
   exit;
EOF
echo "controlo error"

# 2  
Old 07-26-2019
SELECT CodError perhaps?
# 3  
Old 07-26-2019
as a friend? I do not understand
# 4  
Old 07-27-2019
See oracle docs about the WHENEVER SQLERROR clause
SQL*Plus Command Reference

When your code hits an error, your code invokes the whenever clause return the error value to the calling shell. You set the error number to what you need in the clause.

You did not mention what shell you are using but with most shells the the variable $? is the value of the return code from the previous process, you can also call wait to get a return code.

A bash example of wait would be:
Code:
$( sqlplus command ................ )
   wait $! 
   status=$?
   echo Job 2 exited with status "$status"
  # now you exit from the main script with your error code if needed (like you ran this using cron):
  exit $status

Note carefully. Remove the cat command because it will interfere with the return code you want. --
All of this is based on some assumptions, if you need more help please give us the specific shell and version of AIX and Oracle.
This User Gave Thanks to jim mcnamara For This Post:
# 5  
Old 07-29-2019
This User Gave Thanks to abhi_123 For This Post:
# 6  
Old 07-29-2019
what happens is that I have this call to the procedure, and this one returned me a code, that code when closing the connection to the bbdd I need to rescue it and use that code in the shell
# 7  
Old 07-29-2019
exactly that i need
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass a VARIABLE to sqlplus script

Hi Team, I am trying to run a sqlplus script against several databases via a FOR/LOOP and also passing the loop variable to a sqlplus script I am calling, as follows: #!/bin/bash export ORACLE_SID=plgc1 export ORACLE_HOME=/opt/oracle/product/11.2.0.2/db_1 export... (1 Reply)
Discussion started by: jonnyd
1 Replies

2. Programming

How to pass parameter from file to sqlplus in UNIX?

i have file in which i have employee id are there and every time number of employee id are different in file means number of count of employee id in file are every time different. 343535435 365765767 343534543 343543543 i want to pass this file to sqlplus and sql command is ... (7 Replies)
Discussion started by: pallvi_mahajan
7 Replies

3. Shell Programming and Scripting

How to pass Variable from shell script to select query for SqlPlus?

echo "set echo off"; echo "set feedback off"; echo "set linesize 4000"; echo " set pagesize 0"; echo " set sqlprompt ''"; echo " set trimspool on"; Select statement is mentioned below echo "select res.ti_book_no from disney_ticket_history res where res.ti_status =${STATUS} and... (7 Replies)
Discussion started by: aroragaurav.84
7 Replies

4. Shell Programming and Scripting

Can't get shell parameters to pass properly to sqlplus

Gurus, The issue I'm having is that my Shell won't accept SQL parameters properly...... Here's they way I'm running it.... applmgr@ga006hds => sh CW_MigrationDeployScript.sh apps <appspwd> <SID> '01-JAN' '31-MAR' The process just hangs not submitting the SQL job... ... (3 Replies)
Discussion started by: WhoDatWhoDer
3 Replies

5. Shell Programming and Scripting

AIX ksh: how to pass variable to host shell

I have a script that "runs" a script. For example: ./runscript.ksh pcnmc01.ksh runscript puts pcnmc01.ksh into the background with log output going to the logfile. After executing the command, I get this output: Running script in the background: pcnmc01.ksh Logfile:... (2 Replies)
Discussion started by: Eben Yong
2 Replies

6. Shell Programming and Scripting

How to pass parameter from sqlplus(procedure completed) to your shell script

if then # mail -s "Import failed file does not exist" sanjay.jaiswal@xyz.com echo "FILE does not exist" exit 1 fi echo "FILE EXIST" size=-1 set $(du /export/home/oracle/nas/scott21.dmp.gz) while do echo "Inside the loop" size=$1 set $(du... (1 Reply)
Discussion started by: sanora600
1 Replies

7. Shell Programming and Scripting

To pass the .sql file as a paramter to sqlplus through shell programming

Hi, Currently i have a .sql file 1.sql. I need to pass that as a parameter through a shell script to the sqlplus inside the same shell script. How I should I do.can anyone help me pls. I have an req where I need to send the .sql file and the place where the script has to create a .csv... (9 Replies)
Discussion started by: Hemamalini
9 Replies

8. UNIX for Advanced & Expert Users

How to pass unix variable to SQLPLUS

hi fellows, can any body tell me how to pass unix variables to oracle code is... #! /bin/ksh echo ENTER DATE VALUE's read START_DATE END_DATE sqlplus xyx/abc@oracle select * from table1 where coloumn1 between $START_DATE and $END_DATE; is this is correct way........... Thanks in... (1 Reply)
Discussion started by: chiru
1 Replies

9. Shell Programming and Scripting

How to pass variable to SQLPLUS in a ksh script?

Hi, I am writing a ksh script which will use sqlplus to run a sql and pass 2 variables as the SQL request. In the ksh script, I have 2 variables which are $min_snap and $max_snap holding 2 different numbers. Inside the same script, I am using SQLPLUS to run an Oracle SQL script,... (6 Replies)
Discussion started by: rwunwla
6 Replies

10. Shell Programming and Scripting

How to pass Shell variables to sqlplus use them as parameters

Hi, I am trying to pass some of the variables in my shell scripts to the sqlplus call and use them as parameters. For example, I would like to replace the 'SAS', and '20050612' with $var1 and $var2, respectively, how can I do that? --------------------------------------------------------... (1 Reply)
Discussion started by: Jtrinh
1 Replies
Login or Register to Ask a Question