Oracle喜欢模式匹配LIKE Con​​dition

时间:2016-12-08 11:36:51

标签: sql oracle

我需要使用类似条件的列,例如关注'UPDATE'

 UPDATE CUSTOMER_TRANSACTIONS ct
 SET PROCESSID = vQUARTER 
 where ct.CUSTOMERID = l_arrc1(i).CUSTOMERID 
 and ct.APPOINTOFCAID = l_arrc1(i).APPOINTOFCAID        
 and ct.INVOICEID like "'"||l_arrc1(i).INVOICEID||%||"'";

代替

UPDATE CUSTOMER_TRANSACTIONS ct
SET PROCESSID = '2015Q4'
where ct.CUSTOMERID = l_arrc1(i).CUSTOMERID 
and ct.APPOINTOFCAID = l_arrc1(i).APPOINTOFCAID        
and ct.INVOICEID like '0158741%';

INVOICEIDl_arrc1(i).INVOICEID是VARCHAR

怎么做?

2 个答案:

答案 0 :(得分:1)

您缺少适当的字符串分隔符,单引号:

UPDATE CUSTOMER_TRANSACTIONS ct
    SET PROCESSID = vQUARTER 
    WHERE ct.CUSTOMERID = l_arrc1(i).CUSTOMERID and
          ct.APPOINTOFCAID = l_arrc1(i).APPOINTOFCAID and      
          ct.INVOICEID LIKE l_arrc1(i).INVOICEID || '%' ;

SQL中字符串的相应分隔符是单引号而不是双引号。

答案 1 :(得分:0)

假设INVOICEIDnumber列:

UPDATE customer_transactions ct
   SET processid = vQUARTER
 WHERE ct.customerid = l_arrc1(i).customerid
   AND ct.appointofcaid = l_arrc1(i).appointofcaid
   AND to_char(ct.invoiceid) LIKE to_char(l_arrc1(i).INVOICEID) || '%';

如果invoiceid不是number数据类型,则可以删除to_char