【问题标题】:Updating A Column From Another Table And Concatenating Two Columns In Single Query从另一个表更新一列并在单个查询中连接两列
【发布时间】:2016-05-25 02:21:52
【问题描述】:

甲骨文数据库 在 SQL 中:

如何从另一个表的列更新表的一列以及如何在单个查询中连接第一个表的两列

如果 table_1 的 column_1 与 table_2 的 column_A 匹配,则根据 table_2 的 column_B 的值更新 table_1 的 column_2,并将 table_1 的 column_3 和 column_4 连接到 table_1 的 column_5。

我试过了:

UPDATE T1
  SET column_2 = T2.column_B,
      column5 = T1.column_3 + T1.column_4
FROM table_1 AS T1
JOIN table_2 AS T2
  ON T2.column_A = T1.column_1

我没听懂

【问题讨论】:

  • “+”是干什么用的?你是用+连接的吗?
  • 如果您想要连接,您应该使用适用于您正在使用的数据库引擎的方法。 Oracle 有关于该主题的文档。
  • 如果你有 t1.col3 和 t1.col4 为什么还要连接它们呢?对我来说似乎是多余的

标签: sql oracle


【解决方案1】:

您正在使用 '+' 作为字符串连接。 Oracle 的字符串连接运算符是 '||'试试下面的代码

UPDATE (SELECT t1.column_2 column2, 
               t1.column_3 column3,
               t1.column_4 column4,
               t1.column_5 column5,
               t2.column_B columnb
          FROM table_1 t1,
               table_2 t2
         WHERE t1.column_1 = t2.column_A)
   SET column2 = columnb,
       column5 = column3 || column4

【讨论】:

  • t1.column_2 column2 为什么要用column2?这是什么意思?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-07
  • 2012-01-13
  • 1970-01-01
  • 1970-01-01
  • 2010-10-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多