如何从 TOAD for Oracle 执行函数并将结果绑定到数据网格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2829391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 02:34:17  来源:igfitidea点击:

how do I execute a function from TOAD for Oracle and bind the result to a data grid

oracleplsqltoad

提问by neesh

I have a function that takes as one of it's arguments a VARRAY of pl/sql Objects. How do I execute this stored procedure and bind the resultset that it returns to a data grid in TOAD for Oracle?

我有一个函数,它的参数之一是 pl/sql 对象的 VARRAY。如何执行此存储过程并将其返回的结果集绑定到 TOAD for Oracle 中的数据网格?

回答by neesh

After some searching around, I found the answer to my own problem. Say your varray type was called varchar_pair_array and the objects stored in this array were called varchar_pair_object. varchar_pair_object is a simple object that has two varchars as it's members.

经过一番搜索,我找到了自己问题的答案。假设你的 varray 类型被称为 varchar_pair_array 并且存储在这个数组中的对象被称为 varchar_pair_object。varchar_pair_object 是一个简单的对象,它有两个 varchar 作为它的成员。

Here is the code for executing a proc that takes in a varray of varchar_pair_object (s):

这是用于执行接收 varchar_pair_object (s) 数组的 proc 的代码:

DECLARE 
  RetVal SYS_REFCURSOR;
  a_simplevalue VARCHAR2(200);
  another_simplevalue VARCHAR2(200);
  my_array_of_varchar_pairs VARCHAR_PAIR_ARRAY; -- assume varchar_pair_array is defined somewhere else
  my_obj VARCHAR_PAIR_OBJECT; -- assume varchar_pair_object is defined somewhere else
  my_other_obj VARCHAR_PAIR_OBJECT;
BEGIN 
  a_simplevalue := 'hello';
  another_simplevalue := 'there';
  my_obj := VARCHAR_PAIR_OBJECT('nice to meet you', 'greetings');
  my_other_obj := VARCHAR_PAIR_OBJECT('goodbye', 'ciao');
  my_array_of_varchar_pairs := VARCHAR_PAIR_ARRAY(); 
  my_array_of_varchar_pairs.EXTEND(2); -- this should be the number of objects you plan to put into the array
  my_array_of_varchar_pairs(1) := my_obj;
  my_array_of_varchar_pairs(2) := my_other_obj; 

  RetVal := my_function ( a_simplevalue, another_simplevalue, my_array_of_varchar_pairs); -- assuming your array takes two varchars and one array of VARCHAR_PAIR_OBJECT (s)
  :to_grid := RetVal;

END;

Copy paste this code in TOAD's sql editor and change it to adapt to your function and types and hit F9. TOAD will ask you the type of the :to_grid variable. Select cursor (assuming your function returns a ref cursor) and hit enter. TOAD will bind the result set to a data grid.

将此代码复制粘贴到 TOAD 的 sql 编辑器中并更改它以适应您的功能和类型,然后按 F9。TOAD 会询问您 :to_grid 变量的类型。选择光标(假设您的函数返回一个引用光标)并按回车键。TOAD 将结果集绑定到数据网格。

Links that helped me:

对我有帮助的链接:

http://www.smart-soft.co.uk/Oracle/oracle-plsql-tutorial-part-11.htm(good tutorial on collections) http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/10_objs.htm#1972(especially useful in this case is the section on declaring and initializing objects)

http://www.smart-soft.co.uk/Oracle/oracle-plsql-tutorial-part-11.htm(关于集合的好教程) http://download.oracle.com/docs/cd/B10501_01/appdev .920/a96624/10_objs.htm#1972(在这种情况下特别有用的是关于声明和初始化对象的部分)

With very little change the same can be done with a procedure.

只需很少的更改,就可以通过程序完成相同的操作。