oracle 批量update进行判断

oracle 批量update进行判断,第1张

使用oracle进行批量update更新数据的时候,可以在更新前进行判断,根据条件进行批量更新

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

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9429078.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存