使用变量更新查询

时间:2018-04-17 09:11:57

标签: sql string oracle sql-update

是否可以使用变量串联(VARCHARS2的列)更新变量?

UPDATE ARTICLE 
SET DESCRIPTION = (CPV_DESCRIPTION + '/' LEVEL1_DESCRIPTION + LEVEL2_DESCRIPTION+LEVEL3_DESCRIPTION) 
WHERE ID_ARTICULO = 209;

UPDATE ARTICLE 
SET DESCRIPTION = concat(CPV_DESCRIPTION,'/',LEVEL1_DESCRIPTION,' ',LEVEL2_DESCRIPTION' 'LEVEL3_DESCRIPTION) 
WHERE ID_ARTICULO = 209;

这两种情况都给我一个错误。

1 个答案:

答案 0 :(得分:1)

如@a_horse所述...... concat()函数只需要2个参数。当您指定多于2个要参数的参数时,需要使用||运算符。此外,+Oracle中的逻辑运算符,与Java中用于连接的运算符不同。试试这个:

UPDATE ARTICLE
SET DESCRIPTION = CPV_DESCRIPTION
                  || '/'
                  ||LEVEL1_DESCRIPTION
                  ||' '
                  ||LEVEL2_DESCRIPTION
                  ||' '
                  ||LEVEL3_DESCRIPTION
WHERE ID_ARTICULO = 209;