I have two databases with the same table, all my data split between these bases and I have a view with union clause
CREATE OR REPLACE VIEW MY_UNION_VIEW AS
SELECT col1, col2 from tableX@db_link1
UNION
SELECT col1, col2 from tableX@db_link2
and its working well, until we get select with rowid
select col1 from MY_UNION_VIEW – OK
select * from MY_UNION_VIEW – OK
select rowid, col1 from MY_UNION_VIEW – ERROR (ORA-01446: cannot select ROWID from view with DISTINCT, GROUP BY, etc.)
the problem is – I cannot change the rowid select , its an external APP, I can only change the view definition and can create new objects in my DB
Any ideas how can I avoid it ? I know rowid its an address representation of row in db, and “rowid of view” makes no sense, but I have to return rowid from on of these physic tables (tableX@db_link1 or tableX@db_link2 by selecting it with PK: select rowid where <PK conditions> )
I tried to add rowid as column and use UNION ALL instead of UNION:
CREATE OR REPLACE VIEW MY_UNION_VIEW AS
SELECT rowidtochar(rowid) AS "rowid", col1, col2 from tableX@db_link1
UNION ALL
SELECT rowidtochar(rowid) AS "rowid", col1, col2 from tableX@db_link2
I`m using rowidtochar cast here, because if i tried this:
CREATE OR REPLACE VIEW MY_UNION_VIEW AS
SELECT ROWID AS row_id, col1, col2 from tableX@db_link1
UNION ALL
SELECT ROWID AS row_id, col1, col2 from tableX@db_link2
I got another error – ORA-01790: expression must have same datatype as corresponding expression error
fireflysk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.