2017-04-04 55 views
0

我试图执行下面的更新查询更新WHERE子句不更新工作,但在选择在甲骨文工作DB

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

0行。

这并没有更新任何行,但相同的where子句与选择查询工作的罚款,并返回1行

select * from custom_field where cp_entity_id = :cId 

另外,如果我硬编码CID参数的值,那么更新工作正常,但我执行它从Java程序,所以我不可能硬编码值

另外cp_entity_id列是一个外键。

+0

您是否正在运行查询和硬编码的更新?您插入了该行的会话,并且没有提交? Java会话将不会看到来自其他会话的未提交数据。 –

+0

No Row已经存在那里我只是想更新 –

+0

所以你可以从Java中查询它,无论是硬编码还是绑定?如何使用绑定变量从IDE /客户端更新它?显示Java调用(设置变量等)的数据和代码可能也有帮助。 –

回答

0

一个设置参数的方式解释here.

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(); 
1

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

+0

谢谢! Vidhu。它的工作 –

+0

似乎像OraclesqlDevloper IDE的一些限制 –