I'm new at PL/SQL and I'm having problems creating a view using custom table types in Oracle. These are the types created:
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,
)
In DB we have two different types of controls (c_control, g_control) stored in different tables with few common fields. I'm trying to create a view selecting all the different controls despite of their type so I use UNION clause. Here there is my view creation statement (with some subtle changes to make it simplier):
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';
When executing the statement from SQL Developer, the returned value is "SQL error: No more data to read from socket". Is there any problem performing a UNION inside the MULTISET? How can I select UNION result as MULTISET? Thanks in advance