如果没有找到oracle plsql重复

时间:2016-01-21 14:35:08

标签: sql oracle plsql sqlplus

set verify off

accept project prompt ' project : '
select locknr,description,couserid,ciuserid from dgdtw_lockedinfo where     
description = '&project' and ciuserid is null;

accept lock prompt ' locknumber  : '

update dgdtw_lockedinfo set ciuserid = couserid where locknr = &lock;
update dgdtw_topografie set locknr = '' where locknr = &lock;
update dgdtw_topografie set verval=sysdate where id= &lock;
commit;

accept var prompt 'repeat process?  [Y/N] ? '
define doit = 'H:\Scripts\stop.sql'
column doit new_value doit noprint
set termout off
select 'H:\Scripts\unlock.sql' doit from dual where upper('&var') like 'Y%';
set termout on
start &doit. 

我需要一个循环脚本,所以如果项目为空或错误,脚本会要求重复或停止。 类似的东西:

accept var prompt 'project number is wrong try again?  [Y/N] ? '

在项目编号正确或答案为“N”之前

1 个答案:

答案 0 :(得分:1)

如果没有该项目的锁定,下面的示例将立即重新启动unlock.sql,只要至少返回一行,就重新定义对unlock.sql的调用,作为对empty.sql的调用。

set verify off

accept project prompt ' project : '

define doit = 'H:\Scripts\unlock.sql'
column doit new_value doit noprint
select 'H:\Scripts\empty.sql' as doit, locknr,description,couserid,ciuserid from dgdtw_lockedinfo where     
description = '&project' and ciuserid is null;
start &doit. 

accept lock prompt ' locknumber  : '

update dgdtw_lockedinfo set ciuserid = couserid where locknr = &lock;
update dgdtw_topografie set locknr = '' where locknr = &lock;
update dgdtw_topografie set verval=sysdate where id= &lock;
commit;

accept var prompt 'repeat process?  [Y/N] ? '
define doit = 'H:\Scripts\stop.sql'
column doit new_value doit noprint
set termout off
select 'H:\Scripts\unlock.sql' doit from dual where upper('&var') like 'Y%';
set termout on
start &doit. 

作为一项改进,我建议将重复问题移到一个单独的SQL文件中,然后使用一个参数调用它,告诉它重启哪个脚本(参见https://docs.oracle.com/cd/B10501_01/server.920/a90842/ch13.htm#1013716

例如,来自' unlock.sql' call' repeat.sql'像这样:

start 'repeat.sql' unlock

使用repeat.sql,如下所示:

accept var prompt 'repeat &1 process?  [Y/N] ? '
define doit = 'H:\Scripts\stop.sql'
column doit new_value doit noprint
set termout off
select 'H:\Scripts\&1.sql' doit from dual where upper('&var') like 'Y%';
set termout on
start &doit.