情景分析:
业务所用sql:
SELECT
slcmp.compartment_id,
slcmp.type,
mrdp.mete_value,
slcmp.mete_ed
FROM
idc_ito.spc_low_cabinet_measure_point slcmp
LEFT JOIN energy.mete_real_data_pujiang mrdp ON slcmp.mete_id = mrdp.mete_id
WHERE
slcmp.compartment_id = '040002050000001123073990'
此时compartment_id 字段为char类型, 按道理来说是加了单引号可以查询出来,此时查询不出来,奇怪的是 把单引号去掉了就可以查询出来了
因为字段过长, 用int类型也不现实, 所以我想着 如何把单引号去掉
使用replace函数,将test中的单引号,替换为空,单引号前面需要单引号作为转义符
update a set text=replace(text,'''','')
sql语句就是:
SELECT
slcmp.compartment_id,
slcmp.type,
mrdp.mete_value,
slcmp.mete_ed
FROM
idc_ito.spc_low_cabinet_measure_point slcmp
LEFT JOIN energy.mete_real_data_pujiang mrdp ON slcmp.mete_id = mrdp.mete_id
WHERE
slcmp.compartment_id = REPLACE ( '040002050000001123073990', '''', '' );