0

我的产品表中有一个名为 Prod_code 的列。我只需要从产品表中选择有效的 prod_code 并将其加载到另一个表中。有效的 prod_code 是其中没有任何特殊字符的代码。

有效产品代码: WER1234、ASD1345

INVALID prod_code: ABC$123,LPS????,$$$(我需要检查并过滤掉)。
我怎样才能做到这一点?

产品代码的 src 列表

WER1234 
ASD1345
ABC$123
LPS????
$$$

产品代码的目标列表

WER1234
ASD1345
4

1 回答 1

0

这非常可怕,但它确实有效。它使用 LIKE 谓词来拒绝不可接受的字符串。您可能还可以使用 SIMILAR TO 谓词来指定可接受的字符串,但我猜 LIKE 更快。

select prod_code from products
where prod_code not like '%\['+x'00'+'-'+x'2f'+','+
                               x'3a'+'-'+x'40'+','+
                               x'5d'+'-'+x'7f'+'\]%' escape '\'
 and prod_code not like '%\%'
 and prod_code not like '%[%'
于 2015-05-06T09:42:04.040 回答