如何在Dynamic SQL中编写查询,我收到的错误如下所示。
EXECUTE IMMEDIATE
'CREATE TABLE SAMPLE
SELECT EXTRACT (VALUE (d), '''//row/text()''').getstringval ()
FROM (SELECT XMLTYPE ( '''<rows><row>'''
|| REPLACE ('''venkat,vijay,bylla,12''', ''',''', '''</row><row>''')
|| '''</row></rows>'''
) AS xmlval
FROM DUAL) x,
TABLE (XMLSEQUENCE (EXTRACT (x.xmlval, '''/rows/row'''))) d';
错误是:
Error(118,34): PLS-00103: Encountered the symbol "/" when expecting
one of the following: ( - + case mod new null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
答案 0 :(得分:1)
您的报价错误,您需要为列添加别名..eg:
SQL> begin
2 EXECUTE IMMEDIATE
3 'CREATE TABLE SAMPLE AS
4 SELECT EXTRACT (VALUE (d), ''//row/text()'').getstringval () a
5 FROM (SELECT XMLTYPE ( ''<rows><row>''
6 || REPLACE (''venkat,vijay,bylla,12'', '','', ''</row><row>'')
7 || ''</row></rows>''
8 ) AS xmlval
9 FROM DUAL) x,
10 TABLE (XMLSEQUENCE (EXTRACT (x.xmlval, ''/rows/row''))) d';
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> select * from sample;
A
--------------------------------------------------------------------------------
venkat
vijay
bylla
12
但是你为什么要在oracle中动态创建表?如果你正在考虑在你的代码中动态创建表,这是不好的做法,在oracle中要避免使用(如果需要,请使用全局临时表)。