Explain FOR in oracle

半城伤御伤魂 提交于 2019-12-11 06:10:41

问题


I am making a test. I have all tests in rows, so my rows looks like this;

ID  |  TEST
----------------------------------
1   |  'select sysdate from dual'
2   |  'select sysdatesss from dual'

Now I read it row by row and I need to test it with EXPLAIN PLAN FOR

so the for the first row it would be

EXPLAIN PLAN FOR select sysdate from dual

but I have problem converting the TEST field. Right now I use;

EXPLAIN PLAN FOR testing.TEST

but it does not work.

Any ideas?


回答1:


A SQL statement is a string, but you have to use dynamic SQL to convert a SQL statement that is stored as a string.

FOR i IN (SELECT t.test
            FROM TESTING t) LOOP
   EXECUTE IMMEDIATE 'EXPLAIN PLAN FOR '|| i.test ||'';
END LOOP;

Reference:

  • EXECUTE IMMEDIATE



回答2:


EXEC IMMEDIATE 'EXPLAIN PLAN FOR ' || TESTING.TEST



来源:https://stackoverflow.com/questions/2944250/explain-for-in-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!