noo*_*che 1 python sql oracle cx-oracle
我将 Python 连接到 Oracle。
我正在尝试使用 python 显示表的属性,即我想显示表模式。我正在使用“描述”语句,但在执行时出现错误' Invalid SQL Statement'.
我做了以下事情:
queryString = 'Describe Customer'
onCursor.execute(queryString)
Run Code Online (Sandbox Code Playgroud)
“Customer”是表名
如果您需要 SQL 语句列描述,则只需使用cursor.description。如果您需要精确的表模式,请从 ALL_TAB_COLUMNS oracle 视图中选择:
cnn = cx_Oracle.connect(cnn_str)
cursor = cnn.cursor()
cursor.execute("SELECT * FROM dual")
print(cursor.description)
cursor.execute("select * from ALL_TAB_COLUMNS where table_name = 'DUAL'")
print(cursor.fetchall())
cursor.close()
Run Code Online (Sandbox Code Playgroud)
它将证明输出:
[('DUMMY', <class 'cx_Oracle.STRING'>, 1, 4, None, None, 1)]
[('SYS', 'DUAL', 'DUMMY', 'VARCHAR2', None, None, 1, None, None, 'Y', 1, None, None, 1, b'X', b'X', 1, 0, 1, datetime.datetime(2009, 4, 25, 23, 49, 59), 1, 'CHAR_CS', 1, 'YES', 'NO', 2, 1, 'B', 'NO', 'YES', 'NONE', 'NO', 'NO', None, None, None)]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6051 次 |
| 最近记录: |