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