如何将数组从 Java 返回到 PL/SQL?
我可以毫无问题地从 PL/SQL 到 Java 来回传递数字和字符串,但如何传递数组?我从 PL/SQL 调用 Java,而不是其他方式。
下面是 get_widgets_as_string
按预期工作的示例。如何为 so19j.get_widgets_as_array()
编写 PL/SQL 调用规范,以便我可以从 PL/SQL 调用它?
我已阅读发布带有调用规范的Java类我可以看到嵌套表对应于oracle.sql.ARRAY,但我无法让它工作。我可能错过了一些琐碎的细节,因为我不是 Java 程序员。
create or replace and compile java source named "so19j" as
import java.lang.*;
public class so19j {
public static String get_widgets_as_string() {
String widgets = "foo;bar;zoo";
return widgets;
}
public static String[] get_widgets_as_array() {
String[] widgets = new String[]{"foo", "bar", "zoo"};
return widgets;
}
};
/
show errors java source "so19j"
create or replace function get_widgets_as_string return varchar2 as
language java name 'so19j.get_widgets_as_string() return java.lang.String';
/
show errors
declare
widgets constant varchar2(32767) := get_widgets_as_string;
begin
dbms_output.put_line('widgets = ' || widgets);
end;
/
/* How to write a call specification for so19j.get_widgets_as_array so that it
can be excercised by the PL/SQL block below ? */
declare
type widgets_t is table of varchar2(32767);
widgets constant widgets_t := get_widgets_as_array;
begin
for i in widgets.first .. widgets.last loop
dbms_output.put_line('widgets(' || i || ') = ' || widgets(i));
end loop;
end;
/
I have no problems to pass numbers and strings back and forth from PL/SQL to Java, but how do I pass arrays ? I'm calling Java from PL/SQL - not other way round.
Below is an example where get_widgets_as_string
works as expected. How do I write a PL/SQL call specification for so19j.get_widgets_as_array()
so that I can call it from PL/SQL ?
I have read Publishing Java Classes With Call Specifications where I can see that nested table corresponds to oracle.sql.ARRAY
, but I can't get it working. I'm probably missing some trivial details because I'm not a Java programmer.
create or replace and compile java source named "so19j" as
import java.lang.*;
public class so19j {
public static String get_widgets_as_string() {
String widgets = "foo;bar;zoo";
return widgets;
}
public static String[] get_widgets_as_array() {
String[] widgets = new String[]{"foo", "bar", "zoo"};
return widgets;
}
};
/
show errors java source "so19j"
create or replace function get_widgets_as_string return varchar2 as
language java name 'so19j.get_widgets_as_string() return java.lang.String';
/
show errors
declare
widgets constant varchar2(32767) := get_widgets_as_string;
begin
dbms_output.put_line('widgets = ' || widgets);
end;
/
/* How to write a call specification for so19j.get_widgets_as_array so that it
can be excercised by the PL/SQL block below ? */
declare
type widgets_t is table of varchar2(32767);
widgets constant widgets_t := get_widgets_as_array;
begin
for i in widgets.first .. widgets.last loop
dbms_output.put_line('widgets(' || i || ') = ' || widgets(i));
end loop;
end;
/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
打印:
另请参阅:如何创建 oracle.sql.ARRAY 对象?
Prints:
See also: How to create an oracle.sql.ARRAY object?
我不知道 pl/sql 的事情,但你可以做的是处理 PL/SQL 的结果并将结果插入到 set 方法中,然后你就可以得到它。
I dont know about the pl/sql thing but what u can do is process the result from PL/SQL and insert the result into a set method and then later u can get it.