I'm currently making an SQL script that makes a number of changes in the database and I'd like the user to confirm the results for each step.
code:
SET ECHO ON
SET AUTOCOMMIT OFF
SET EXITCOMMIT OFF
-- make changes
update plan_table
set statement_id = '3'
where statement_id = '2';
-- check if correct
select statement_id from plan_table;
-- ask confirmation
ACCEPT response CHAR DEFAULT 'n' PROMPT 'Result ok? - y/n: ';
if lower(&response) = 'y' then (
update plan_table
set statement_id = '4'
where statement_id = '3';
-- check if correct
select statement_id from plan_table;
-- ask confirmation
ACCEPT response CHAR DEFAULT 'n' PROMPT 'Result ok? - y/n: ';
if lower(&response) = 'y' then commit;
else rollback;
end if;
)
else rollback;
end if;
/
exit;
The changes work, but I always get an error when I try to get verification (the Accept response parts):
SQL> -- ask confirmation
SQL> ACCEPT response CHAR DEFAULT 'n' PROMPT 'Result ok? - y/n: ';
Result ok? - y/n: SQL> if lower(&response) = 'y' then commit;
SP2-0734: unknown command beginning "if lower(&..." - rest of line ignored.
SQL> else rollback;
SP2-0734: unknown command beginning "else rollb..." - rest of line ignored.
SQL> end if;
SP2-0042: unknown command "end if" - rest of line ignored.
SQL> )
SP2-0042: unknown command ")" - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SQL> else rollback;
SP2-0734: unknown command beginning "else rollb..." - rest of line ignored.
SQL> end if;
SP2-0042: unknown command "end if" - rest of line ignored.
SQL> /
Can anyone tell me what I'm doing wrong?
error when using case:
Enter value for userreply: old 7: case &userReply when 'y' then exit commit
new 7: case y when 'y' then exit commit
ACCEPT userReply PROMPT 'Result ok? - y/n: '
*
ERROR at line 6:
ORA-06550: line 6, column 8:
PLS-00103: Encountered the symbol "USERREPLY" when expecting one of the
following:
:= . ( @ % ;
Thanks