oracle 預設值需要注意的一個地方__oracle

來源:互聯網
上載者:User

以字元類型為例

java代碼

public static void main(String[] args) throws Exception {      String sql = "select COLUMN_NAME, DATA_TYPE, Data_Default from user_tab_columns where TABLE_NAME = 'TEST'";      Connection con = DriverManager.getConnection(constr, username, password);      ResultSet rs = con.createStatement().executeQuery(sql);      while(rs.next()) {         System.out.println(rs.getString(1) + "\t" + rs.getString(2) + "\t|" + rs.getString(3) + "|");      }      rs.close();      con.close();   }

結果

Sql語句

Java結果

備忘

create table test(a varchar2(10) default 'abc');

A  VARCHAR2 |'abc'|

正常,預設值單引號後面有括弧

alter table test modify a  default 'abc';

A  VARCHAR2 |'abc'

|

預設值後出現分行符號

alter table test modify a  default 'abc'  not null;

A  VARCHAR2 |'abc'  |

'abc'與not null之間有兩個空格,java結果中也出現兩個空格

alter table test modify a  default 132   null;

A  VARCHAR2 |132   |

三個空格

alter table test modify a  default 132 /*dd*/ not null;

A  VARCHAR2 |132 /*dd*/ |

加入注釋的情況

alter table test modify a  default 'abc' /*dd*/;

A  VARCHAR2 |'abc' /*dd*/

|

有注釋,換行

alter table test modify a  default 'abc' null /*dd*/;

A  VARCHAR2 |'abc' |

 

 

上面的結果僅僅是顯示會有問題,在插入資料時,預設值仍然為132或abc,不會出現空格,換行,注釋的情況。 其它類型的欄位也會出現類似的情況

alter table test add b number default 11 /*dd*/;alter table test add c date default sysdate /*dd*/;SQL> desc testName Type         Nullable Default        Comments ---- ------------ -------- -------------- -------- A    VARCHAR2(10) Y        123 /*dd*/              B    NUMBER       Y        11 /*dd*/               C    DATE         Y        sysdate /*dd*/ 



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.