GetSchemaTable
This method returns a DataTable
that describes the column metadata of the OracleDataReader
.
Declaration
// C# public override DataTable GetSchemaTable();
Return Value
A DataTable
that contains the metadata of the result set.
Implements
IDataReader
Exceptions
InvalidOperationException
- The connection is closed or the reader is closed.
Remarks
The OracleDataReader.GetSchemaTable
method returns the SchemaTable
.
OracleDataReader SchemaTable
The OracleDataReader
SchemaTable
is a DataTable
that describes the column metadata of the OracleDataReader
.
The value of ColumnSize
can show value up to 32K depending on the definition of VARCHAR2
, NVARCHAR2
, or RAW
type columns in the table definition.
The columns of the SchemaTable
are in the order shown.
Table 6-81 OracleDataReader SchemaTable
Name | Name Type | Description |
---|---|---|
|
|
The name of the column. |
|
|
The |
|
|
The maximum possible length of a value in the column.
|
|
|
The maximum precision of the column, if the column is a numeric data type. This column has valid values for Oracle |
|
|
The scale of the column. This column has valid values for Oracle |
|
|
Indicates whether or not the column is unique.
The default is The value of this property is the same for each occurrence of the base table column in the select list. |
|
|
Indicates whether or not the column is a key column.
This set of columns can be generated from one of the following in descending order of priority:
An explicitly selected |
|
|
|
|
|
The name of the column in the database if an alias is used for the column. |
|
|
The name of the schema in the database that contains the column. |
|
|
The name of the table or view in the database that contains the column. |
|
|
Maps to the common language runtime type. |
|
|
The database column type ( |
|
|
|
|
|
|
|
|
This value is always |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The type name of the UDT. |
|
|
|
|
|
Not Available in ODP.NET, Managed Driver and ODP.NET Core |
|
|
An Not Available in ODP.NET, Managed Driver and ODP.NET Core |
Example
This example creates and uses the SchemaTable
from the reader.
/* Database Setup, if you have not done so yet. connect scott/tiger@oracle CREATE TABLE empInfo ( empno NUMBER(4) PRIMARY KEY, empName VARCHAR2(20) NOT NULL, hiredate DATE, salary NUMBER(7,2), jobDescription Clob, byteCodes BLOB ); Insert into empInfo(EMPNO,EMPNAME,JOBDESCRIPTION,byteCodes) values (1,'KING','SOFTWARE ENGR', '5657'); Insert into empInfo(EMPNO,EMPNAME,JOBDESCRIPTION,byteCodes) values (2,'SCOTT','MANAGER', '5960'); commit; */ // C# using System; using System.Data; using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; class GetSchemaTableSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); string cmdstr = "SELECT EMPNO,EMPNAME FROM EMPINFO where EMPNO = 1"; OracleCommand cmd = new OracleCommand(cmdstr, con); //get the reader OracleDataReader reader = cmd.ExecuteReader(); //get the schema table DataTable schemaTable = reader.GetSchemaTable(); //retrieve the first column info. DataRow row = schemaTable.Rows[0]; //print out the column info Console.WriteLine("Column name: " + row["COLUMNNAME"]); Console.WriteLine("Precision: " + row["NUMERICPRECISION"]); Console.WriteLine("Scale: " + row["NUMERICSCALE"]); reader.Close(); // Close the connection con.Close(); } }