Solved

how to have if logic in a simple (oracle) sql file

Posted on 2013-12-12
2
419 Views
Last Modified: 2013-12-13
Hi,

I have a shell script which invokes a sql file like below. When there is an error (ORA error) in SQL it rollback the changes and abort the sql execution.

Shell script. run.sh
sqlplus <1>/<2>@${target.db.instance} @runSqlScript.sql <3>

runSqlScript.sql content
whenever sqlerror exit failure rollback
start &1

My request is:
I would like add a logic/flag "ignore_error"  inside the SQL file "runSqlScript.sql" to determine to exit on error or continue on error.

sorry I'm a if else guy. not good in sql.

e.g.
if ignore_error=true
whenever sqlerror continue
else
whenever sqlerror exit failure rollback
end if
start &1
0
Comment
Question by:enthuguy
2 Comments
 
LVL 23

Accepted Solution

by:
David earned 200 total points
ID: 39714150
First pass, you would have to set the flag as a shell variable (if true then export var=string); then pass that variable to the whenever phrase - e.g., "whenever sqlerror 'var'".
0
 
LVL 13

Assisted Solution

by:Alexander Eßer [Alex140181]
Alexander Eßer [Alex140181] earned 200 total points
ID: 39714158
This one's a quick shot/workaround:
You could set up a "set env" script, one with "whenever sqlerror continue" and the other with "whenever sqlerror exit failure rollback". Then you could decide from "outside" which one to load (or from within the DB -> e.g. some options table)...

You might want to take a look at this:
https://forums.oracle.com/thread/909622
https://forums.oracle.com/message/4499960#4499960
http://www.freelists.org/post/oracle-l/Conditional-logic-in-a-main-SQLPLUS-script-file,4
http://stackoverflow.com/questions/13345621/sqlplus-decode-to-execute-scripts
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now