powershell and oracle pl/sql

i call pl/sql procedure in powershell script. how to send exception when others then raise; from pl/sql back to powershell.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
I'm not sure I understand the question.  PL/SQL will raise whatever exception you tell it to.

Are you asking how to trap the raised exception inside Powershell and take some appropriate action?

How are you connecting to Oracle from Powershell?
JasaidaAuthor Commented:
Yes. i connect to oracle like that
sqlplus.exe $username/$pas'@'$DBP "@" file.sql

and sql raised. how to trap raised exception inside powershell i want to set raise exeption equal to
$lastexitcode and exit powershell with $lastexitcode.
slightwv (䄆 Netminder) Commented:
Many people confuse Oracle's Procedural Language, PL/SQL and just normal SQL.

Are the commands in file.sql an actual pl/sql block or straight SQL commands?
Webinar: Cyber Crime Becomes Big Business

The rising threat of malware-as-a-service is not one to be overlooked. Malware-as-a-service is growing and easily purchased from a full-service cyber-criminal store in a “Virus Depot” fashion. Join us in our upcoming webinar as we discuss how to best defend against these attacks!

JasaidaAuthor Commented:
it is a pl/sql block.
slightwv (䄆 Netminder) Commented:
I'm not a Powershell person so I'm not sure what you mean by lastexitcode but using sqlplus to execute a pl/sql block, you'll likely need to capture the script output, maybe with spool, and parse it looking for errors.

I know sqlplus has an exit value but I've never played with it in capturing a pl/sql exception.  My guess is the pl/sql, even with an exception, will complete successfully which means sqlplus will likely complete successfully.

You can set up some quick tests and try it.
DBAduck - Ben MillerPrincipal ConsultantCommented:
You can check this out.

This will tell you about the $? and the $LASTEXITCODE variables in PowerShell.

This will tell you the exit code for sqlplus.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
slightwv (䄆 Netminder) Commented:
>>This will tell you the exit code for sqlplus.

I'm not sure what is sufficient.  From a quick test of a pl/sql block and sqlplus, sqlplus exited successful even though the pl/sql block had an exception.
DBAduck - Ben MillerPrincipal ConsultantCommented:
That could be, but that just means that all you will get from PowerShell is the exit code.  Because PowerShell did not execute the pl/sql block it has no knowledge of any exception that is thrown, only sqlplus.exe knows about that.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.