[转]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 ...
随机推荐
- 七牛上传Qt版本
最近在找图床,写博客啥的需要.以前的图床好像挂了,搭在BAE上的图床也挂了,可能BAE3.0更新了吧. 花了点时间写了Qt版本 github地址:https://github.com/wzyuliya ...
- 《Nagios系统监控实践》一书出版
本书是我的第一本译著,有此机会实属机缘巧合.虽然使用Nagios只有一年多的时间,但是作为用户,我深感其设计的简洁与高效—没有一丝多余的东西.因为工作的关系,要求对各个领域都有所了解,所以没有仔细地阅 ...
- centos ssh 免密码登录
最近在学习的过程中遇到这个问题: A主机和B主机: A 免密码登录B: 首先在A的 ~/.ssh 目录中 执行 ssh-keygen -t rsa 一路回车 最后生成连个文件: 将id_rsa.pub ...
- 【转】为什么C++编译器不能支持对模板的分离式编译
出处:刘未鹏(pongba) http://blog.csdn.net/pongba) 首先,一个编译单元(translation unit)是指一个.cpp文件以及它所#include的所有.h ...
- 设备扩展(DEVICE_EXTENSION)
原文链接:http://blog.csdn.net/hazy/article/details/481705 WDM中的结构 ---设备扩展 设备扩展(DEVICE_EXTENSION)是与设备对象 ...
- 基于Hadoop 2.2.0的高可用性集群搭建步骤(64位)
内容概要: CentSO_64bit集群搭建, hadoop2.2(64位)编译,安装,配置以及测试步骤 新版亮点: 基于yarn计算框架和高可用性DFS的第一个稳定版本. 注1:官网只提供32位re ...
- Android 4.1.1源码编译
适用环境: 系统:ubuntu-12.04.2-desktop-amd64 JDK:sun-java6-jdk Android源码:android_4.1.1_r1 虚拟机安装: VMware Wor ...
- hdoj 2045 不容易系列之(3)—— LELE的RPG难题
不容易系列之(3)—— LELE的RPG难题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- ALM11测试计划页面图解1
在 ALM 侧栏上的测试下方,选择测试计划. 在查看菜单中,选择测试网格或测试计划树. 在 ALM 侧栏上的测试下方,选择测试计划. 右键单击测试,并选择测试详细信息. 在测试计划树中选择主题文件夹, ...
- Oracle管道函数示例
Oracle的管道函数需要定义下面的三样: Record/Object Type:定义一个Record或Object类型的变量,这个变量用于表示返回结果集的一行数据,有点像C#中的DataRow类. ...