数据库常用查询语句报错及解决方案,根据自己经验总结下:
语句:select * from FF_GW_CUST_RC where CST_NM like '%杜芳%' and and CREADIT_AMT='12000';
报错:18:05:27 [SELECT - 0 row(s), 0.000 secs] [Error Code: 942, SQL State: 42000] ORA-00942: 表或视图不存在
解决:表不存在,修改表的名字
语句:select * from FF_GW_CUST_RC where CT_NO='00156712020042664271';
报错:16:44:17 [SELECT - 0 row(s), 0.000 secs] [Error Code: 904, SQL State: 42000] ORA-00904: "CT_NO": 标识符无效
解决:发现数据库中列名CT_NO不存在,CT_ID存在,因此修改语句中的列名
语句:select distinct BS_NO from FF_GW_REQUEST where BS_NO between '1100931' and 1100939'
select distinct BS_NO from FF_GW_REQUEST where BS_NO='1234'
报错:09:50:12 [SELECT - 0 row(s), 0.000 secs] [Error Code: 933, SQL State: 42000] ORA-00933: SQL 命令未正确结束
解决:第一条语句前面增加 /*
或者仅选中第二句执行
语句:select distinct BS_NO from FF_GW_REQUEST where BS_NO between '1100931' and 1100939'
报错:09:51:58 [SELECT - 0 row(s), 0.000 secs] [Error Code: 1756, SQL State: 42000] ORA-01756: 引号内的字符串没有正确结束
解决:'1100939'增加左边的引号
语句:select * from FF_GW_REQUEST where BS_NO
报错:09:54:01 [SELECT - 0 row(s), 0.000 secs] [Error Code: 920, SQL State: 42000] ORA-00920: 无效的关系运算符
解决:BS_NO赋值
语句:select * from FF_GW_REQUEST where
报错:09:54:44 [SELECT - 0 row(s), 0.000 secs] [Error Code: 936, SQL State: 42000] ORA-00936: 缺失表达式
解决:where后 +任意条件
语句:# select * from FF_GW_CUST_RC where CT_NO='00156712020042664271';
报错:09:59:31 [# - 0 row(s), 0.000 secs] [Error Code: 911, SQL State: 22019] ORA-00911: 无效字符
解决:/* select * from FF_GW_CUST_RC where CT_NO='00156712020042664271';
语句:select * from FF_REQUEST where CR_DATE between ’2019-03-20’ and ’2019-03-21’
报错:16:43:58 [SELECT - 0 row(s), 0.000 secs] [Error Code: 1843, SQL State: 22008] ORA-01843: 无效的月份
解决:select * from FF_REQUEST where to_char(CR_DATE,YYYY-MM-DD) =’2019-03-20’
select * from FF_REQUEST where to_char(CR_DATE,YYYY-MM-DD) between ’2019-03-20’ and ‘2019-03-24’
语句:select * from FF_REQUEST where CR_DATE between ’2019-03-20’ YYYY-MM-DD and ’2019-03-21’ YYYY-MM-DD
报错:00905:缺失关键字
解决:select * from FF_REQUEST where to_char(CR_DATE,YYYY-MM-DD) =’2019-03-20’
语句:select * from FF_REQUEST order by CR_DATE desc where to_char(CR_DATE,YYYY-MM-DD) =’2019-03-20’
报错:00933:SQL命令未正确结束
原因:order排序应该放在条件的后面,正确的用法是:select 列名 from 表名 where 条件 order by 列名 desc
解决:select * from FF_REQUEST where to_char(CR_DATE,YYYY-MM-DD) =’2019-03-20’ order by CR_DATE desc