将mysql查询更改为oracle

8fq7wneg  于 2021-06-21  发布在  Mysql
关注(0)|答案(4)|浏览(237)

下面的sql查询在mysql数据库服务器上运行,但生产服务器在oracledb上运行。如果有人能帮助将此查询转换为在oracle db中工作,那就太难了:

SELECT LAS_NAME as lastName, 
       OTHER_NAMES as firstName, 
       NUBAN as accountNumber, 
       FLG as account_status, 
       CUS_EMAIL as emailAddress,  
       CUS_MOBILE as phoneNumber 
FROM " . TABLE_NAME . " 
WHERE `OTHER_NAMES` LIKE ? AND 
      (CUS_EMAIL = ? OR 
       CUS_MOBILE = ?)

注意:这个查询在mysql上运行得很好,但是当我在oracledb上尝试时,总是返回一个错误。

kadbb459

kadbb4591#

就我有限的oracle知识而言,它应该是这样的:

SELECT LAST_NAME as lastName, 
       OTHER_NAMES as firstName, 
       NUBAN as accountNumber, 
       FLG as account_status, 
       CUS_EMAIL as emailAddress,  
       CUS_MOBILE as phoneNumber 
FROM TABLE_NAME 
WHERE OTHER_NAMES LIKE '?%?' AND 
      (CUS_EMAIL = '?' OR 
       CUS_MOBILE = '?');

记住用一个(分号)。
至于like语句,请记住使用“单引号”,因为oracle对字符串非常特殊。
对于不应该使用引号的表名,如果愿意,plsql可以是一个残酷的情妇。希望这有帮助。

f45qwnt8

f45qwnt82#

我不是mysql的Maven,也不了解 " . TABLE_NAME . " 所以我假设你指的是一个表名。在oracle中,如果表不在另一个模式或远程数据库中,我们只使用表名。
同样,backtick`在oracle中也不是有效的符号。

SELECT LAS_NAME as lastName, 
       OTHER_NAMES as firstName, 
       NUBAN as accountNumber, 
       FLG as account_status, 
       CUS_EMAIL as emailAddress,  
       CUS_MOBILE as phoneNumber 
FROM your_table
WHERE OTHER_NAMES LIKE ? AND 
      (CUS_EMAIL = ? OR 
       CUS_MOBILE = ?)
dohp0rv5

dohp0rv53#

假设您正在传递表名,下面的提示对我有效

SELECT LAS_NAME as lastName, 
       OTHER_NAMES as firstName, 
       NUBAN as accountNumber, 
       FLG as account_status, 
       CUS_EMAIL as emailAddress,  
       CUS_MOBILE as phoneNumber 
FROM TABLE_NAME 
WHERE  OTHER_NAMES LIKE '%' AND 
      (CUS_EMAIL = '' OR 
       CUS_MOBILE = '')
slwdgvem

slwdgvem4#

根据您的表名和列名,尝试使用适当的步骤,您将在步骤3得到答案
第一步:
选择lastname作为lastname,other name作为firstname,nuban作为accountnumber,flg作为account status,cus email作为emailaddress,
cus\u mobile as phonenumber from table\u name(表\u名称中的电话号码)
其他名称,如“%?%”;
第二步:
选择lastname作为lastname,other name作为firstname,nuban作为accountnumber,flg作为account status,cus email作为emailaddress,
cus\u mobile as phonenumber from table\u name(表\u名称中的电话号码)
其他名称,如“%?%”和(cus_email=“?”);
第三步:
选择lastname作为lastname,other name作为firstname,nuban作为accountnumber,flg作为account status,cus email作为emailaddress,
cus\u mobile as phonenumber from table\u name(表\u名称中的电话号码)
其中其他名称,如“%?%”和(cus_email='?'或cus_mobile='?');

相关问题