执行 PL/SQL 过程的 Ant exec 可执行文件失败
Ant exec executable to execute PL/SQL procedure fails
我有一个 Ant 脚本来执行 SQL 和 PL/SQL 过程。
<exec executable="sqlplus" failonerror="true" >
<arg value="${user}/${password}@${DB}" />
<arg value="@${scriptFilename}" />
</exec>
以上代码执行 SQL 个脚本和程序包,但不执行以下过程:
BEGIN
-- drop functions
FOR R IN (
SELECT owner, object_name
FROM all_objects
WHERE owner='FCPOTP'
AND OBJECT_TYPE IN ('FUNCTION'))
LOOP
EXECUTE IMMEDIATE 'drop function '||R.owner||'.'||R.object_name;
END LOOP;
-- drop procedure
FOR R IN (
SELECT owner, object_name
FROM all_objects
WHERE owner='FCPOTP'
AND OBJECT_TYPE IN ('PROCEDURE'))
LOOP
EXECUTE IMMEDIATE 'drop procedure '||R.owner||'.'||R.object_name;
END LOOP;
END;
如何使用相同的 exec sqlplus
可执行文件来执行所有内容?
您没有收到错误,并且从注释的输出中您没有看到正在执行的块。那是因为它不是。 From the documentation:
SQL*Plus stores the subprograms you enter in the SQL buffer. Execute the current subprogram with a RUN or slash (/) command. A semicolon (;) is treated as part of the PL/SQL subprogram and will not execute the command.
目前您的匿名块(子程序)正在进入 'SQL buffer',但从未被执行。
您只需要在您的脚本文件中添加一个 /
,在您的匿名块之后:
...
LOOP
EXECUTE IMMEDIATE 'drop procedure '||R.owner||'.'||R.object_name;
END LOOP;
END;
/
我有一个 Ant 脚本来执行 SQL 和 PL/SQL 过程。
<exec executable="sqlplus" failonerror="true" >
<arg value="${user}/${password}@${DB}" />
<arg value="@${scriptFilename}" />
</exec>
以上代码执行 SQL 个脚本和程序包,但不执行以下过程:
BEGIN
-- drop functions
FOR R IN (
SELECT owner, object_name
FROM all_objects
WHERE owner='FCPOTP'
AND OBJECT_TYPE IN ('FUNCTION'))
LOOP
EXECUTE IMMEDIATE 'drop function '||R.owner||'.'||R.object_name;
END LOOP;
-- drop procedure
FOR R IN (
SELECT owner, object_name
FROM all_objects
WHERE owner='FCPOTP'
AND OBJECT_TYPE IN ('PROCEDURE'))
LOOP
EXECUTE IMMEDIATE 'drop procedure '||R.owner||'.'||R.object_name;
END LOOP;
END;
如何使用相同的 exec sqlplus
可执行文件来执行所有内容?
您没有收到错误,并且从注释的输出中您没有看到正在执行的块。那是因为它不是。 From the documentation:
SQL*Plus stores the subprograms you enter in the SQL buffer. Execute the current subprogram with a RUN or slash (/) command. A semicolon (;) is treated as part of the PL/SQL subprogram and will not execute the command.
目前您的匿名块(子程序)正在进入 'SQL buffer',但从未被执行。
您只需要在您的脚本文件中添加一个 /
,在您的匿名块之后:
...
LOOP
EXECUTE IMMEDIATE 'drop procedure '||R.owner||'.'||R.object_name;
END LOOP;
END;
/