Declaring and opening cursors + cursors + declaration cursors + Open Cursors

Source: Internet
Author: User

declaring and opening cursors
Cursors
A 1 cursor is a data query from the database in the form of a temporary table stored in memory.
A 2 cursor can manipulate data stored in memory, return one or a set of records, or do not return records.
3pl/sql Records and table types can also store data, but operate on a set of data stored in memory, without the cursor aspect
4 cursor Operation: Declaration cursor, open cursor, advance cursor, close cursor.
5 cursors are similar to pointers and can handle one row at a time
6 Cursor Classification
1 Display cursors: Specialized processing of multiple rows of data returned by a SELECT statement
2 implicit cursors: For processing SELECT INTO and DML statements, Oracle automatically creates declarative implicit cursors to process the result data.

Reason: RowType is saving a row of data, and I returned too many lines

After correction

declaring Cursors
1 declares a cursor, primarily by defining a cursor name to correspond to a query statement, which enables you to use the cursor to perform a single operation on the result set returned by the query statement.
Grammar
Cursor Cursorname
"(parametername" in "Data_type" {: =| default}value "", ...) "
Is
Select_statement
"For update of column", ... "" nowait "";

Cursorname: Cursor Name

ParameterName "In": defines an input parameter for a cursor, the IN keyword can be omitted, the user needs to assign a value to an input parameter when the cursor is opened, the input parameter can be multiple, separated by a comma (,).
Data_type: Specifies the data type for the input parameter, but cannot specify the precision or length, such as the use of VARCHAR2, but cannot use VARCHAR2 (10)

Select_statement: Query statement

For UPDATE: Lock the result set of the cursor with all or part of the corresponding data row in the table when using the data for the cursor.
Of: If you do not use the clause, you will lock the cursor result set to all columns of the corresponding data row in the table, or only the specified column if you specify the.
NoWait: If the data row of the table is locked by the user, the other user's for update operation will not execute until the user releases the lock on the data row. If you use the NOWAIT keyword, other users will return an error message immediately if they use open cursors.

examples
Declare
Cursor stu_cursor (num number:=1)
Is
Select Sage,sname from student where rownum=num;

Open Cursor
1 A query statement is specified for the cursor when the cursor is declared, but the statement is not executed immediately, and Oracle does not execute the query statements until the cursor is opened
2 When the cursor is opened, if the cursor has input parameters, the user must be assigned a value, otherwise the error will be

Grammar
Open Cursorname "(value", ... ")";

examples
Open Stu_cursor (2);

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.