Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle help with Linux

Posted on 2015-01-27
16
Medium Priority
?
172 Views
Last Modified: 2015-03-19
Hi ,

I am using Oracle procedures in my shellscript .
Can you advice how to get the return values from the Oracle plsql to proceed further on the shell scripting?
Or in case any error happened during PLSQL , how to get the error code /resturn status and handle the exceptions?

      
Thanks
0
Comment
Question by:magento
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
  • 3
16 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40575072
Can you provide more information?

Exceptions are typically handled inside PL/SQL itself.

What are you returning from the procedure?
What are you wanting to do with it once it is returned?
In case of an exception, what do you want the script to do?
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40575654
Try something like this:
Result=`sqlplus -s userid/passwd <<EOSQL
var var1 number;
exec myProc( :var1 out number);
print :var1
exit
EOSQL`

Open in new window

0
 
LVL 5

Author Comment

by:magento
ID: 40597768
Hi Mike,

So if i check for return value in line 7 i will get the return status right ...echo $? (0=success other =failure)
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 5

Author Comment

by:magento
ID: 40602054
Hi Slightwv,

Slightwv,

Sorry for late response, i didnt see ur post ...

What are you returning from the procedure?
The returnFlag
What are you wanting to do with it once it is returned?
Based  on returnFlag status need to run the commands
In case of an exception, what do you want the script to do?
It should log the exception and exit .

Thanks
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40602066
>>The returnFlag

Need more information.  Do you mean the error-code like ORA-00942, teh error message, what?

>>Based  on returnFlag status need to run the commands

What commands?  More PL/SQL code, more Unix commands, what?

>>It should log the exception and exit .

Log how?  In a log file created by the script, in the database, what/where?


The more specific you can be when asking questions, the faster you can get it answered.  We need to know the specifics...
0
 
LVL 5

Author Comment

by:magento
ID: 40602279
Hi,

First apologies about the other question. I do understand that here i am getting help , i was try to make the question visible to some other experts so only posted this . Sorry again.

In the PLSQL , we have return_flag = y and return_flag = n , so how shell script will capture that y/n value.

Based on the y/n , i have to execute Unix commands.

The exception, say "unable to access table" should get logged in the Unix log which i am storing >> /var/log/app/log

Thanks
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40603115
Did you try the sample provided my Mike in http:#a40575654 ?

The Unix shell variable Result should contain whatever the output parameter of the stored procedure is.
0
 
LVL 5

Author Comment

by:magento
ID: 40607109
No, i didnt try it. I just installed oracle , i will test it and let you know the outcome.
0
 
LVL 5

Author Comment

by:magento
ID: 40613458
Sorry guys, i still not tested this . As i was unable to install the oracle rpm package in ubuntu  since rpm wasnt installed in my machine and i dont have internet access expect i can connect a usb .
0
 
LVL 5

Author Comment

by:magento
ID: 40646085
Hi,

Sorry for the delay.

Its working fine,but the only issue is the output coming as below.

pl/sql procedure completed...............................................123

I want to store only the actual value. I managed to get the value using shell script.
But is there a way to handle the same in oracle ? so i get the output as 123

Thanks
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40647084
Do this:
Result=`sqlplus -s userid/passwd <<EOSQL
var var1 number;
exec myProc( :var1 out number);
exit :var1
EOSQL`
return_flag=$?

Open in new window

0
 
LVL 5

Author Comment

by:magento
ID: 40647200
So instead of checking the variable var1 for Y or N, i can check the value for $return_flag=0or not 0 right?
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40648025
Or 123
This is unix return code from 0 to 255 only
0
 
LVL 5

Author Comment

by:magento
ID: 40648483
Sorry for confusion , 123 is the value output from stored procedure.
its the value returned from table column which is the output parameter.
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 2000 total points
ID: 40654205
The "exit :var1" statement will return the the value output from stored procedure as a "Unix" $? return code and must be a number between 0 and 255.
;)
0
 
LVL 5

Author Comment

by:magento
ID: 40677243
Great Mike , thank you so much . Learned pretty much . Thanks again.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question