在Oracle中的相同假脱机中生成输出

时间:2014-06-26 10:24:00

标签: sql oracle oracle11g oracle10g sql-scripts

SPOOL c:\out.SPL

    SELECT * FROM a WHERE ACCOUNT_NUMBER='&CRN' ;
    SELECT * FROM b WHERE ACCOUNT_NUMBER='&CRN' ;

    Spool off
    accept op prompt 'Do u want to generate el spool,type y ' default 'n'
    SAVE c:\query2.SQL 
       select * from getm_liab   where liab_no='a' ;

    column c me new_value x
    set termout off
    select decode(lower('&op'),'y','C:\query2.SQL','n', 'null') c from dual;

    spool c:\out.SPL APPEND
    @&x

上面的脚本是我首先运行一组查询,只有当用户输入y时我才会运行剩余的查询集。但它没有用,请建议

1 个答案:

答案 0 :(得分:0)

q1.sql的内容:

accept op prompt 'Do u want to generate el spool,type y ' default 'n'

column c new_value x
set veri off
set echo off
set head off
spool qyn.sql
select decode(lower('&op'),'y','@','n', '--')||'q2'  from dual;
spool off

@qyn '&1'

q2.sql的内容:

select 'boe' from dual where dummy = '&1';
select 'oops' from dual where dummy = '&1';

sqlplus foo / far @ orcl @ q1 X. 输出Y:

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 26 15:00:13 2014

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


Verbonden met:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

Do u want to generate el spool,type y y

@q2


boe


oops

输出N:

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 26 15:00:54 2014

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


Verbonden met:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

Do u want to generate el spool,type y n

--q2

这是处理此问题的方法之一。最简单的方法是使用位置变量,但也可以将它们定义为命名变量。