Larkin-oracle Package

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.