Chinaunix首页 | 论坛 | 博客
  • 博客访问: 409992
  • 博文数量: 66
  • 博客积分: 1416
  • 博客等级: 上尉
  • 技术积分: 922
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-16 10:37
个人简介

高級Oracle DBA,善長Linux系統維運以及Oracle數據庫管理,開發,調優. 具有多年PL/SQL開發經驗.

文章分类

全部博文(66)

文章存档

2015年(9)

2014年(4)

2013年(5)

2010年(1)

2009年(3)

2008年(6)

2007年(30)

2006年(8)

我的朋友

分类: Oracle

2007-12-03 10:49:56


今天同事有個Java procedure,需要傳出參數. 無法解決.
在oracle網站找到了方法




Setting Parameter Modes

In Java and other object-oriented languages, a method cannot assign values to objects passed as arguments. When calling a method from SQL or PL/SQL, to change the value of an argument, you must declare it as an OUT or IN OUT parameter in the call specification. The corresponding Java parameter must be an array with only one element.

You can replace the element value with another Java object of the appropriate type, or you can modify the value if the Java type permits. Either way, the new value propagates back to the caller. For example, you map a call specification OUT parameter of the NUMBER type to a Java parameter declared as float[] p, and then assign a new value to p[0].

Note:

A function that declares OUT or IN OUT parameters cannot be called from SQL data manipulation language (DML) statements.

做了個小範例測試
傳入varchar2, 用out參數返回字串長度

create or replace java source named "Hello" as
        public class Hello {
                static public void Message(String name, int ret[]) {
                        ret[0] = name.length() ;
        }
}
/

create or replace procedure hello (name VARCHAR2, aa out number ) as language java name 'Hello.Message (java.lang.String, int[]) ';
/

var r number ;
call hello('world', :r) ;

print :r ;


                                阿飛
                     2007/12/03
阅读(2572) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~