我知道如何運行正常的選擇查詢。
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@xxx";
String uname = "";
String passwd = "";
Connection conn = DriverManager.getConnection(url, uname, passwd);
Statement stmt = conn.createStatement();
String sql = "select * from table_name";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println();
}
但是如何運行查詢sql = "describe table_name"呢?
uj5u.com熱心網友回復:
describe是 SQL*Plus 命令;盡管它可以在其他地方使用(例如在 SQL Developer 或 TOAD 中),但它不是“標準”命令,所以我認為您不能按照自己的方式使用它。
因此,由于您已經知道如何運行“正常”查詢,請再次執行此操作,但這次是通過從中獲取user_tab_columns包含您需要的資料的資料。例如:
SQL> SELECT column_name, data_type, data_precision, data_length, nullable
2 from user_tab_columns
3 where table_name = 'TEMP';
COLUMN_NAME DATA_TYPE DATA_PRECISION DATA_LENGTH N
--------------- --------------- -------------- ----------- -
ID NUMBER 22 Y
ENAME VARCHAR2 10 Y
JOB VARCHAR2 15 Y
DEPT NUMBER 22 Y
HIREDATE DATE 7 Y
LOC VARCHAR2 10 Y
6 rows selected.
可以類比
SQL> describe temp
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER
ENAME VARCHAR2(10)
JOB VARCHAR2(15)
DEPT NUMBER
HIREDATE DATE
LOC VARCHAR2(10)
SQL>
作為評論:有一個很好的視圖,dictionary您可以查詢并找到一些有用的資訊,即系統視圖,然后可以讓您找到其他資訊。就是這樣:
SQL> select * from dictionary
2 where lower(table_name) like '%user%' and lower(comments) like '%comment%';
TABLE_NAME COMMENTS
------------------------- --------------------------------------------------
USER_COL_COMMENTS Comments on columns of user's tables and views
USER_INDEXTYPE_COMMENTS Comments for user-defined indextypes
USER_MVIEW_COMMENTS Comments on materialized views owned by the user
USER_OPERATOR_COMMENTS Comments for user-defined operators
USER_TAB_COMMENTS Comments on the tables and views owned by the user
好的; 它是user_tab_comments,user_col_comments我需要。因此,讓我們在temp表格中添加一些注釋:
SQL> comment on table temp is 'Sample table for Stack Overflow';
Comment created.
SQL> comment on column temp.ename is 'Employee''s name';
Comment created.
結果:
SQL> select * from user_tab_comments where table_name = 'TEMP';
TABLE_NAME TABLE_TYPE COMMENTS
------------------------- ----------- --------------------------------------------------
TEMP TABLE Sample table for Stack Overflow
SQL> select * from user_col_comments where table_name = 'TEMP';
TABLE_NAME COLUMN_NAME COMMENTS
------------------------- --------------- --------------------------------------------------
TEMP ID
TEMP ENAME Employee's name
TEMP JOB
TEMP DEPT
TEMP HIREDATE
TEMP LOC
6 rows selected.
SQL>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/489477.html
上一篇:(SQL)我必須使用IN運算子從2個不同的表中獲取資訊
下一篇:dom串列呈現不需要的逗號或引號
