[转]Oracle Stored Procedures Hello World Examples
本文转自:http://www.mkyong.com/oracle/oracle-stored-procedures-hello-world-examples/
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 procPrintHelloWorld
IS
BEGIN DBMS_OUTPUT.PUT_LINE('Hello World!'); END;
/
Run it
EXEC procPrintHelloWorld;
Output
Hello World!
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)
IS
BEGIN 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)
IS
BEGIN outParam1 := 'Hello World OUT parameter'; END;
/
Run it
DECLARE
outParam1 VARCHAR2();
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)
IS
BEGIN genericParam := 'Hello World INOUT parameter ' || genericParam; END;
/
Run it
DECLARE
genericParam VARCHAR2() := '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)
IS
BEGIN 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://www.oradev.com/ref_cursor.jsp
- http://psoug.org/reference/procedures.html
- http://www.devshed.com/c/a/Oracle/Working-with-REF-CURSOR-in-PL-SQL/
- http://www.codeproject.com/KB/database/Oracle_RefCursor_ADO_C__.aspx
[转]Oracle Stored Procedures Hello World Examples的更多相关文章
- Spring, Hibernate and Oracle Stored Procedures
一篇英文博文,写的是利用hibernate处理存储过程中的游标等等: Motivation: While there are a few resources available online for ...
- [转]How to: Execute Oracle Stored Procedures Returning RefCursors
本文转自:http://www.telerik.com/help/openaccess-orm/openaccess-tasks-oracle-execute-sp-result-set.html I ...
- MySQL Error Handling in Stored Procedures 2
Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...
- Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one SQL statement
Is there any way in which I can clean a database in SQl Server 2005 by dropping all the tables and d ...
- Home / Python MySQL Tutorial / Calling MySQL Stored Procedures in Python Calling MySQL Stored Procedures in Python
f you are not familiar with MySQL stored procedures or want to review it as a refresher, you can fol ...
- [MySQL] Stored Procedures 【转载】
Stored routines (procedures and functions) can be particularly useful in certain situations: When mu ...
- Good Practices to Write Stored Procedures in SQL Server
Reference to: http://www.c-sharpcorner.com/UploadFile/skumaar_mca/good-practices-to-write-the-stored ...
- An Introduction to Stored Procedures in MySQL 5
https://code.tutsplus.com/articles/an-introduction-to-stored-procedures-in-mysql-5--net-17843 MySQL ...
- Cursors in MySQL Stored Procedures
https://www.sitepoint.com/cursors-mysql-stored-procedures/ After my previous article on Stored Proce ...
随机推荐
- Android学习笔记:TabHost 和 FragmentTabHost
TabHost 命名空间: android.widget.TabHost 初始化函数(必须在addTab之前调用): setup(); 包含两个子元素: 1.Tab标签容器TabWidget(@and ...
- 简单的activemq的封装和使用
天空中飘着小雨,实在是适合写代码的时节. 1 package ch02.chat; import java.io.Serializable; import javax.jms.Connection; ...
- htmlcss笔记--a
a标签 1.下载:href里面放一个文件或者压缩包时,会下载: 2.锚点:跳转到锚点: href="#id" 跳转到的模块添加一个id,点击id就会跳转到该模块. html标签: ...
- Android字符串相关类 - CharSequence
Class Overview CharSequence定义为public interface.该接口用于表示一个有序字符的集合,并在其中定义里了处理字符的方法. 已知的常用间接子类有String, S ...
- 【转载】/etc/passwd & /etc/shadow 详解
转载自:http://blog.csdn.net/snlying/article/details/6130468 1,passwd文件passwd文件存放在/etc目录下.这个文件存放着所有用户帐号的 ...
- [C语言 - 12] Union联合
union Student { int age; char *name; } stu; union只按照最长的数据成员分配控件,适用于有N个数据不会同时出现的情况,用以压缩空间.
- ALM11用例测试类型
默认一般都是选择的是manual
- (5)RARP:逆地址解析协议
一.简介 无盘系统的RARP实现过程是从接口卡上读取唯一的硬件地址,然后发送一份RARP请求(一帧在网络上广播的数据),请求某个主机响应该无盘系统的IP地址(在RARP应答中).感觉这个过程和上一章中 ...
- 最清晰的ios消息推送机制教程
研究了一下Apple Push Notification Service,实现的很简单,很环保.原理如下 财大气粗的苹果提供了一堆服务器,每个ios设备和这些服务器保持了一个长连接,ios版本更新提示 ...
- 剑指OFFER之二叉树中和为某一值的路径(九度OJ1368)
题目描述: 输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径. 输入: 每个测试案例包括n+1行: 第一行为2 ...