Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL, is it possible to use a user-defined datatype property in a nested select?

I have a PL/SQL function that returns a datatype with a property start_date:

create or replace FUNCTION RETURN_OBJ
RETURN my_obj
IS
  obj my_obj;
BEGIN
   obj := my_obj(SYSDATE);
   RETURN obj;
END;

create or replace TYPE my_obj
AS OBJECT (
start_date DATE
);

I can make use of the property in a simple SELECT statement e.g.

select RETURN_OBJ().start_date FROM DUAL

However when I try to use a virtual table (e.g. to avoid multiple function calls) I get an error:

select obj.start_date from (select RETURN_OBJ() AS obj FROM DUAL)
ORA-00904: "OBJ"."START_DATE": invalid identifier

Am I using the wrong syntax, or is this just not possible? (By the way I'm using Oracle 11 although the customer is still on 9)

Thanks very much.

like image 465
Hadden Uff Avatar asked Feb 22 '26 19:02

Hadden Uff


2 Answers

Brackets :-)

select (obj).start_date from (select RETURN_OBJ() AS obj FROM DUAL)
like image 98
David דודו Markovitz Avatar answered Feb 25 '26 08:02

David דודו Markovitz


You must use a table alias when you like to access functions from OBJECT Types. Try this one:

SELECT t.obj.start_date 
FROM (SELECT RETURN_OBJ() AS obj FROM DUAL) t;
like image 35
Wernfried Domscheit Avatar answered Feb 25 '26 09:02

Wernfried Domscheit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!