Hey, Oracle, "2."

Source: Internet
Author: User
Tags variables

/************************************************
Me with the cursor

/************************************************
Using an explicit cursor

Define cursor DECLARE
CURSOR cursor_name is select_statement;

Open the cursor Open
OPEN cursor_name

Fetching cursor FETCH
FETCH cursor_name into Variable1,variable2,...;

Closing cursor Close
Close cursor_name;

Explicit cursor Properties
%isopen to determine if opening is turned on true
%found whether to extract data from the result set to True
%notfound whether the data was extracted from the result set and not extracted to true
%rowcount returns the actual number of rows that have been extracted to the current behavior

Parameter cursors

To implement multiple open cursors with different parameter values, you can generate different result sets
CURSOR cursor_name (parameter_name datatype) is select_statement;

Update/delete data with cursors
CURSOR cursor_name (parameter_name datatype) is select_statement for UPDATE [of Column_reference] [nowait];

For update is used to add a row of shared locks on the result set data to prevent other users from performing the DML operation again
of determining those tables to be locked
NOWAIT specifies that execution does not wait for a lock, and if another session is already locked on the action line, the current session displays an error prompt

UPDATE table_name SET column= ... WHERE Current OF cursor_name;
DELETE table_name WHERE Current OF cursor_name;

Cursor Loops

Oracle implicitly opens the cursor, extracts the cursor, and closes the cursor
For Record_name in Cursor_name Loop
Statement1;
Statement2;
...
End LOOP;

If you do not need to use any of the cursor properties while looping, you can use the subquery directly
For Record_name in (select_statement) loop
Statement1;
Statement2;
...
End LOOP;

Using cursor variables

Defining REF CURSOR types and cursor variables
TYPE Ref_type_name is ref CURSOR [return return_type];
Cursor_variable Ref_type_name;

Open cursor
OPEN cursor_variable for select_statement;

Extract cursor Data
FETCH cursor_variable into Variable1,variable2,...;

Closing cursor Close
Close cursor_variable


Related Article

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.