Oracle Defaults one place to note __oracle

Source: Internet
Author: User

Take the character type as an example

Java code

public static void Main (string[] args) throws Exception {
      String sql = ' Select column_name, data_type, Data_default fr Om 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 ();
   }

Results

SQL statement

Java results

Note

CREATE TABLE Test (a VARCHAR2 (a) Default ' abc ');

A VARCHAR2 | ' ABC ' |

Normal, default value single quotes with parentheses behind

ALTER TABLE test Modify a default ' ABC ';

A VARCHAR2 | ' abc

|

Line breaks appear after default values

ALTER TABLE test Modify a default ' abc ' NOT NULL;

A VARCHAR2 | ' ABC ' |

There are two spaces between ' abc ' and NOT NULL, and two spaces in Java results

ALTER TABLE test Modify a default 132 null;

A VARCHAR2 |132 |

Three spaces

ALTER TABLE test Modify a default 132/*dd*/NOT null;

A VARCHAR2 |132/*dd*/|

Add a note to the situation

ALTER TABLE test Modify a default ' abc '/*dd*/;

A VARCHAR2 | ' ABC '/*dd*/

|

Comments, wrapping

ALTER TABLE test Modify a default ' abc ' NULL/*dd*/;

A VARCHAR2 | ' ABC ' |

The result of the above is only to show that there is a problem, when inserting data, the default value is still 132 or ABC, there will be no space, wrapping, note the case. Similar situations can occur with other types of fields

ALTER TABLE Test add b number default/*dd*/;
ALTER TABLE test add c date default sysdate/*dd*/;

Sql> desc Test
Name Type         Nullable Default        Comments 
-------------------------------------------- -- 
A    VARCHAR2 (A) y        123/*dd*/B number       y        /*dd*/               
C    DATE         y        



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.