SQL是或否重复功能

时间:2015-12-23 09:37:36

标签: sql oracle sqlplus repeat

goto1:

           --- update tabellen
    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 ' yes or no '

    if (var = yes) then 
    goto1

    and if (var = no)
       exit
    end if

如果用户输入是

,则需要重复一个功能

有没有办法按输入重复命令?

1 个答案:

答案 0 :(得分:1)

如果你真的必须这样做,可以通过start命令使用递归来循环。

使用内容

创建'递归结束'文件stop.sql
prompt OK, end of repeat
exit

使用以下内容创建文件repeat.sql

set echo off verify off

select 'Your SQL statements go here' from dual;

accept var prompt 'Repeat the SQL statement [yes or no] ? '

define doit = 'stop.sql'
column doit new_value doit noprint
set termout off
select 'repeat.sql' doit from dual where upper('&var') like 'Y%';
set termout on
start &doit.

这是一个示例运行:

SQL*Plus: Release 11.2.0.4.0 Production on Mon Jan 11 23:30:24 2016

Copyright (c) 1982, 2014, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options


'YOURSQLSTATEMENTSGOHERE'
---------------------------
Your SQL statements go here

Repeat the SQL statement [yes or no] ? yes

'YOURSQLSTATEMENTSGOHERE'
---------------------------
Your SQL statements go here

Repeat the SQL statement [yes or no] ? y

'YOURSQLSTATEMENTSGOHERE'
---------------------------
Your SQL statements go here

Repeat the SQL statement [yes or no] ? n
OK, no further repetitions.