Step 1:- Create table
CREATE TABLE TEST
(
ID INTEGER,
NAME VARCHAR2(50)
);
Step
2:- Insert records in table
INSERT INTO TEST VALUES('1','Ram');
INSERT INTO TEST VALUES('2','Shyam');
INSERT INTO TEST VALUES('3','Ghanshyam');
Step
3:- Select records from table
SELECT * FROM "TEST" t
ID
|
NAME
|
1
|
Ram
|
2
|
Shyam
|
3
|
Ghanshyam
|
Let's
Test it
Step
1:- Create procedure
CREATE OR REPLACE PROCEDURE USP_TEST1(V_OUT OUT pkg_nonpins.CUR_REF) AS
BEGIN
OPEN V_OUT FOR
SELECT * FROM TEST;
END;
Step
2:- Create procedure
CREATE OR REPLACE PROCEDURE USP_TEST2 AS
V_OUT SYS_REFCURSOR;
V_ID INTEGER;
V_NAME VARCHAR2(20);
BEGIN
USP_TEST1(V_OUT);
LOOP
FETCH V_OUT
INTO V_ID, V_NAME;
IF V_OUT%NOTFOUND THEN
EXIT;
END IF;
DBMS_OUTPUT.PUT_LINE('ID-' || V_ID || ' NAME-' || V_NAME);
END LOOP;
CLOSE V_OUT;
END;
OR
DECLARE
V_OUT SYS_REFCURSOR;
V_ID INTEGER;
V_NAME VARCHAR2(20);
BEGIN
USP_TEST1(V_OUT);
LOOP
FETCH V_OUT
INTO V_ID, V_NAME;
IF V_OUT%NOTFOUND THEN
EXIT;
END IF;
DBMS_OUTPUT.PUT_LINE('ID-' || V_ID || ' NAME-' || V_NAME);
END LOOP;
CLOSE V_OUT;
END;
No comments:
Post a Comment