PLSQL / Programming Fundamentals – the cursor
3 loop
% found Boolean property if the sql statement to affect at least the line is true or false,
8 dbms_output.put_line ( pdate record| the sql% rowcount to| #39;);
cursor main attributes are as follows:
consolidated cases:
6 dbms_output.put_line ( he employee department number| merchandise.deptno);
implicit cursor:
the select *
14 fetch merchandise_cursor into merchandise_row;
2 for merchandise in (select empno, ename, deptno from emp)
21 end;
10 merchandise_row merchandise;
…… < br /> 2, open the cursor
13 the loop
end if;
SQL> begin
20 the close merchandise_cursor;
% the isopen Boolean attribute cursor is open to open to true otherwise false,
SQL> begin
04 22 2011 Check out the latest essence of the article please visit the blog home page article
12 dbms_output.put_line ( retrieved sql% rowcount to| ecords ;
variable for the storage and retrieval of data
6 where the empno = 7369;
% notfound Boolean attribute with% found the opposite.
cursor attribute information always reflect the latest SQL statement processing. Therefore, when multiple SQL statements in a block, you need to consider where to check the property value. the
grammar is as follows:
the cursor
4 dbms_output.put ( mployee number| merchandise.empno);
For example:
10 from emp
% rowcount numeric attributes returned by the sql statement impact of the number of rows
7 dbms_output.put_line ( pdate| the sql% rowcount to| ecords ;
cursor (cursor) can be seen as pointing to the result set (a set of rows) in the row pointer (pointer). Oracle database can use two kinds of cursors or implicitly.
the deptno emp.deptno type
results: the number of employees 7369 employees name SMITH staff departments 20
11 begin the
5 dbms_output.put ( mployee Name| merchandise. ename);
return return_type] is the select_statement that;
statement cursor is defined cursor name, cursor features to declare a cursor, open cursor can call the query, the syntax of the statement is as follows:
17 dbms_output.put ( mployee name| merchandise_row.ename);
6 dbms_output.put_line ( oes not update any records ;
10 end The;
the type merchandise is record (
PLSQL / strong> programming basics strong> cursor:
SQL> the declare PL / SQL program contains the select statement to declare the cursor. If you need to deal with a group of records retrieved from the database, you can use the display cursor using cursor processing data requires four steps: declaring a cursor, open cursor, retrieve data, close the cursor, the statement cursor < br /> 16 dbms_output.put ( mployee number| merchandise_row.empno);
SQL> declare
Note: When using the implicit cursor attributes need to be coupled with the SQL property before, because Oracle implicit cursor is created, the default cursor named SQL. through the sql attribute name to see the results
18 dbms_output.put_line ( he employee department number| merchandise_row.deptno);
the cursor emp_cursor (pno in. number (4) default 7 369)
results: Number of employees 7900 employee name JAMES employees department 30 @ April 22, 2011, 22:42:00 Comments (loading.) ReportFavorites old one: PLSQL / Programming Fundamentals – loop strong> strong> new one: Capriccio 2 strong>
the where the empno = eno;
19 end loop;
fetch statement to identify a single row result set, and extract a single value is passed to the main variable.
2 update emp
15 exit when merchandise_cursor% notfound;
an implicit cursor cursor sql statement for the loop can be used to process the result set 5 set sal = 8000
Open cursor_name Is (parameters);
end The; < br /> is select * from emp
2 cursor merchandise_cursor (eno in number default 7396)
Fetch cursor_name into [variable_list [record_variable]]
6 empno emp.empno% type,
4 to close the cursor Close cursor name
2 merchandise_row the emp% rowtype;
begin
14 /
Cursor cursor_name Is [parameter [, parameter] ….
22 /
the into merchandise_row
refers to the query specified in the implementation of the statement of the cursor. open just use open to open the syntax:
retrieve data
the set sal = 8000 < br />
declare
12 the open merchandise_cursor (7900);
9 /
11 /
to retrieve a record
strong>
retrieve data from the retrieved results centralized access to data to a variable, so that the variable processing
If you do not specify a parameter default value of the implementation of the select statement
Parameter as a cursor input parameter, which allows the user to open the cursor type to the cursor pass a value; syntax is as follows:
11 where the empno = 7 369;
7% type ename emp.ename
For example:
staff number 7499 employee name ALLEN staff departments 30
a sql statement oracle server will automatically create an implicit cursor, the cursor is to deal with the statement of work area memory, which stores the result of executing SQL statements. available through the properties of the cursor sql statement is executed results and cursor state information.
is the select the empno, ename, the deptno from 7934 employees of the emp
Employee Number Name MILLER staff department No. 10
end loop;
the where the empno = 7 369;
Results: update a record
Parameter_name [in] datatype [{: =default} expression is] /
5 the if the sql% notfound then
employee number 7521 employee name the WARD employees department number 30
where the empno = pno;
13 end;
9);
4 the update the emp
else
