我是 PL/SQL 的新手,在 Oracle 中使用自定义表类型创建视图时遇到问题。这些是创建的类型:
create or replace
TYPE "Control" AS OBJECT ("Date" nvarchar2(10), "R" number(7,3), "Limit(7,3);
create or replace TYPE Controls AS TABLE OF "Control";
CREATE OR REPLACE TYPE Result_typ AUTHID CURRENT_USER AS OBJECT (
"Program" varchar(10),
"ID_User" nvarchar2(25),
"Controls" Controls,
)
在 DB 中,我们有两种不同类型的控件(c_control、g_control)存储在不同的表中,公共字段很少。我正在尝试创建一个视图,选择所有不同的控件,尽管它们的类型不同,所以我使用 UNION 子句。这是我的视图创建语句(进行了一些细微的更改以使其更简单):
CREATE OR REPLACE VIEW "all_controls" OF Result_typ
with object IDENTIFIER ("ID_User")
as SELECT 'MYAPP' as Program,
u.user_id as "ID_User",
CAST(MULTISET(
select to_char(control_date,'yyyy-mm-dd') as "Date",
r as "R",
limit as "Limit"
from g_control
where control_date between to_date('20130310','yyyymmdd')
and to_date('20130313','yyyymmdd')
UNION
select to_char(control_date,'yyyy-mm-dd') as "Date",
r as "R",
limit as "Limit",
from control
where and control_date between to_date('20130310','yyyymmdd')
and to_date('20130313','yyyymmdd')
) AS Controls)
FROM user u
WHERE u.user_name like 'Scott';
从 SQL Developer 执行语句时,返回值为“SQL 错误:没有更多数据可从套接字读取”。在 MULTISET 中执行 UNION 是否有任何问题?如何选择 UNION 结果作为 MULTISET?提前致谢