1.报错Oracle语句如下
SELECT YK_CKGY.ID,YK_CKGY.DJH,YK_CKGY.BLRQ,YK_CKGY.ZBRQ,YK_CKGY.SHRQ,YK_CKGY.YT,YK_CKGY.ZDR,YK_CKGY.SHR,YK_CKGY.BZ,YK_CKGY.JZRQ,YK_CKGY.ZT,YK_CKGY.CKLX,(case YK_CKGY.CKLXwhen '09' then'药房调借'when '02' then'科室退药'when '03' then'损耗出库'when '04' then'科室领药'when '06' then'药房退药'when '07' then'药房领药'when '88' then'领药计划'when '08' then'过期出库'when '10' then'其它出库'end) AS LXMC,YK_CKGY.BMNBBH,(select CO_QX_XTBM.BMMCfrom CO_QX_XTBMwhere YK_CKGY.BMNBBH = CO_QX_XTBM.BMNBBH) as DCBMMC,(select CO_QX_XTBM.BMMCfrom CO_QX_XTBMwhere YK_CKGY.DRBM = CO_QX_XTBM.BMNBBH) as DRBMMC,YK_CKGY.DRBM,(select sum(yk_ckmx.cksl * YK_CKMX.CBJ)from yk_ckmxwhere gyid = YK_CKGY.id) as jhjeFROM YK_CKGYWHERE 1 = 1and substr(YK_CKGY.BLRQ, 1, 10) >= '2024/12/07'and substr(YK_CKGY.BLRQ, 1, 10) <= '2025/01/07'and YK_CKGY.JZRQ is nulland (YK_CKGY.DRBM = 2202)and YK_CKGY.ZT = 2 andYK_CKGY.jgdm = '22'and YK_CKGY.CKLX IN ("04", "07", "03", "02", "06", "10")
2.报错原因:
Oracle 数据库中,双引号用于引用列名、表名等标识符(区分大小写)。但是,在 SQL 中,数字或字符串应该使用单引号。因此,
IN ("04", "07", "03", "02", "06", "10")
中的双引号应该替换为单引号。
3:修正:
IN ('04', '07', '03', '02', '06', '10')
4.其他潜在问题:
substr(YK_CKGY.BLRQ, 1, 10)
用于截取日期的前 10 位,如果BLRQ
是日期字段,可以考虑直接使用TO_DATE
函数来进行日期比较,避免使用substr
来处理日期字段。
SELECT YK_CKGY.ID,YK_CKGY.DJH,YK_CKGY.BLRQ,YK_CKGY.ZBRQ,YK_CKGY.SHRQ,YK_CKGY.YT,YK_CKGY.ZDR,YK_CKGY.SHR,YK_CKGY.BZ,YK_CKGY.JZRQ,YK_CKGY.ZT,YK_CKGY.CKLX,(case YK_CKGY.CKLXwhen '09' then'药房调借'when '02' then'科室退药'when '03' then'损耗出库'when '04' then'科室领药'when '06' then'药房退药'when '07' then'药房领药'when '88' then'领药计划'when '08' then'过期出库'when '10' then'其它出库'end) AS LXMC,YK_CKGY.BMNBBH,(select CO_QX_XTBM.BMMCfrom CO_QX_XTBMwhere YK_CKGY.BMNBBH = CO_QX_XTBM.BMNBBH) as DCBMMC,(select CO_QX_XTBM.BMMCfrom CO_QX_XTBMwhere YK_CKGY.DRBM = CO_QX_XTBM.BMNBBH) as DRBMMC,YK_CKGY.DRBM,(select sum(yk_ckmx.cksl * YK_CKMX.CBJ)from yk_ckmxwhere gyid = YK_CKGY.id) as jhjeFROM YK_CKGYWHERE 1 = 1and substr(YK_CKGY.BLRQ, 1, 10) >= '2024/12/07'and TO_DATE(substr(YK_CKGY.BLRQ, 1, 10), 'YYYY/MM/DD') <=TO_DATE('2025/01/07', 'YYYY/MM/DD')and YK_CKGY.JZRQ is nulland (YK_CKGY.DRBM = 2202)and YK_CKGY.ZT = 2and YK_CKGY.jgdm = '22'and YK_CKGY.CKLX IN ('04', '07', '03', '02', '06', '10')
5.总结
- 使用单引号来定义字符串值,例如
IN ('04', '07', '03', '02', '06', '10')
。- 如果
BLRQ
字段是日期类型,考虑直接使用TO_DATE
进行日期比较,而不使用substr
来截取字符串。
补充:
在 Vue 组件中使用正则替换双引号:
使用 replace()
替换双引号为单引号:
let str = '("04", "07", "03", "02", "06", "10")';
str = str.replace(/"([^"]+)"/g, "'$1'");
解释:
-
正则表达式
/\"([^\"]+)\"/g
:\"
匹配双引号。([^\"]+)
匹配双引号内的内容,并捕获它。$1
表示替换成捕获的内容。g
标志表示全局匹配,即替换字符串中的所有双引号。
-
replace()
方法:- 将匹配到的内容替换为单引号包裹的内容。