[英]cx_Oracle.DatabaseError: ORA-00922: missing or invalid option when trying to execute pl/sql using python
AM trying to execute the PL/SQL script which am constructing at the run time but getting AM试图执行在运行时正在构造的PL / SQL脚本,但是
cx_Oracle.DatabaseError: ORA-00922: missing or invalid option
Looks like some formatting issue with the script as it is showing as STRING but still not sure how to resolve it. 脚本显示为STRING时,似乎出现了一些格式问题,但仍不确定如何解决。
Below is the code that am trying: 下面是正在尝试的代码:
script = '''Set serveroutput on;
DECLARE
V_req pls_integer;
BEGIN
V_req := infomediary_nse.request(
p_inApp_id => 100,
p_inPayload => XMLTYPE(
'<tag>hello</tag>'
)
);
END;
/'''
dbconnection = cx_Oracle.connect(ConnectionString)
str, err = dbconnection.cursor().execute(script)
set serveroutput on
is not a PL/SQL command, but a SQL*Plus one, so you can only use it in SQL*PLus. 不是PL / SQL命令,而是SQL * Plus命令,因此只能在SQL * PLus中使用它。
Even the final /
should be removed, because it also is SQL*Plus specific. 即使最后一个/
也应删除,因为它也是SQL * Plus特有的。
This should work: 这应该工作:
script = '''DECLARE
V_req pls_integer;
BEGIN
V_req := infomediary_nse.request(
p_inApp_id => 100,
p_inPayload => XMLTYPE(
'<tag>hello</tag>'
)
);
END;'''
If you used set serveroutput on
to get the result from DBMS_OUTPUT
calls, you can have a look at this . 如果使用set serveroutput on
来从DBMS_OUTPUT
调用中获取结果,则可以查看this 。
For example, this: 例如,这:
import cx_Oracle
conn = cx_Oracle.connect(..., ..., ...)
c = conn.cursor()
vSql = '''begin
dbms_output.put_line('Hello!');
end;
'''
c.callproc("dbms_output.enable")
c.execute(vSql)
statusVar = c.var(cx_Oracle.NUMBER)
lineVar = c.var(cx_Oracle.STRING)
while True:
c.callproc("dbms_output.get_line", (lineVar, statusVar))
if statusVar.getvalue() != 0:
break
print (lineVar.getvalue())
conn.close()
gives: 给出:
E:\Python>python testOracle.py
Hello!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.