我在WHERE语句中插入子查询时遇到了一些麻烦。我到目前为止的代码是:
select * from (
SELECT 'P_' dmnsn AS partition_name,
decode(dmnsn,'PROMO','CMBD_PROMO',dmnsn_code) AS high_value,
dmnsn AS part_pre
FROM
(select to_char(to_clob(COLUMN_VALUE)) as dmnsn
from XMLTABLE(to_clob('"CLSTR","CUSTOMER","CALENDAR","TYPE",
"PROMO","PRODUCT","PRODUCTION","STORE","WAREHOUSE","SALES","PRICE"')))
)
where ( select count(*) 'TEST_' || substr( partition_name,3) || '_VIEW' ) > 0
显然它不起作用。 (我只是把它放在这里给你一个我想要做的事情的一瞥) XMLTABLE的所有视图实际上都存在,看起来像这样" TEST_CLSTR_VIEW"。 我的目标是从XMLTABLE中选择那些创建非空的视图的值(包含一些记录)
答案 0 :(得分:0)
您的查询中有几个问题
1 - 在SQL中使用var的数据库对象作为表或列名称是不允许的。所以你应该使用另一个tecnique构建你的查询,例如:构建dinamically服务器端,查询的字符串避免var
2 - 你错过了sub sublect中的FROM子句。
3 - 'P_'dmnsn AS partition_name,是错误的
select * from (
SELECT 'P_' dmnsn AS partition_name,
decode(dmnsn,'PROMO','CMBD_PROMO',dmnsn_code) AS high_value,
dmnsn AS part_pre
FROM
(select to_char(to_clob(COLUMN_VALUE)) as dmnsn
from XMLTABLE(to_clob('"CLSTR","CUSTOMER","CALENDAR","TYPE",
"PROMO","PRODUCT","PRODUCTION","STORE","WAREHOUSE","SALES","PRICE"')))
)
where ( select count(*) FROM YOUR_VIEW ) > 0