|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: building a pl/sql query from select statement [message #561207 is a reply to message #561203] |
Thu, 19 July 2012 08:55   |
 |
candi
Messages: 28 Registered: July 2012
|
Junior Member |
|
|
first of all, thanks again. I have this code:
(created a work table OLD_DIR)
BEGIN
FOR rec IN (select 'create or replace directory '||dir_name||' as '''||
regexp_replace(dir_path, '^(/[^/]*/)(.*)$', '\1'||name||'/\2')||''';' as NEW_DIR
from OLD_DIR, v$database
where dir_path like '/xyz%') LOOP
execute immediate rec.NEW_DIR;
END LOOP;
END;
but I get an error:
ORA-00911: invalid character
ORA-06512: at line 6
would it be simpler to use a cursor
ie
declare cursor cr_new_dir is
<QUERY>
BEGIN
for rec in NEW_DIR loop
execute immediate rec.NEW_DIR
end loop;
end;
(but this also dosent work)
[Updated on: Thu, 19 July 2012 08:56] Report message to a moderator
|
|
|
|
| Re: building a pl/sql query from select statement [message #561208 is a reply to message #561207] |
Thu, 19 July 2012 08:57   |
 |
BlackSwan
Messages: 20097 Registered: January 2009
|
Senior Member |
|
|
see a picture of my car.
It doesn't work.
tell me how to make my car go.
Since we don't have your tables or data,
we can not compile, run or test posted code.
It would be helpful if you provided DDL (CREATE TABLE ...) for tables involved.
It would be helpful if you provided DML (INSERT INTO ...) for test data.
It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/311
It would be helpful if you provided expected/desired results & a detailed explanation how & why the test data gets transformed or organized.
[Updated on: Thu, 19 July 2012 08:58] Report message to a moderator
|
|
|
|
| Re: building a pl/sql query from select statement [message #561209 is a reply to message #561208] |
Thu, 19 July 2012 09:19   |
mnitu
Messages: 131 Registered: February 2008 Location: Reims
|
Senior Member |
|
|
Kindly suggest to replace execute immediate rec.NEW_DIR by Dbms_output(rec.NEW_DIR) in order to inspect the sql statement you are generating.
Also suggest to not using ";" in order to finish your SQL statement; SQL doesn't need this character it's PL/SQL or sqlplus who needs it.
Please follow forum guidelines.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|