Oracle 记录

存储过程实现多条件查询

CREATE OR REPLACE PACKAGE TESTPACKAGE is
type TEST_CURSOR is REF CURSOR;
PROCEDURE PROCEDURE3 (RNAME IN VARCHAR2, TEST_CURSOR OUT TEST_CURSOR);
END TESTPACKAGE;

CREATE OR REPLACE PACKAGE BODY TESTPACKAGE IS
  PROCEDURE PROCEDURE3 
  (
    RNAME IN VARCHAR2,
    TEST_CURSOR OUT TEST_CURSOR
  ) is
  str_sql varchar2(500);
  BEGIN
    str_sql := 'select * from ROLE where 1=1 ';
    
    if RNAME is not null or NVL(RNAME, 'null') <> 'null' then
         str_sql := str_sql || 'and RNAME = ' || RNAME || '';
    end if;
    open TEST_CURSOR for str_sql;
    
  END PROCEDURE3;
END TESTPACKAGE;

调用:

1.执行

var c refcursor;
exec TESTPACKAGE.PROCEDURE3('', :c);

-------------------------------------------------

2.打印

print :c;

posted @ 2015-02-11 11:12  e.e.p  阅读(207)  评论(0编辑  收藏  举报