ITPub博客

首页 > 数据库 > Oracle > ref cursor ,动态SQL

ref cursor ,动态SQL

原创 Oracle 作者:419088217 时间:2015-08-12 13:42:47 0 删除 编辑
DECLARE
  TYPE ref_cursor IS REF CURSOR;

  v_ref_cursor ref_cursor;

  CURSOR cur_get_order IS
    SELECT organization_id,
           organization_code
      FROM mtl_parameters;
  rec_cur_get_ordline_details cur_get_order%ROWTYPE;

  v_sql      VARCHAR2(200);
  p_chr_code VARCHAR2(20) := 'SZK';
  p_num_id   NUMBER := NULL;
BEGIN
  v_sql := ' select organization_id, organization_code from mtl_parameters where organization_code = :p_code';

  IF p_num_id IS NOT NULL THEN
    v_sql := v_sql || ' and organization_id = :p_id ';
 
  ELSE
    v_sql := v_sql || ' and nvl( :p_id, 1 ) = 1 ';
  END IF;
  dbms_output.put_line(v_sql);

  OPEN v_ref_cursor FOR v_sql
    USING p_chr_code, p_num_id;

  LOOP
    FETCH v_ref_cursor
      INTO rec_cur_get_ordline_details;
    EXIT WHEN v_ref_cursor%NOTFOUND;
    dbms_output.put_line(rec_cur_get_ordline_details.organization_id);
  END LOOP;
  CLOSE v_ref_cursor;

END;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/13975809/viewspace-1769211/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-12-25

  • 博文量
    63
  • 访问量
    52243