繁体   English   中英

插入语句中同一列的两个case语句

[英]two case statements for the same column in insert statement

在我的plsql过程中,我基于同一表的其他一些行的值插入行。 对于insert语句中的一列,我需要根据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语句都针对相同的列值。 (两个statemtents一起完成了该列的值),但是第二个“ case”语句却出错了。 这不正确吗?

 input||'.'|| end case 

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

您大概想用替换它

input||'.' end || case

连接两个CASE的结果。

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

这听起来不像是游标的操作。 我希望insert . . . select insert . . . select 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 . . . ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM