Home  >  Article  >  Database  >  Oracle 包内的存储过程的动态sql

Oracle 包内的存储过程的动态sql

WBOY
WBOYOriginal
2016-06-07 17:28:00946browse

---创建包 create or replace package test_pkg is g_public_flag varchar2(1); function test_function(p_param1 varcha

---创建包
 create or replace package test_pkg is
  g_public_flag varchar2(1);
 
  function test_function(p_param1 varchar2,
                          p_param2 varchar2) return varchar2;
  function  hello_function(p_param3 varchar2) return varchar2;
  procedure ff(p1 varchar2);                   
  end;
 

 --包体
  create or replace package body test_pkg is
  g_private_flag varchar2(1) := 'Y';
 

  function test_function(p_param1 varchar2,
                          p_param2 varchar2) return varchar2
    is
      val varchar2(10):='hello';
   
    begin
      dbms_output.put_line('helo');
      return val;
    end ;
   
  function hello_function(p_param3 varchar2) --参数与包头中必须保持一致
    return varchar2 is
    val varchar2(10):='hello';
  begin
      dbms_output.put_line('world');
      return val;
  end;
  procedure ff(p1 varchar2) is
    flag number;
    pp1  VARCHAR2(10):='p'; 
    p2  VARCHAR2(10):='p';
    p3  VARCHAR2(10):='p';
    p4  VARCHAR2(10):='p';
  begin
        select count(*)into flag from  all_all_tables where table_name='LOGTABLE1';
        dbms_output.put_line(flag);
        if(flag = 0) then
        execute immediate
        'CREATE TABLE logtable1 (userid VARCHAR2(10), logdate VARCHAR2(10),exception_id VARCHAR2(10),exception_msg VARCHAR2(10))';
        end if; 
        execute immediate 'insert into logtable1 values (:1,:2,:3,:4)' using '1','1','2','3'; --只能动态插入
  end;
  end; 

----测试
 declare
 begin
    dbms_output.put_line(test_pkg.test_function('1','1'));
    dbms_output.put_line(test_pkg.hello_function('1'));
    test_pkg.ff('dd');
 end;
 select * from logtable1;
 drop table logtable1

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn