C#获取oracle数据库某表的列名和数据类型的sql语句为:
select column_name,data_type ,data_length,data_precision,data_scale from user_tab_columns [where table_name=表名]
关于此sql语句的说明:
column_name:某表列名(varchar2(30));
data_type:某表列的数据类型(varchar2(106));
data_length:某表列的长度(number);
使用实例:
DataSet ds = cfo.ReturnDataSet("select column_name,data_type ,data_length from user_tab_columns where table_name=‘" + TableName + "‘", TableName);//TableName
为指定的表名
string strcreatesql = "";
for (int j = 0; j < ds.Tables[TableName].Rows.Count; j++)
{
if (j == ds.Tables[TableName].Rows.Count - 1)
{
strcreatesql += ds.Tables[TableName].Rows[j]["column_name"].ToString() + " " + ds.Tables[TableName].Rows[j]["data_type"].ToString() + "(" + ds.Tables
[TableName].Rows[j]["data_length"].ToString() + ")";
}
else
{
strcreatesql += ds.Tables[TableName].Rows[j]["column_name"].ToString() + " " + ds.Tables[TableName].Rows[j]["data_type"].ToString() + "(" + ds.Tables
[TableName].Rows[j]["data_length"].ToString() + ")" + ",";
}
}
string strcreatesqlvale = "create table " + TableName + "(" + strcreatesql + ")"; 根据获取的表列名和数据库类型长度来创建表的sql语句。
还有一种方法C#获取oracle数据库某表的列名和数据类型:
select * from 某表名 where 1<>1
这样可以取得空数据表,循环取返回某表的列名也可以.