2014-04-17 38 views
1

我正在使用以下過程來包裝PL/SQL代碼。SYS.DBMS_DDL.WRAP不允許編譯指示和intctx

declare 
    l_source DBMS_SQL.VARCHAR2A; 
    l_wrap DBMS_SQL.VARCHAR2A; 
    l_wrap1 clob; 
    typ_ibt utl_file.file_type; 
    cnt  number := 0; 
    v_directory varchar2(400) := 'd:\ftpedi\eqpm\eqpm_hold\'; 

    cursor cur_name_get is 
    select distinct name object_name,type object_type 
    from user_source 
    where type = 'PROCEDURE' 
    and name = 'PROCESS_TIME_INSERT'; 

    cursor cut_text_get (p_type in varchar2 , p_name in varchar2) is 
    select replace(text,chr(10),'') text 
    from user_source 
    where type = p_type 
    and name = p_name; 
begin 

for i in cur_name_get 
loop 
    l_source.delete;l_wrap.delete; 
    open cut_text_get (i.object_type,i.object_name); 
    fetch cut_text_get bulk collect into l_source; 
    close cut_text_get; 
    l_source (1) := 'CREATE OR REPLACE ' || l_source (1); 
    l_wrap := SYS.DBMS_DDL.WRAP(ddl => l_source, 
           lb => 1, 
           ub => l_source.count); 
    for i in 1..l_wrap.count 
    loop 
     if i = 1 
     then 
      l_wrap1 := l_wrap(i); 
     else 
      l_wrap1 := l_wrap1 || l_wrap(i); 
     end if; 
     insert into ibt_global_inter_transfer (git_process_id,git_c_1) 
     values (3004, l_wrap1); 
    end loop;         
    end loop; 

exception when others 
then 
    dbms_output.put_line('sqlerrm '||sqlerrm||dbms_utility.format_error_backtrace); 
end; 

上述程序扭曲正常的程序,但不允許像「用法」的特殊字符。

下面是示例過程,它不包裝。

CREATE OR REPLACE 
PROCEDURE xml_insert (p_in_xml in xmltype ,p_status out varchar2,p_message out varchar2) is 
intctx DBMS_XMLSTORE.ctxtype; 
rows number; 
begin 
    p_status := 'S'; 
    p_message := 'Success'; 

    intctx := Dbms_xmlstore.newcontext('IBT_GLOBAL_INTER_TRANSFER'); 
    dbms_xmlstore.clearupdatecolumnlist(intctx); 
    dbms_xmlstore.setupdatecolumn(intCtx,'GIT_PROCESS_ID'); 
    dbms_xmlstore.setupdatecolumn(intCtx,'GIT_SESSION_ID'); 
    rows := Dbms_xmlstore.insertxml(intctx,p_in_xml); 
    dbms_xmlstore.closecontext(intctx); 
exception when others 
then 
    p_status := 'R'; 
    p_message := sqlerrm||dbms_utility.format_error_backtrace; 
    return;  
end; 

任何人都可以幫忙嗎?

+0

它適用於我的12.1.0.1.0。然而,我不得不做一些小的修改來運行你的代碼,比如改變'name ='PROCESS_TIME_INSERT';',添加'pragma',並用dbms_output替換插入。如果這是一個解析錯誤,那麼這些細微的更改可能會產生很大的差異。你能稍微修改你的代碼,以便其他人可以測試100%相同的版本嗎? –

+0

Hi @jonearles,你可以發佈修改後的代碼作爲解決方案,以便我可以在上面的代碼片段中看到所做的更改。 – Sravan

+0

@Sravan:我添加了代碼作爲答案。 –

回答

1

更新

(我誤解了這個問題。我想你的意思是包裹代碼沒有被創建,現在我明白了真正的問題是包裝的輸出不編譯。)

刪除replace,一些線條之間需要有空白區域。

替換:

--select replace(text,chr(10),'') text 

與:

select text 

步驟:

CREATE OR REPLACE 
PROCEDURE xml_insert (p_in_xml in xmltype ,p_status out varchar2,p_message out varchar2) is 
intctx DBMS_XMLSTORE.ctxtype; 
rows number; 
pragma autonomous_transaction; --ADDED 
begin 
    p_status := 'S'; 
    p_message := 'Success'; 

    intctx := Dbms_xmlstore.newcontext('IBT_GLOBAL_INTER_TRANSFER'); 
    dbms_xmlstore.clearupdatecolumnlist(intctx); 
    dbms_xmlstore.setupdatecolumn(intCtx,'GIT_PROCESS_ID'); 
    dbms_xmlstore.setupdatecolumn(intCtx,'GIT_SESSION_ID'); 
    rows := Dbms_xmlstore.insertxml(intctx,p_in_xml); 
    dbms_xmlstore.closecontext(intctx); 
exception when others 
then 
    p_status := 'R'; 
    p_message := sqlerrm||dbms_utility.format_error_backtrace; 
    return;  
end; 
/

PL/SQL塊包裹代碼:

declare 
    l_source DBMS_SQL.VARCHAR2A; 
    l_wrap DBMS_SQL.VARCHAR2A; 
    l_wrap1 clob; 
    typ_ibt utl_file.file_type; 
    cnt  number := 0; 
    v_directory varchar2(400) := 'd:\ftpedi\eqpm\eqpm_hold\'; 

    cursor cur_name_get is 
    select distinct name object_name,type object_type 
    from user_source 
    where type = 'PROCEDURE' 
    and name = 'XML_INSERT'; --CHANGED 

    cursor cut_text_get (p_type in varchar2 , p_name in varchar2) is 
    --select replace(text,chr(10),'') text --WOOPS! 
    select text 
    from user_source 
    where type = p_type 
    and name = p_name; 
begin 

for i in cur_name_get 
loop 
    l_source.delete;l_wrap.delete; 
    open cut_text_get (i.object_type,i.object_name); 
    fetch cut_text_get bulk collect into l_source; 
    close cut_text_get; 
    l_source (1) := 'CREATE OR REPLACE ' || l_source (1); 
    l_wrap := SYS.DBMS_DDL.WRAP(ddl => l_source, 
           lb => 1, 
           ub => l_source.count); 
    for i in 1..l_wrap.count 
    loop 
     if i = 1 
     then 
      l_wrap1 := l_wrap(i); 
     else 
      l_wrap1 := l_wrap1 || l_wrap(i); 
     end if; 
     --insert into ibt_global_inter_transfer (git_process_id,git_c_1) 
     --values (3004, l_wrap1); 
     dbms_output.put_line(l_wrap1); 
    end loop;         
    end loop; 

exception when others 
then 
    dbms_output.put_line('sqlerrm '||sqlerrm||dbms_utility.format_error_backtrace); 
end; 
/
+0

@jonearls感謝您的代碼。不幸的是,我們只有Oracle11g。我們將在Oracle11g中嘗試它並讓你知道狀態。 – Sravan

+0

Hi @jonearles在編譯封裝源時出現以下錯誤 –

+0

處理中... (1):PLS-00103:遇到以下符號之一時出現符號「ISINTCTX」: (1): (1) :; (1):確定性parallel_enable流水線result_cache (1):將符號「is」替換爲「ISINTCTX」以繼續。 (2):PLS-00103:當期望以下之一時遇到符號「文件結束」: (2): (2):begin函數編譯指示過程子類型<標識符> (2) :當前光標刪除 (2):以前存在 過程XML_INSERT編譯時有錯誤;狀態無效 –