update tables_name t
set t.value1 = case
when t.value1 = '33020' then
'330200'
when t.value1 = '33021' then
'330210'
when t.value1 = '33022' then
'330221'
end
where t.value1 in ('33020', '33021', '33022')
C#利用update更新数据到oracle数据库:第一步:打开oracle数据库
public static string connString = ""
public static OracleConnection conn = null
//打开数据库连接
public static bool Open()
{
//从配置文件中获取连接字符串
//配置文件需要放在项目目录下的bin\Release中
connString = getXmlValue("connString")
conn = new OracleConnection(getXmlValue("connString"))
try
{
conn.Open()
Console.WriteLine("数据库连接成功")
return true
}
catch (System.Exception ex)
{
Console.Write(ex.Message)
MessageBox.Show("未能连接到数据库")
return false
}
第二步:执行更新方法:
public static int update(int ruleId, int equipmentId, String equipmentName, String propertyName, int ruleType, String ruleRequest, String ruleRequestOther, String ruleExplain)
{
String sql = "update Device_Attr t set t.BASEID = :equipmentId, t.BASENAME = :equipmentName,t.CA_NAME = :propertyName,t.CA_RULETYPE = :ruleType,t.CA_RULETEXT = :ruleRequest,t.CA_RULETEXT2 = :ruleRequestOther,t.CONTENT = :ruleExplain where t.CA_ID =:ruleId"
OracleCommand cmd = new OracleCommand(sql, conn)
OracleParameter param_1 = new OracleParameter(":equipmentId", equipmentId)
cmd.Parameters.Add(param_1)
OracleParameter param_2 = new OracleParameter(":equipmentName", equipmentName + "$")
cmd.Parameters.Add(param_2)
OracleParameter param_3 = new OracleParameter(":propertyName", propertyName)
cmd.Parameters.Add(param_3)
OracleParameter param_4 = new OracleParameter(":ruleType", ruleType)
cmd.Parameters.Add(param_4)
OracleParameter param_5 = new OracleParameter(":ruleRequest", ruleRequest)
cmd.Parameters.Add(param_5)
OracleParameter param_6 = new OracleParameter(":ruleRequestOther", ruleRequestOther)
cmd.Parameters.Add(param_6)
OracleParameter param_7 = new OracleParameter(":ruleExplain", ruleExplain)
cmd.Parameters.Add(param_7)
OracleParameter param_8 = new OracleParameter(":ruleId", ruleId)
cmd.Parameters.Add(param_8)
int result = cmd.ExecuteNonQuery()
return result
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)