请检查Oracle的Java代码。我喜欢将println()输出到DBMS_OUTPUT.PUT_LINE()等oracle控制台。
我还创建了一个函数/过程(在java中没有返回)来调用java函数。它执行正常并返回值(对于函数),但不要在Oracle控制台(ServerOutput)中打印任何内容。
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "Azam/Azam_Test" as package Azam;
import java.lang.*;
public class Azam_Test {
public static String Azam_Test_Print(String testString) {
System.out.println(testString); // want this output into ORACLE console
return testString;
}
}
答案 0 :(得分:1)
文档DBMS_JAVA
和程序
DBMS_JAVA.SET_OUTPUT(2000000)
同时检查DBMS_JAVA.SET_OUTPUT_TO_SQL
,它更有用
答案 1 :(得分:1)
这是一个有效的完整脚本。
SQL> SET SERVEROUTPUT ON
SQL> CALL dbms_java.set_output(2000);
Call completed.
SQL>
SQL> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "MyOutput" as
2
3 import java.lang.*;
4 public class MyOutput {
5
6 public static String print(String testString) {
7 System.out.println(testString); // want this output into ORACLE console
8 return testString;
9 }
10 }
11 /
Java Source MyOutput created
SQL>
SQL> create or replace procedure Test_Output(testString in varchar2)
2 as LANGUAGE JAVA
3 NAME 'MyOutput.print(java.lang.String)';
4 /
Procedure TEST_OUTPUT compiled
SQL>
SQL> exec Test_Output('Hello');
Hello
PL/SQL procedure successfully completed.
SQL>