SQLplus解码以执行脚本 [英] SQLplus decode to execute scripts

查看:87
本文介绍了SQLplus解码以执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写要在sqlplus 11中运行的脚本.我有一个用户定义的变量,称为压缩.如果是这样,那么我想运行脚本CreateTablesCompression,否则运行.我有以下内容:

I am writing a script to be run in sqlplus 11. I have a user defined variable called compression. If this is true then I want to run the script CreateTablesCompression, otherwise run. I have the following:

decode(compression,'true',@@CreateTablesCompression,@@CreateTables);

但是,当我运行此命令时,我抛出了错误:未知命令以"decode ..."开头.

However,when I run this I am thrown the error: unknown command beginning "decode...

我在这里缺少什么吗?我看不出为什么SQLPlus无法识别解码?

Am I missing something here, I can't see why SQLPlus wouldn't recognise decode?

推荐答案

Decode不是SQL * PLUS命令,您不能仅在pl/sql块或查询中直接在sql * plus中使用它.因此,这是一个如何完成条件分支的示例: 我们声明一个变量flag,它将调节要运行的两个可用脚本中的哪一个.

Decode is not a SQL*PLUS command, you cannot use it directly in sql*plus only inside a pl/sql block or a query. So here is an example of how a conditional branching can be done: We declare a variable flag which going to regulate which one of two available scripts to run.

SQL> variable flag varchar2(7);
SQL> exec :flag := 'true';

PL/SQL procedure successfully completed.

SQL> column our_script new_value script noprint;
SQL> select decode(:flag, 'true', 
  2                'c:\sqlplus\script1.sql', 
  3                'c:\sqlplus\script2.sql'
  4                ) our_script
  5  from dual;




SQL> @&script;

SCRIPT                                                                          
--------                                                                        
script_1                                                                        

这篇关于SQLplus解码以执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆