繁体   English   中英

子句在Update中不起作用而在Oracle DB中的Select中起作用

[英]Where Clause is not working in Update but working in Select in Oracle DB

我正在尝试执行以下更新查询

update custom_field cfe set cfe.field_value =:valueId where  cp_entity_id = :cId

更新了0行。

这不会更新任何行,但where子句在select查询中可以正常工作并返回1行

select * from custom_field where cp_entity_id = :cId

另外,如果我对cId参数的值进行硬编码,则update可以正常工作,但是我正在从Java程序执行它,因此我无法对值进行硬编码

cp_entity_id列也是一个外键。

试试这个,我遇到了类似的问题。 select primary_key from custom_field where cp_entity_id = :cId查询中使用此select primary_key from custom_field where cp_entity_id = :cId查找主键,然后在更新查询的where子句中使用该主键。

此处说明设置参数的方法之一

PreparedStatement ps = conn.prepareStatement(
  "UPDATE Messages SET description = ?, author = ? WHERE id = ? AND seq_num = ?");

// set the preparedstatement parameters
ps.setString(1,description);
ps.setString(2,author);
ps.setInt(3,id);
ps.setInt(4,seqNum);

// call executeUpdate to execute our sql update statement
ps.executeUpdate();
ps.close();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM