All knowledge is better than DEMO,SO
The test table required by the demo
CREATE TABLE" SCOTT". " TEST "(" ID " Number(6,0) not NULLENABLE, "USERNAME"VARCHAR2( -BYTE), "Userpwd"VARCHAR2( -BYTE), "New_email"VARCHAR2( -BYTE), "RegDate" DATEDEFAULT NULL, "Userage" Number(4,0), "Score" Number( -,0), CONSTRAINT"TEST_PK"PRIMARY KEY("ID") USINGINDEXPCTFREETenInitrans2Maxtrans255 COMPUTE STATISTICSSTORAGE (INITIAL65536 NEXT 1048576Minextents1MAXEXTENTS2147483645Pctincrease0Freelists1FREELIST GROUPS1Buffer_poolDEFAULTFlash_cacheDEFAULTCell_flash_cacheDEFAULT) tablespace "USERS" ENABLE) SEGMENT CREATION IMMEDIATE PCTFREETenPctused +Initrans1Maxtrans255nocompress LOGGING STORAGE (INITIAL65536 NEXT 1048576Minextents1MAXEXTENTS2147483645Pctincrease0Freelists1FREELIST GROUPS1Buffer_poolDEFAULTFlash_cacheDEFAULTCell_flash_cacheDEFAULT) tablespace "USERS";
First, you define the header, declare the structure
1 Create or ReplacePackage Testpackage as 2 3 /*TODO Enter package declarations (types, exceptions, methods etc) here*/ 4 --Define structure Body5Type Te_stu isRecord (6PID Test.id%type,7PName Test.username%type,8Page Test.userage%type,9Pscore Test.score%typeTen ); One --Defining Cursors AType Test_cursor isRefcursor; - procedureGtest (useridinch Number, tlist out test_cursor); - ENDTestpackage;
Then we create the subject
Create or ReplacePackage BODY Testpackage as procedureGtest (useridinch Number, tlist out Test_cursor) asR_stu Test%RowType; BEGIN --todo:procedure testpackage.gtest Required Implementation OpenTlist for SelectId,username,userage,score fromtest; --where Id=userid; ENDgtest;ENDTestpackage;
Now that a basic package is finished, let's make a call and create a Package.sql
Declarex testpackage.test_cursor; T Testpackage.te_stu;beginTestpackage.gtest (1, x); LoopFetchX intoT; Exit whenX%NotFound; Dbms_output.put_line ('name ='||t.pname); EndLoop;End;
Reference cursors typically return a result set for use. From the test we can see that the Oracle package is equivalent to the class we are very familiar with.
Larkin-oracle Package