com.huawei.dataconvert.db.convert


private TableInfo getCreateTableSQL(DataBase sourceDB, Connection oraConn,
SqlRecord record) throws Exception
{
Statement stmt = oraConn.createStatement();
String sql = "select COLUMN_NAME ,DATA_TYPE,DATA_LENGTH,NULLABLE,DATA_PRECISION,DATA_SCALE from cols"
+ " where table_name='"
+ record.getTableName()
+ "' order by COLUMN_ID";
ResultSet cols = stmt.executeQuery(sql);

String tableName = record.getTableName();
if (tableName.contains(Constant.SPECIAL_CHAR_$))
{
String ftableName = tableName;
tableName = tableName.replace(Constant.SPECIAL_CHAR_$,
Constant.SPECIAL_CHAR_R$);

this.hsqlDataBase.saveReplaceInfo(record.getUser(),
DataBase.OBJ_TYPE_TABLE, ftableName, ftableName, tableName);
// ,String Objype,String ObjName,String tableName,String
// oracleValue,String hsqlValue
}

TableInfo tableInfo = new TableInfo();
tableInfo.setTablename(tableName);
tableInfo.setDbType("oracle");
List<Column> columns = new ArrayList<Column>();
while (cols.next())
{
Column column = new Column();
column.setColumn_name(cols.getString("COLUMN_NAME"));
String type = cols.getString("DATA_TYPE");
column.setColumn_stype(type);
int lenth = cols.getInt("DATA_LENGTH");
column.setColumn_length(lenth);
String isnull = cols.getString("NULLABLE");
int nullable = 1;
if (isnull.equalsIgnoreCase("N"))
nullable = 0;
column.setColumn_nullable(nullable);
column.setColumn_precision(cols.getInt("DATA_PRECISION"));
Integer ct = ColumnTypeMapping.oracleMap.get(type);
if (null == ct)
{
System.out.println(type);
column.setColumn_type(0);
} else
{
column.setColumn_type(ct);
}
column.setColumn_data_scale(cols.getInt("DATA_SCALE"));
columns.add(column);
}
tableInfo.setColumns(columns);
Primary_Key priKey = sourceDB.getPrimaryKey(record);

tableInfo.setPri_key(priKey);

// String keycols = "";
// add constraint PK_DC_STATUS_DEF primary key (STATUS_TYPE, STATUS_ID)
// String creatKey = "alter table " + priKey.getTableName()
// + " add constraiint " + priKey.getKeyName() + " primary key ("
// + keycols + ")";

String createSql = OracleDataBase.getHQLTableDdlSQL(tableInfo);
tableInfo.setHsqldbCreatTableSQL(createSql);
// tableInfo.setHsqldbCreateKey(creatKey);
stmt.close();
cols.close();
return tableInfo;
}
db.convert

你可能感兴趣的:(oracle,sql)