0

在我的 plsql 过程中,我根据同一张表的其他一些行的值插入行。对于插入语句中的一列,我需要根据 case 语句操作现有的行值,然后插入。我要做的是:

我为要使用的现有行创建一个光标,然后使用它的列值。

 INSERT into table columns
 (column names..)
 values (
 curser.column names
 ,case 
     when input is null then null 
     else input||'.'|| 
 end 
 case 
     when curser.column like 'drop:%' then replace(curser.column,'drop:%') 
     else curser.column 
 end
 , other column values).

这里输入是我的程序的一个参数。

两个 case 语句都针对相同的列值。(两个语句一起完成了该列的值)但是第二个“case”语句出现错误。这不正确吗?

4

2 回答 2

2
input||'.'|| end case

该部分在语法上不正确。第二个字符串连接没有第二个操作数, . 之后也没有逗号(或其他运算符)end

你大概想用

input||'.' end || case

连接两个CASEs 的结果。

如果还有其他问题,例如目标列的数量与值的数量不匹配,则很难判断,因为遗漏了太多。

于 2018-07-24T11:03:52.553 回答
1

这听起来不像是光标操作。我希望insert . . . select

insert into t columns (column names..)
    select . . .,
           (case when t.input is not null then input || '.' end),
           replace(t.column, 'drop:', ''),
           . . .
    from t
    where . . . ;
于 2018-07-24T11:00:53.573 回答