如何根据对象的查询返回对象

发布于 2025-02-12 07:43:21 字数 894 浏览 0 评论 0 原文

I have a table a based on the object a_obj:

CREATE TYPE a_obj IS OBJECT (
  a1 INTEGER,
  a2 integer
);

CREATE TABLE a OF a_obj (
  CONSTRAINT a__a1__pk PRIMARY KEY (a1)
);

Sometime i want to select the column of a:

select a.* from a  -- it works

sometime I want to select the object a_obj.

 select a_obj(a.a1,a.a2) from a; --works

但是我不想重写所有列的名称,因为,我可以写很多列要写,而且很容易忘记一个列。

我尝试这样的事情:

select a_obj(a.*) from a;

ORA-01747:无效的用户。

it doesn't work.

有办法做到吗?

that doesn't work either:

declare 
  ret a_obj;
begin
  select a.* into ret
  from a;
end;

code

I have a table a based on the object a_obj:

CREATE TYPE a_obj IS OBJECT (
  a1 INTEGER,
  a2 integer
);

CREATE TABLE a OF a_obj (
  CONSTRAINT a__a1__pk PRIMARY KEY (a1)
);

Sometime i want to select the column of a:

select a.* from a  -- it works

sometime I want to select the object a_obj.

 select a_obj(a.a1,a.a2) from a; --works

But I don't want to rewrite the name of all columns because, I can have a lot of columns to write and it's easy to forget one.

I try something like that:

select a_obj(a.*) from a;

ORA-01747: invalid user.table.column, table.column, or column specification

it doesn't work.

Is there a way to do that?

that doesn't work either:

declare 
  ret a_obj;
begin
  select a.* into ret
  from a;
end;

code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

|煩躁 2025-02-19 07:43:21

使用

SELECT OBJECT_VALUE FROM a;

或,AS @padders评论 ,使用

SELECT VALUE(a_alias) FROM a a_alias;

需要参考表别名而不是表标识符。

db<>>

Use the OBJECT_VALUE pseudo-column:

SELECT OBJECT_VALUE FROM a;

Or, as @padders commented, use the VALUE() function:

SELECT VALUE(a_alias) FROM a a_alias;

Which needs to reference a table alias and not the table identifier.

db<>fiddle here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文