DECLARE
a NUMBER := 3333;
TYPE rc IS REF CURSOR; -- ref cursor declare
l_cursor rc;
l_ename emp.ename%TYPE;
l_deptno dept.deptno%TYPE;
l_value NUMBER;
BEGIN
IF (a = 30)
THEN
OPEN l_cursor FOR 'select ename from emp'; -- opening the cursor for query
FETCH l_cursor INTO l_ename;
CLOSE l_cursor;
DBMS_OUTPUT.put_line ('l_ename : = ' || l_ename);
ELSIF (a = 20)
THEN
OPEN l_cursor FOR SELECT deptno FROM dept;
FETCH l_cursor INTO l_deptno;
CLOSE l_cursor;
DBMS_OUTPUT.put_line ('l_deptno : = ' || l_deptno);
ELSE
OPEN l_cursor FOR SELECT 1 FROM DUAL;
FETCH l_cursor INTO l_value;
CLOSE l_cursor;
DBMS_OUTPUT.put_line ('l_value : = ' || l_value);
END IF;
END;
/
No comments:
Post a Comment
Please do not add any spam links or abusive comments.