Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

oracle - SQLplus decode to execute scripts

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);

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:sqlplusscript1.sql', 
  3                'c:sqlplusscript2.sql'
  4                ) our_script
  5  from dual;




SQL> @&script;

SCRIPT                                                                          
--------                                                                        
script_1                                                                        

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...