使用python获取Oracle数据库的模式

问题描述 投票:0回答:2

我想列出并描述Oracle数据库中存在的表。

要通过使用SQL Plus等客户端连接到数据库来实现此目的,一种工作方法是:

  1. 列出表格: select tablespace_name, table_name from all_tables;
  2. 获取每个表的列和数据类型: describe [table_name];

但是当通过python使用cx_Oracle时,cur.execute('describe [table_name]')会导致“无效的sql”错误。

我们如何在python中使用qzxswpoi和cx_Oracle?

python cx-oracle
2个回答
1
投票

看来你不能。

从cx_Oracle而不是describe使用:

describe

(来自Richard Moore,来自cur.execute('select column_name, data_type from all_tab_columns where table_name = [table_name]')


1
投票

正如其他人所指出的,没有能力直接描述。但是,我创建了一组库和工具,可以让你这样做。你可以在这里看到它们:http://cx-oracle-users.narkive.com/suaWH9nn/cx-oracle4-3-1-describe-table-query-is-not-working

© www.soinside.com 2019 - 2024. All rights reserved.