【发布时间】:2021-10-29 02:18:03
【问题描述】:
我在docker 容器中安装了Oracle 实例,并在容器启动时放置了sql 脚本:
Dockerfile:
FROM...
...
CMD powershell echo @C:\scripts\entrypoint.sql | sqlplus -S sys/password as sysdba
entrypoint.sql:
set serveroutput on format wrapped;
declare
userexist integer;
db_schema_version varchar2(20);
begin
select count(*) into userexist from dba_users where username='DEV';
if (userexist = 0) then
dbms_output.put_line('SCHEMA NOT FOUND!');
dbms_output.put_line('CONNECTION STRING: ' || 'sqlplus sys/password@localhost/ORA193 as sysdba');
elsif (userexist = 1) then
dbms_output.put_line('SCHEMA FOUND!');
select DB_SCHEMA_VERSION into db_schema_version from DEV.VER_INFO where CODE = 'CORE';
dbms_output.put_line('DB_SCHEMA_VERSION: ' || db_schema_version);
dbms_output.put_line('CONNECTION STRING: ' || 'sqlplus DEV/password@localhost/ORA193');
end if;
end;
/
问题是查询 select DB_SCHEMA_VERSION into db_schema_version from DEV.VER_INFO where CODE = 'CORE'; 正在执行,即使 elsif 条件是 false
编写PL/SQL 以获取select 查询仅在条件为true 的情况下执行的正确方法是什么?
【问题讨论】:
-
@WalterMitty 这是 PL/SQL,所以
then语句的范围在下一个end if结束,并且没有脚本解释器。
标签: windows oracle docker powershell plsql