在Oracle中,如何验证对象类型层次结构中使用的对象类型? [英] In Oracle, how do I verify the object type used from an object type hierarchy?

查看:96
本文介绍了在Oracle中,如何验证对象类型层次结构中使用的对象类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Oracle模式中具有类型层次结构:

I have a Type hierarchy in an Oracle Schema:

CREATE OR REPLACE TYPE FV AS OBJECT (
   idno           NUMBER)
NOT FINAL;
/

CREATE TYPE FV_Integer UNDER FV (
   features INTEGER_ARRAY)
   NOT FINAL;
/


CREATE TYPE FV_Number UNDER FV (
   features NUMBER_ARRAY)
   NOT FINAL;
/

我想构建一个PLSQL函数,该函数非常适合对象的层次结构类型:对于函数dummy(obj1 FV,obj2 FV)...如何检查用户是层次结构的对象类型是什么使用吗?

I want to build a PLSQL function that veryfies which type of the hierarchy is an object: for a function dummy(obj1 FV, obj2 FV)... how can I check what is the object type of the hierarchy the user is using?

例如,我要打印对象的类型名称(该函数用于ilustration,它不是真正的pl/sql代码):

For example, I want to print the objects type names (the function is for ilustration, it is not a real pl/sql code):

 dummy(obj1 FV, obj2 FV){
      if obj1%type = FV_INTEGER
          THEN print 'FV_INTEGER'
      endif
      if obj2%type = FV_NUMBER
          THEN print 'FV_NUMBER'
      endif
}

推荐答案

您可以使用sys.anydata检查对象的类型:

You can inspect the type of an object using sys.anydata:

create or replace function which_type
    ( p_fv fv )
    return varchar2
as
begin
    return sys.anydata.gettypename(sys.anydata.convertobject(p_fv));
end which_type;

测试:

create or replace type number_array as table of number;
create or replace type integer_array as table of integer;

create or replace type fv as object (
   idno           number)
not final;
/

create type fv_integer under fv (
   features integer_array)
   not final;
/

create type fv_number under fv (
   features number_array)
   not final;
/

create table fv_test (my_fv fv);

insert into fv_test values (fv(1));
insert into fv_test values (fv_integer(1, integer_array(1)));
insert into fv_test values (fv_number(1, number_array(1)));

select which_type(my_fv) from fv_test;

WHICH_TYPE(MY_FV)
-------------------------
WILLIAM.FV
WILLIAM.FV_INTEGER
WILLIAM.FV_NUMBER

3 rows selected.

这篇关于在Oracle中,如何验证对象类型层次结构中使用的对象类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆