Table Meta: ------------------------------------- type tab_name new tab_news sports tab_sps Table tab_news ------ id Table tab_sps ------------------- id xx
现在我要使用
SELECT id FROM (SELECT tab_name FROM Meta WHERE type = 'news');
但这行不通,有什么想法吗?
SQL不支持表名使用变量/ etc-支持您要求的唯一方法是使用动态SQL:
FOR i IN (SELECT tab_name FROM META m WHERE m.type = ?) LOOP EXECUTE IMMEDIATE 'SELECT * FROM '|| i.tab_name ||''; END LOOP;