标签:for oracle result 来源 精简 ora 多行 使用 规则
DECLARE CURSOR emp_cursor IS SELECT empno,ename,job FROM emp; v_empno emp.empno%TYPE; v_name emp.ename%TYPE; v_job emp.job%TYPE; BEGIN OPEN emp_cursor; LOOP FETCH emp_cursor INTO v_empno,v_name,v_job; DBMS_OUTPUT.PUT_LINE(‘员工号为:‘||v_empno||‘姓名是‘||v_name||‘职位:‘||v_job); EXIT WHEN emp_cursor%NOTFOUND; END LOOP; CLOSE emp_cursor; END;
DECLARE CURSOR emp_cursor IS SELECT empno,ename,job FROM emp; v_empno emp.empno%TYPE; v_name emp.ename%TYPE; v_job emp.job%TYPE; BEGIN OPEN emp_cursor; LOOP FETCH emp_cursor INTO v_empno,v_name,v_job; EXIT WHEN emp_cursor%NOTFOUND; END LOOP; IF emp_cursor%ISOPEN THEN DBMS_OUTPUT.PUT_LINE(‘游标已打开‘); DBMS_OUTPUT.PUT_LINE(‘读取了‘||emp_cursor%ROWCOUNT||‘行‘); ELSE DBMS_OUTPUT.PUT_LINE(‘游标没有打开‘); END IF; CLOSE emp_cursor; END;
CREATE TABLE emp_new AS SELECT * FROM emp;
BEGIN UPDATE emp_new SET sal = sal+500 WHERE empno=&empno; IF SQL%FOUND THEN DBMS_OUTPUT.PUT_LINE(‘成功修改‘); COMMIT; ELSE DBMS_OUTPUT.PUT_LINE(‘修改失败‘); ROLLBACK; END IF; END;
DECLARE CURSOR emp_cursor IS SELECT empno,ename,job FROM emp; BEGIN FOR emp_record IN emp_cursor LOOP DBMS_OUTPUT.PUT_LINE(‘员工号:‘||emp_record.empno||‘员工姓名‘||emp_record.ename||‘员工职位‘||emp_record.job); END LOOP; END;
BEGIN FOR emp_record IN (SELECT empno,ename,job FROM emp) LOOP DBMS_OUTPUT.PUT_LINE(‘员工号:‘||emp_record.empno||‘员工姓名‘||emp_record.ename||‘员工职位‘||emp_record.job); END LOOP; END;
DECLARE CURSOR emp_cursor(dno NUMBER)IS SELECT empno,ename,job FROM emp WHERE deptno=dno; BEGIN FOR emp_record IN emp_cursor(&dno) LOOP DBMS_OUTPUT.PUT_LINE(‘员工号‘||emp_record.empno||‘姓名‘||emp_record.ename||‘职位‘||emp_record.job); END LOOP; END;
CREATE TABLE emp_new AS SELECT * FROM emp;
DECLARE CURSOR empnew_cursor IS SELECT ename,job FROM emp_new FOR UPDATE; BEGIN FOR empnew_record IN empnew_cursor LOOP DBMS_OUTPUT.PUT_LINE(‘姓名‘||empnew_record.ename||‘职位‘||empnew_record.job); IF empnew_record.job=‘PRESIDENT‘ THEN UPDATE emp_new SET sal=sal+1000 WHERE CURRENT OF empnew_cursor; ELSIF empnew_record.job=‘MANAGER‘ THEN UPDATE emp_new SET sal=sal+500 WHERE CURRENT OF empnew_cursor; END IF; END LOOP; COMMIT; END;
SELECT * FROM EMP WHERE job in(‘PRESIDENT‘,‘MANAGER‘); SELECT * FROM EMP_NEW WHERE job in(‘PRESIDENT‘,‘MANAGER‘);
标签:for oracle result 来源 精简 ora 多行 使用 规则
原文地址:https://www.cnblogs.com/loveleaf/p/9603785.html