我从ant脚本调用PL / SQL过程。在输出窗口中,它显示“构建成功”,但存储过程proc.sql
不会执行。
这是我的构建脚本:
<target name="DATA">
<property name="oracle.scriptPath" value="D:\\ganganshu" />
<property name="oracle.tns_alias2" value="wind"/>
<!-- Oracle user name -->
<property name="oracle.user_name2" value="SILO2" />
<!-- Oracle Password -->
<property name="oracle.password2" value="SILO2" />
<exec executable="sqlplus" failonerror="true">
<arg value="${oracle.user_name2}/${oracle.password2}@${oracle.tns_alias2}"/>
<arg value="@${oracle.scriptPath}\\ELEM10_ELEM_PHX_WTPART.sql"/>
<arg value="@${oracle.scriptPath}\\proc.sql"/>
</exec>
</target>
我的存储过程是:
create or replace
PROCEDURE ELEM10_ELEM_PHX_ATT_WTPART
AS
CURSOR targ_dest_relation IS
SELECT sourcecolumn FROM mapping where destinationtable='ATT_WTPART';
BEGIN
DECLARE
source_Table varchar2(255) := 'ELEM10_ELEM_PHX';
destination_Table varchar2(255) := 'ATT_WTPART';
src_Column varchar2(255);
src_Type varchar2(255);
src_Type_Value varchar2(255);
src_Name varchar2(255);
src_Name_Value varchar2(255);
dest_Column varchar2(255);
dest_Column_Value varchar2(255);
query1 varchar2(255);
BEGIN
FOR rec IN targ_dest_relation loop
dbms_output.put_line('destination_Table: ' || destination_Table);
dbms_output.put_line('source_Table: ' || source_Table);
src_Column := rec.sourcecolumn;
dbms_output.put_line('src_Column: ' || src_Column);
src_Type := 'select data_type from user_tab_columns where
table_name ='''||source_Table||'''and column_name='''||
src_Column ||'''';
dbms_output.put_line('src_Type: ' || src_Type);
execute immediate src_Type INTO src_Type_Value;
dbms_output.put_line('src_Type_Value: ' || src_Type_Value);
dest_Column := 'select DEST_COLUMN from ATT_TABLE_MAPPING where
SOURCETYPE='''|| src_Type_Value || '''';
dbms_output.put_line('dest_Column: ' || dest_Column);
execute immediate dest_Column INTO dest_Column_Value;
dbms_output.put_line('dest_Column_Value: ' || dest_Column_Value);
src_Name := 'select column_name from user_tab_columns where
table_name ='''|| source_Table ||''' and column_name= ''' ||
src_Column || '''';
dbms_output.put_line('src_Name: ' || src_Name);
execute immediate src_Name INTO src_Name_Value;
dbms_output.put_line('src_Name_Value: ' || src_Name_Value);
EXECUTE IMMEDIATE 'INSERT INTO ' || destination_Table || ' (IBANAME,' ||
dest_Column_Value || ') SELECT :name,' || src_Column ||
' FROM ' || source_Table USING src_Name_Value;
END loop;
END;
END;
为什么这不会运行存储过程?
答案 0 :(得分:1)
在您的Ant脚本中,您尝试执行一个sqlplus
执行两个文件,但这不起作用。 sqlplus
只执行第一个文件而忽略第二个文件。如果要在两个不同的文件中创建过程和执行,则必须运行sqplus
两次。否则你的Ant脚本对我来说没问题。
以下是如何使用单个sqlplus
运行创建,执行和删除过程的示例。
所有内容都在文件foo.sql
中:
$ cat foo.sql
-- just for demonstration with dbms_output
set serveroutput on
-- create procedure
create or replace procedure foo is
begin
dbms_output.put_line('Hello!');
end;
/
show errors
-- execute procedure
exec foo
-- remove procedure
drop procedure foo;
-- exit sqlplus
exit
sqlplus
执行:
$ sqlplus -L joe/joe @foo.sql
SQL*Plus: Release 11.2.0.2.0 Production on Tue Dec 17 16:31:20 2013
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
Procedure created.
No errors.
Hello!
PL/SQL procedure successfully completed.
Procedure dropped.
Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
$
答案 1 :(得分:0)
尝试在最后添加:
/
EXECUTE ELEM10_ELEM_PHX_ATT_WTPART;
/