SQL中的动态"LIKE"语句(Oracle) [英] Dynamic 'LIKE' Statement in SQL (Oracle)

查看:783
本文介绍了SQL中的动态"LIKE"语句(Oracle)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从具有以下结构的表中进行选择:

I am trying to select from a table with the following structure :

MATERIALS 
id
shortname 
longname

长名称类似于短名称的所有行.

all the lines where the long name is like the short name.

我已经尝试过此处介绍的解决方案: SQL中的动态赞语句 ,但对我不起作用.

I've tried the solution presented here : Dynamic Like Statement in SQL , but it doesn't work for me.

SELECT * from MATERIALS where longname like (shortname + '%');

在Oracle中不起作用.

doesn't work in Oracle.

推荐答案

您可以使用 甚至更好的是,标准 || (double pipe) 运算符:

or even better, the standard || (double pipe) operator:

SELECT * 
FROM MATERIALS 
WHERE longname LIKE (shortname || '%')


Oracle的CONCAT()函数接受的参数不超过2个,因此可以使用笨重的CONCAT(CONCAT(a, b), c),而对于运算符则很简单:a || b || c


Oracle's CONCAT() function does not take more than 2 arguments so one would use the cumbersome CONCAT(CONCAT(a, b), c) while with the operator it's the simple: a || b || c

这篇关于SQL中的动态"LIKE"语句(Oracle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆