posts - 431,  comments - 344,  trackbacks - 0

首先在PL/Sql中分别执行:

create or replace and compile java source named TestJava1 as 
public class TestJava1 

  public static void test() 
  { 
   System.out.println("Hello"); 
  } 
}


create or replace procedure testJava1 as language java name 'TestJava1.test()';

---------------------------------------------------------------------------------------------------------

在SQLPlus中

C:\Windows\System32>sqlplus nc5520110105/nc5520110105@192.168.10.87

SQL*Plus: Release 11.2.0.1.0 Production on Fri Apr 1 14:06:02 2011

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> set serveroutput on;
SQL> show serveroutput;
serveroutput ON SIZE UNLIMITED FORMAT WORD_WRAPPED
SQL> call dbms_java.set_output(2000);

Call completed.

SQL>
SQL> show serveroutput;
serveroutput ON SIZE UNLIMITED FORMAT WORD_WRAPPED
SQL> exec testJava1();
Hello

PL/SQL procedure successfully completed.

SQL>

---------------------------------------------------------------------------------------------------------

再看一个例子:

在PL/Sql中执行:

--用Java编写Oracle存储过程。
create or replace and compile java source named test as
public class MyTest
{
    public static void myProc(int a,int b,int[] ret){
       ret[0]=a+b;
    }
    public static int myFunc(int a,int b){
       return a+b;
    }
}

--创建存储过程
create or replace procedure myProc(a in number, b in number, ret out number) as
language java name 'MyTest.myProc(int,int,int[])';
--创建函数
create or replace function myFunc(a in number, b in number) return number is
language java name 'MyTest.myFunc(int,int) return int';

然后在SqlPlus中测试存储过程——

SQL> set serveroutput on
SQL> DECLARE a INTEGER;
  2  BEGIN
  3  myProc(1, 2, a);
  4  DBMS_OUTPUT.PUT_LINE(a);
  5  END;
  6  /
3

PL/SQL procedure successfully completed.

 

SQL> select myFunc(1,2) from dual;

MYFUNC(1,2)
-----------
          3

SQL>

posted on 2011-06-22 12:38 周锐 阅读(918) 评论(0)  编辑  收藏 所属分类: JavaOracle

只有注册用户登录后才能发表评论。


网站导航: