当前位置:网站首页>Oracle database pl/sql procedure body, cursor, stored procedure
Oracle database pl/sql procedure body, cursor, stored procedure
2022-06-22 08:06:00 【EA development - green shirt code customer】
PL/SQL The process of body
DECLARE
-- Declaration part
BEGIN
-- Executive part
END;
DECLARE
sname varchar(20):='Jack';
BEGIN
sname :='HI!'||sname;
DBMS_OUTPUT.PUT_LINE(sname);
END;
-- Results output : HI!Jack
The cursor
A cursor is a pointer to a query result set , The records in the query result set can be fetched one by one through the cursor .
Cursor declaration
CURSOR You name
IS SELECT Result set query statement ;
Execute cursor
OPEN You name
FETCH You name INTO Variable 1[, Variable 2..]
perhaps
FETCH You name INTO Cursor variable ;
CLOSE;
Cursor properties :%FOUND and %NOTFOUND
%FOUND: Used to determine whether the cursor extracts data from the result set . If data is extracted , The return value is TRUE, Otherwise, the return value is FALSE.
%NOTFOUND: And %FOUND contrary , If data is extracted, the return value is FALSE, Otherwise TRUE.
DECLARE
CURSOR mycursor
IS SELECT sname FROM student_0;
row_cursor mycursor%ROWTYPE;
BEGIN
OPEN mycursor;
LOOP
FETCH mycursor INTO row_cursor;
EXIT WHEN mycursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(row_cursor.sname);
END LOOP;
CLOSE mycursor;
END;
DECLARE
CURSOR mycursor
IS SELECT sname FROM student_0;
BEGIN
FOR row_cursor IN mycursor LOOP
DBMS_OUTPUT.PUT_LINE(row_cursor.sname);
END LOOP;
END;
Create stored procedure
CREATE [OR REPLACE] PROCEDURE The process of ( Parameters 1 [IN | OUT | IN OUT] data type , Parameters 2[IN | OUT | IN OUT] data type ...)
IS | AS
PL/SQL Process style sentences ;
Calling stored procedure
BEGIN
The process of [ Parameters ];
END;
Delete stored procedure
DROP PROCEDURE The process of ;
CREATE OR REPLACE PROCEDURE SP_MYEMP(P_DEPTNO IN NUMBER,
P_HIREDATE OUT DATE,
P_JOB_ENAME IN OUT VARCHAR2)
AS
V_SAL NUMBER;
BEGIN
SELECT E.ENAME,E.SAL,E.HIRDATE
INTO P_JOB_ENAME,V_SAL,P_HIRDATE
FROM EMP E
WHERE E.DEPTNO=P_DEPTNO
AND E.JOB=P_JOB_ENAME;
DBMS_OUTPUT.PUT_LINE(P_JOB_NAME||' '||V_SAL||' '||P_HIREDATE);
END;
-- Calling stored procedure
DECLARE
V_JOB_ENAME varchar2(20) :='MANAGER';
V_HIREDATE DATE;
BEGIN
SP_MYEMP(20,V_HIREDATE,V_JOB_ENAME);
END;
A package is a collection of related stored procedures 、 function 、 Variable 、 Constants and cursors, etc PL/SQL Put together , And a program block endowed with certain management functions .
Create enclaves
CREATE [OR REPLACE] PACKAGE BODY mypackage
AS | IS
PROCEDURE The process of ( Parameters )
IS | AS
BEGIN
The process of body ;
END [ The process of ];
END;
边栏推荐
- [Oracle database] mammy tutorial day13 date function
- setneedsdisplay layoutifneeded setNeedsLayout
- Windchill - how to start workflow through API
- It operation and maintenance knowledge map
- Docker install redis
- JSON使用示例
- PostgreSQL common commands and SQL -- continuous update
- Windchill API drops
- Model electricity experiment -- Experiment 2 JFET common source amplifier circuit
- LR 2022 ultra detailed installation tutorial "latest"
猜你喜欢

Model electricity experiment -- Experiment 2 JFET common source amplifier circuit

Mystery of power bank

LR 2022 ultra detailed installation tutorial "latest"

LNMP environment setup

Characteristics of industrial Internet

Energy and interference of waves
![[Oracle database] mammy tutorial day14 conversion function](/img/ef/c468316750c57212a067abd00a10e9.png)
[Oracle database] mammy tutorial day14 conversion function

Mt4/mql4 getting started to mastering EA tutorial lesson 4 - common functions of MQL language (IV) - common functions of K-line value

Failed to access the ES installed on Tencent ECs, but the solution to accessing the ES successfully on the server

(7) Bidirectional linked list
随机推荐
Characteristics of industrial Internet
【Oracle 数据库】奶妈式教程 day11 数值函数
Windchill - how to start workflow through API
mysql截取字符串CS0000_1中_后面的字符
OSI and tcp/ip
(7)双向链表
Expérience électrique en mode - - expérience 2 circuit d'amplification de source commune JFET
Technology blog collection
Download addresses of Xcode versions
Mt4/mql4 getting started to proficient in foreign exchange EA automatic trading tutorial - identify the emergence of the new K line
Mt4/mql4 getting started to mastering EA tutorial lesson 4 - common functions of MQL language (IV) - common functions of K-line value
Microsoft Remote Desktop 10.7.6 official
JSON usage example
MySQL backup - mysqldump
计算水费问题
C#实现语音朗读功能
User defined pop-up use
RAID technology
Modular import and export collation in JS
【Oracle 数据库】奶妈式教程 day14 转换函数