oracle 监测数据库是否存在指定字段
public static bool ExistColumn(string tableName, string columnName, string connStr) { using (OracleConnection conn = new OracleConnection(connStr)) { try { bool blnRet = false; conn.Open(); OracleCommand cmd = conn.CreateCommand(); cmd.CommandText = "select count(1) from USER_TAB_COLUMNS where table_name=:tablename and column_name=:columnname"; OracleParameter param = cmd.Parameters.Add(":tablename", OracleDbType.Varchar2); param.Value = tableName.ToUpper(); param = cmd.Parameters.Add(":columnname", OracleDbType.Varchar2); param.Value = columnName.ToUpper(); object obj = cmd.ExecuteScalar(); if (obj != null && obj != DBNull.Value) { if (Convert.ToInt64(obj) > 0) { blnRet = true; } } conn.Close(); return blnRet; } catch (Exception ex) { throw ex; } finally { if (conn != null && conn.State != ConnectionState.Closed) { conn.Close(); } } } }
积累小的知识,才能成就大的智慧,希望网上少一些复制多一些原创有用的答案