![](/img/trans.png)
[英]IN clause for Oracle Prepared Statement in Python cx_Oracle
[英]cx_oracle select statement with where clause and single quote
import cx_Oracle
dsn_tns = cx_Oracle.makedsn('**********', '*******', service_name='***')
conn = cx_Oracle.connect(user='******', password='*******', dsn=dsn_tns)
c = conn.cursor()
c.execute('select username,created from dba_users where username='USERNAME' ')
for row in c:
print (row[0], '-', row[1]) # this only shows the first two columns. To add an additional column you'll need to add , '-', row[2], etc.
conn.close()
File "*******************", line 9
c.execute('select username,created from dba_users where username='MONITOR' ')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
这里出了什么问题,当我在用户名周围使用单引号时,我收到了这个错误。
c.execute("""select username,created from dba_users where username=:USERNAME""", USERNAME = 'Cristiano Ronaldo')
您的 SQL 语句的语法确实不正确。 目前尚不清楚 USERNAME 的值应该是什么。 如果它只是应该是连接的用户,你可以这样做:
c.execute("select username, created from dba_users where username = user")
如果您打算将其作为参数,则可以执行以下操作:
c.execute("select username, created from dba_users where username = :user",
user=USERNAME)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.