oracle 在列中搜索字符串

r55awzrz  于 2022-11-22  发布在  Oracle
关注(0)|答案(3)|浏览(169)

我需要显示此列的结果,其中Product_name列在结果中包含“Documentation”或“documentation”。无论单词是小写还是大写,查询都必须返回结果
https://i.stack.imgur.com/bjLuY.png

SELECT UPPER(PROD_NAME)as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN
FROM PRODUCTS 
WHERE (PROD_NAME like '%Documentation%'
 or PROD_NAME like '%DOCUMETATION%')
 and LENGTH(PROD_NAME) <= 35
    order by 2 DESC;

我找到了这个解决方案,有什么建议吗

nuypyhwy

nuypyhwy1#

SELECT UPPER(PROD_NAME)as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN
FROM PRODUCTS 
WHERE lower(PROD_NAME) like '%documentation%'
 and LENGTH(PROD_NAME) <= 35
    order by 2 DESC;
myss37ts

myss37ts2#

如果要获取表中的原始PROD_NAME,请不要在select子句中使用UPPER ...

SELECT PROD_NAME as PROD_NAME, LENGTH(PROD_NAME) as PROD_NAME_LEN
FROM PRODUCTS 
WHERE LOWER(PROD_NAME) like '%documentation%'
      -- UPPER(PROD_NAME) like '%DOCUMENTATION%' - instead of LOWER(), you can do it this way too - same result
      And LENGTH(PROD_NAME) <= 35
ORDER BY 2 DESC;

此致

3duebb1j

3duebb1j3#

当我在MySQL中使用PHP时,我只会使用如下代码:

$setgeneral=$db->prepare("SELECT * FROM general where general_id=:general_id");
$setgeneral->execute(array('general_id' => 0));
$getgeneral=$setgeneral->fetch(PDO::FETCH_ASSOC);

这段代码使用“general”表,并产生一行或多行general_id=0的行。当然,它不仅仅用于id。您也可以将它用于prod_name!

相关问题