SQLPLus 如果值不为空则解码

Fra*_*ser 1 oracle sqlplus

我有一个 sqlplus 脚本,如果变量不为空,那么我想执行脚本并传递值。如果它为空,那么我想执行不同的脚本。我有以下内容:

col scr new_value script
set term off
select decode('&partitions', 'true', 'CreateTablesPartitions', 'CreateTables') scr from   dual;
set term on
@@&script &partitions
Run Code Online (Sandbox Code Playgroud)

检查变量分区是否为 true,然后执行 CreateTablePartitions。如何检查变量分区是否为空?

Daz*_*zaL 5

只需在解码字符串中添加 null 和要解码的值即可。

select decode('&partitions', 'true', 'CreateTablesPartitions',
              null, 'itsnull', 'CreateTables') scr 
from   dual;
Run Code Online (Sandbox Code Playgroud)

所以如果它为空,那么结果将是itsnull