C # Gets the column name and data type of a table in Oracle database "reprint"

Source: Internet
Author: User

C # Gets the SQL statement for the column name and data type of a table in the Oracle database: Select Column_name,data_type, Data_length,data_precision,data_scale from User_tab_ columns [where table_name= table name]  Description of this SQL statement: column_name: A table column name (VARCHAR2 ());d Ata_type: The data type of a table column (VARCHAR2 (106)); Data_length: Length of a table column (number);   use instance: DataSet ds = CFO. Returndataset ("Select Column_name,data_type, data_length from User_tab_columns where table_name= '" + TableName + "'", tab Lename);//tablename  for the specified table name 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 + ")"; Creates a table's SQL statement based on the table column name obtained and the database type length.   There's another way. C # Gets the column name and data type of a table in the Oracle database: SELECT * from a table name where 1<>1 can get an empty data table and loop through the column names that return a table.

C # Gets the column name and data type of a table in Oracle database "reprint"

Related Article

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.