将字符附加到Oracle SQL中多行中的字符串(Append characters to a string in multiple rows in Oracle SQL)

编程入门 行业动态 更新时间:2024-10-28 07:31:23
将字符附加到Oracle SQL中多行中的字符串(Append characters to a string in multiple rows in Oracle SQL)

我试图通过附加字符串'999'来更新多行中的单个列:

UPDATE integration.ol_orders SET order_id = ((SELECT order_id FROM integration.ol_orders WHERE status = 2) || '999') WHERE status = 2

但不管出于什么原因,我总是收到“ORA-01427:单行子查询返回多行提示”的错误。

所以,当我迭代我的n行时,我试图做到:

a1 = a1 || '999' a2 = a2 || '999' a3 = a3 || '999' an = an || '999'

有什么建议怎么办?

编辑:将'+'更改为'||',仍然没有运气

I'm trying to update a single column in multiple rows by appending the string '999':

UPDATE integration.ol_orders SET order_id = ((SELECT order_id FROM integration.ol_orders WHERE status = 2) || '999') WHERE status = 2

but for whatever reason, I keep getting the error of "ORA-01427: single-row subquery returns more than one row tips".

So, as I iterate my n rows, I'm trying to do:

a1 = a1 || '999' a2 = a2 || '999' a3 = a3 || '999' an = an || '999'

Any suggestions how to go about this?

edit: changed '+' to '||', still no luck

最满意答案

子查询看起来没有必要,只要这样做就可以工作:

UPDATE integration.ol_orders SET order_id = order_id || '999' WHERE status = 2

如果我记得Oracle正确使用|| 用于连接。 如果它是一个整数,可能需要将order_id转换为字符类型,我对此不确定,目前无法对其进行测试。 (如注释中所述,转换应该是隐含的,否则可以使用TO_CHAR()明确地TO_CHAR()它)。

确保在运行之前备份或复制表格...

The subquery looks unnecessary, just doing this should work:

UPDATE integration.ol_orders SET order_id = order_id || '999' WHERE status = 2

If I remember right Oracle uses || for concatenation. It might be necessary to cast the order_id to a character type if it's an integer, I'm not sure about that and can't test it at the moment. (The conversion should be implicit as stated in a comment, otherwise you can use TO_CHAR() to cast it explicitly).

Make sure to have a backup or copy of the table before running though...

更多推荐

本文发布于:2023-07-08 00:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1070168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   字符   SQL   中多行中   rows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!