博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[转]Oracle Stored Procedures Hello World Examples
阅读量:5896 次
发布时间:2019-06-19

本文共 2343 字,大约阅读时间需要 7 分钟。

本文转自:

List of quick examples to create stored procedures (IN, OUT, IN OUT and Cursor parameter) in Oracle database. PL/SQL code is self-explanatory.

1. Hello World

A stored procedure to print out a “Hello World” via DBMS_OUTPUT.

CREATE OR REPLACE PROCEDURE procPrintHelloWorldISBEGIN   DBMS_OUTPUT.PUT_LINE('Hello World!'); END;/

Run it

EXEC procPrintHelloWorld;

Output

Hello World!
2. Hello World + IN Parameter

A stored procedure to accept a single parameter and print out the “Hello World IN parameter” + parameter value via DBMS_OUTPUT.

CREATE OR REPLACE PROCEDURE procOneINParameter(param1 IN VARCHAR2)ISBEGIN   DBMS_OUTPUT.PUT_LINE('Hello World IN parameter ' || param1); END;/

Run it

EXEC procOneINParameter('mkyong');

Output

Hello World IN parameter mkyong

3. Hello World + OUT Parameter

A stored procedure to output/assign the “Hello World OUT parameter” value to OUT parameter.

CREATE OR REPLACE PROCEDURE procOneOUTParameter(outParam1 OUT VARCHAR2)ISBEGIN   outParam1 := 'Hello World OUT parameter'; END;/

Run it

DECLARE  outParam1 VARCHAR2(100);BEGIN  procOneOUTParameter(outParam1);  DBMS_OUTPUT.PUT_LINE(outParam1);END;/

Output

Hello World OUT parameter

4. Hello World + INOUT Parameter

A stored procedure to accept a INOUT parameter (genericParam), construct the output message and assign back to the same parameter name(genericParam) again.

CREATE OR REPLACE PROCEDURE procOneINOUTParameter(genericParam IN OUT VARCHAR2)ISBEGIN   genericParam := 'Hello World INOUT parameter ' || genericParam; END;/

Run it

DECLARE  genericParam VARCHAR2(100) := 'mkyong';BEGIN  procOneINOUTParameter(genericParam);  DBMS_OUTPUT.PUT_LINE(genericParam);END;/

Output

Hello World INOUT parameter mkyong

5. Hello World + Cursor

A stored procedure, return a ref cursor and accept a IN parameter.

CREATE OR REPLACE PROCEDURE procCursorExample(cursorParam OUT SYS_REFCURSOR, userNameParam IN VARCHAR2)ISBEGIN   OPEN cursorParam FOR  SELECT * FROM DBUSER WHERE USERNAME = userNameParam; END;/

Run it

DECLARE   dbUserCursor SYS_REFCURSOR;  dbUserTable DBUSER%ROWTYPE;BEGIN   procCursorExample(dbUserCursor,'mkyong');   LOOP 	FETCH dbUserCursor INTO dbUserTable;     EXIT WHEN dbUserCursor%NOTFOUND;    dbms_output.put_line(dbUserTable.user_id);   END LOOP;   CLOSE dbUserCursor; END;/

Output

List OF the user_id which matched username='mkyong'

Reference

 

转载地址:http://bqxsx.baihongyu.com/

你可能感兴趣的文章
游戏音效下载网站大全
查看>>
实验五
查看>>
3-继承
查看>>
海归千千万 为何再无钱学森
查看>>
vue2.0 仿手机新闻站(六)详情页制作
查看>>
FreeRTOS的内存管理
查看>>
JSP----九大内置对象
查看>>
Java中HashMap详解
查看>>
delphi基本语法
查看>>
沙盒目录介绍
查看>>
260. Single Number III
查看>>
Hadoop生态圈-Kafka的完全分布式部署
查看>>
css的border的solid
查看>>
[MODx] Build a CMP (Custom manager page) using MIGX in MODX 2.3 -- 1
查看>>
jQuery自动完成点击html元素
查看>>
[算法]基于分区最近点算法的二维平面
查看>>
webpack多页应用架构系列(七):开发环境、生产环境傻傻分不清楚?
查看>>
笨办法学C 练习1:启用编译器
查看>>
树的总结--树的性质(树的深度) leetcode
查看>>
nagios短信报警(飞信fetion20080522004-linrh4)
查看>>