Oracle PL/SQL:如何打印表类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1200142/
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:03:42  来源:igfitidea点击:

Oracle PL/SQL: How to print a table type

oracleplsql

提问by David

I am trying to print an table typefor debugging purposes, but don't know how. I tried the following two methods, neither of which work:

我正在尝试打印一个table type用于调试目的,但不知道如何。我尝试了以下两种方法,都不起作用:

dbms_output.put_line (V_TEMP_TABTYPE(1));
dbms_output.put_line (V_TEMP_TABTYPE);

The error generated is: PLS-00306: wrong number or types of arguments in call to.

产生的错误是:PLS-00306: wrong number or types of arguments in call to

So, how can I print the contents of a table type? Or is there a different way to display the contents?

那么,如何打印 a 的内容table type?或者是否有不同的方式来显示内容?

The table_typeand the typeit references are::

table_typetype它引用::

create or replace TYPE MY_TYPE IS OBJECT( MyString Varchar(20)
                                        , counter Number(9) );    
create or replace TYPE MY_TABTYPE AS TABLE OF MY_TYPE;

采纳答案by jva

dbms_output.put_line(v_temp_tabtype(i).myString);

回答by David

Oracle has objects but it's ... different. Not exactly sure with your question if you want to see the values of the properties or if you want to actually see the type.

Oracle 有对象,但它...不同。如果您想查看属性的值或者是否想实际查看类型,则不确定您的问题。


CREATE OR REPLACE TYPE MY_TYPE IS OBJECT ( 
  MyString Varchar(20)
  , counter Number(9) 
);

Now run some code for it.

现在为它运行一些代码。


DECLARE
    myType  MY_TYPE;
BEGIN
  myType := MY_TYPE('ABC123',0);
  -- To see the values reference the properties
  DBMS_OUTPUT.PUT_LINE(myType.mystring);
  -- To see they TYPE of the OBJECT
  DBMS_OUTPUT.PUT_LINE(SYS.ANYDATA.CONVERTOBJECT(myType).getTypeName());
END;

Of course you can create methods on the object to return information for you a bit easier.

当然,您可以在对象上创建方法以更轻松地为您返回信息。


CREATE OR REPLACE TYPE MY_TYPE IS OBJECT ( 
  MyString Varchar(20)
  , counter Number(9)
 , MEMBER FUNCTION getType RETURN VARCHAR2
 , MEMBER FUNCTION toString RETURN VARCHAR2
)
/

CREATE OR REPLACE TYPE BODY MY_TYPE 
AS
  MEMBER FUNCTION getTYPE RETURN VARCHAR2 IS
    BEGIN
      RETURN SYS.ANYDATA.CONVERTOBJECT(SELF).getTypeName();
    END;
  MEMBER FUNCTION toString RETURN VARCHAR2 IS
    BEGIN
      RETURN 'MY_TYPE('||self.mystring||','||self.counter||')';
    END;
END;
/

You can call the functions on the object now makes it easier to read imo.

您现在可以调用对象上的函数,这样可以更轻松地阅读 imo。


DECLARE
  mytype    MY_TYPE;
BEGIN
  mytype := MY_TYPE('AGAIN','0');
  DBMS_OUTPUT.PUT_LINE(mytype.toString);
  DBMS_OUTPUT.PUT_LINE(mytype.getType);
END;