摘要:
开始CREATE OR REPLACE PROCEDURE query_emp(p_id IN emp.empno%TYPE, p_name OUT emp.ename%TYPE, p_salary OUT emp.sal%TYPE)ISBEGIN SELECT ename,sal INTO p_name,p_salary FROM emp WHERE empno = p_id;END query_emp;生成完毕后,可以这样来执行:DECLARE g_name varchar2(20); g_salary NUMBER(4);BEGIN query_emp(7369,... 阅读全文
摘要:
开始想要知道,是否在一条SQL执行完毕之后,有否机会在接下来的程序运行段看SQL%NOTFOUND的值。事实上,它立即跳到了异常段。SET SERVEROUTPUT ON;DECLARE v_ename emp.ename%TYPE; e_norecord EXCEPTION; PRAGMA EXCEPTION_INIT (e_norecord, -20001); err_num NUMBER; err_msg VARCHAR2(100);BEGIN SELECT ename INTO v_ename FROM emp where empno=3000; IF SQL%... 阅读全文
摘要:
开始SET SERVEROUTPUT ON;DECLARE v_ename emp.ename%TYPE; e_norecord EXCEPTION; PRAGMA EXCEPTION_INIT (e_norecord, -20001); err_num NUMBER; err_msg VARCHAR2(100);BEGIN SELECT ename INTO v_ename FROM emp WHERE empno=3000; EXCEPTION WHEN OTHERS THEN err_num := SQLCODE; err_msg := SUBST... 阅读全文
摘要:
开始set serveroutput on;DECLARE e_no_rows EXCEPTION; e_integrity EXCEPTION;BEGIN BEGIN RAISE e_no_rows; END;EXCEPTION WHEN e_no_rows THEN DBMS_OUTPUT.PUT_LINE('no rows exception');END;运行结果:anonymous block completedno rows exception结束 阅读全文
摘要:
开始set serveroutput on;DEFINE p_deptno = 10DECLARE e_emps_remaining EXCEPTION; PRAGMA EXCEPTION_INIT (e_emps_remaining, -2292);BEGIN DELETE FROM dept WHERE deptno = & p_deptno; COMMIT;EXCEPTION WHEN e_emps_remaining THEN DBMS_OUTPUT.PUT_LINE('Cannot remove dept' || TO_CHAR(&... 阅读全文