oracle10g中多行的单列更新
Update table_1 set col1= 1 where col2 = 'ONE';
update table_1 set col1= 2 where col2 = 'TWO';
Update table_1 set col1= 3 where col2 = 'THREE';
...
update table_1 set col1= 100 where col2 = 'HUNDRED';
是否有任何简化的方法可以在单个查询中实现此目的,而不是在 oracle10g 中编写 100 个更新状态网?
Update table_1 set col1= 1 where col2 = 'ONE';
update table_1 set col1= 2 where col2 = 'TWO';
Update table_1 set col1= 3 where col2 = 'THREE';
...
update table_1 set col1= 100 where col2 = 'HUNDRED';
Is there any simplified way to achive this in a single query instead of writing 100 update statemnets in oracle10g??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为可能有一个使用Oracle Case-Statement 或decode-function 的解决方案,尽管这将是一个相当长的语句,而且我不太确定相对于100 个更新语句的优势是什么。另外,我不知道有关参数列表长度等的任何限制。
案例示例:
解码示例:
I think there might be a solution with Oracle Case-Statement or the decode-function, although it will be a quite long statement and I am not quite sure what the advantage over 100 update statements might be. Also I am not aware of any limitations regarding length of parameter-lists, etc.
Example for Case:
Example for decode:
您可以使用 Julian 拼写格式(搜索 Asktom.oracle.com 了解更多详细信息)
这是我的会话的输出: -
令人讨厌的提示(bypass_ujvc)忽略了内联视图未保留密钥的事实 - 实际上您应该请改用合并语句。但这不是现实世界的场景,对吧! (并且您必须将“HUNDRED”视为特殊情况=“ONE HUNDRED”。)
You could make use of the Julian spelling formats (search asktom.oracle.com for more details)
Here's output from my session:-
The nasty hint (bypass_ujvc) ignores the fact that the inline view isn't key preserved - in practice you should use a merge statement instead. But this isn't a real-world scenario, right! (And you'll have to treat your 'HUNDRED' as a special case = 'ONE HUNDRED'.)