Following is small block of code i use to deploy the SQL scripts in my databases. I'm just wondering if i can automate this task of commit or rollback based in the result.
disc
connect username/password@database
spool D:\Deployments\path\to\logfile\logfile.log
@D:\Deployments\path\to\script\sqlquery_script.sql
If the sql script is ran successfully with out any errors means I want the system to Commit it automatically and in case any error is occcured all teh transactions should be rollbacked (Note that my sql script has many update statements)
When I use WHENEVER SQLERROR EXIT SQL.CODE ROLLBACK;
the SQL* plus window is closed without showing any error.
Please help to resolve this.
You don't say what your script is. How about putting it inside a PL/SQL anonymous block?
BEGIN
... updates here ...
COMMIT;
EXCEPTION WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;
/
Probably you can give call to a procedure or in the Sql script you give call to procedure
exec procedureName(parameter1,parameter2);
Keep this statement in your sql file
and in case of exception keep this statement along with the above statement
EXCEPTION WHEN x_Error THEN
ROLLBACK ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.