Oracle存储过程模板


PROCEDURE proc_test(p_id             IN NUMBER,
                    v_cur            OUT SYS_REFCURSOR,
                    p_result_code    OUT NUMBER,
                    p_result_message OUT VARCHAR2) AS
  p_flag NUMBER;
  p_row  frm_table1%ROWTYPE;
BEGIN

  p_result_message := '成功';
  p_result_code    := '1';

  BEGIN
  
    SELECT col_a INTO p_flag FROM frm_table2 WHERE id = p_id;
  
  EXCEPTION
    WHEN no_data_found THEN
      p_result_code    := '0';
      p_result_message := '无数据';
      RETURN;
    
  END;

  FOR rs IN (SELECT col_b FROM frm_table3 WHERE id = p_id) LOOP
  
    dbms.output_putline("col_b" || col_b);
  
  END LOOP;

  OPEN v_cur FOR
    SELECT * FROM frm_table4;

  COMMIT;

EXCEPTION
  WHEN OTHERS THEN
    ROLLBACK;
    p_result_code    := '0';
    p_result_message := '系统异常:' || SQLERRM;
END;

 

posted @ 2021-04-04 08:48  天天代码码天天  阅读(17)  评论(0编辑  收藏  举报  来源