首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SYS.DBMS_DDL.WRAP不允许杂注和intctx

SYS.DBMS_DDL.WRAP不允许杂注和intctx
EN

Stack Overflow用户
提问于 2014-04-17 20:27:22
回答 1查看 200关注 0票数 1

我使用下面的过程包装PL/SQL代码。

代码语言:javascript
复制
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;

上面的过程扭曲了正常的过程,但不允许使用特殊字符,如“PRAGMA”。

下面是示例过程,它不是包装。

代码语言:javascript
复制
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;

有人能帮上忙吗?

EN

回答 1

Stack Overflow用户

发布于 2014-04-22 07:46:15

更新

(我误解了这个问题。我以为您的意思是包装的代码不是创建的,现在我明白了真正的问题是包装的输出不能编译。)

删除replace,需要在某些行之间留出空格。

替换:

代码语言:javascript
复制
  --select replace(text,chr(10),'') text

通过以下方式:

代码语言:javascript
复制
  select text

操作步骤:

代码语言:javascript
复制
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块包装代码:

代码语言:javascript
复制
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;
/
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23133081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档