Oracle Database Cursor and stored procedure PL/SQL

Source: Internet
Author: User

Oracle Database cursor and stored procedure

Spool abc. log -- start logging

Create or replace procedure db. PROC_FIRST (flag out interger,
T_DATE IN VARCHAR2)

AS

Varno varchar2 (20 );
Varprice varchar2 (20 );

CURSOR mycur (vartype number) is
Select emp_no, emp_zc from cus_emp_basic
Where com_no = vartype;

BEGIN
If NOT mycur % ISOPEN then
Open mycur (1, 043925 );
End if;
FETCH mycur INTO varno, varprice;
WHILE mycur % FOUND
LOOP

Dbms_output.put_line (varno | ',' | varprice );
If mycur % rowcount = 2 then
EXIT;
End if;
Fetch mycur into varno, varprice;
End loop;
CLOSE mycur;

 

EXCEPTION WHEN OTHERS THEN
ROLLBACK;

End;

Spool off

The record is not stored in the database. It is stored in the memory space like a variable. When using the record, you must first define the record structure and then declare the record variable. PL/SQL records can be viewed as user-defined data types.

Execute immediate sqlstr;

It parses and immediately executes dynamic SQL statements or PL/SQL blocks created when they are not running. The performance of dynamic creation and execution of SQL statements is advanced.


System variables and CURSOR of PL/SQL:

Cursor property:
% ISOPEN
% FOUND
% NOTFOUND
% ROWCOUNT

Exception:

SQLCODE () error code
SQLERRM () error message
NO_DATA_FOUND

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.