Oracle - 具有虚拟列的联合表

时间:2015-03-01 19:09:54

标签: sql oracle11g union

我试图从现有视图和表中创建一个新的工会化视图,我想在该表中添加一个虚拟列,根据表/视图,将在标记中标记真/假虚拟列。有点像...

CREATE OR REPLACE VIEW myouterview AS 
SELECT id, field1, field2, ..., 'true' as editable FROM
mytable
union 
SELECT to_number(id), field1, field2, ..., 'false' as Editable FROM
myinnerview

通过上面的查询,行正在复制,其中一个条目为true,另一个条目为false。我很感激任何帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

你可以试试这样的......

CREATE OR REPLACE VIEW myviewouter AS 
SELECT id, field1, field2, ..., 'true' as editable FROM
mytable
union 
SELECT to_number(id), field1, field2, ..., 'false' as Editable FROM
myview B
where not Exists (select 1 from mytable A where A.id=to_number(B.id))