问题
How can I query for data having literal chars as colon, semi-colon and some part of text in Oracle?
SELECT result
FROM TABLE1
WHERE result like '"generalinfo"":""Authorize-All-06262019"'
Data:
Result
{"generated":"6/19/2019 12:54:55 PM -05:00","msgid":"SYSTEMID_115064221_2","servicenumber":"115064221","queueid":2,"expected":"7/1/2019 12:00:00 AM -05:00","startrange":"","endrange":"6/24/2019 12:00:00 AM -05:00","startdate":"6/24/2019 12:00:00 AM -05:00","flag":1,"setby":"6/5/2019 12:00:00 AM","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}
{"generated":"6/26/2019 11:32:30 PM -05:00","msgid":"SYSTEMID_115064221_2","servicenumber":"115064221","queueid":2,"expected":"7/8/2019 12:00:00 AM -05:00","startrange":"","endrange":"7/1/2019 12:00:00 AM -05:00","startdate":"7/1/2019 12:00:00 AM -05:00","flag":0,"setby":"","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}
{"generated":"6/25/2019 6:27:10 AM -05:00","msgid":"SYSTEMID_115064221_3","servicenumber":"115064221","queueid":3,"expected":"7/8/2019 12:00:00 AM -05:00","startrange":"","endrange":"6/24/2019 12:00:00 AM -05:00","startdate":"6/24/2019 12:00:00 AM -05:00","flag":1,"setby":"7/1/2019 12:00:00 AM","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}
{"generated":"6/19/2019 12:54:56 PM -05:00","msgid":"SYSTEMID_115047234_2","servicenumber":"115047234","queueid":2,"expected":"7/1/2019 12:00:00 AM -05:00","startrange":"","endrange":"6/24/2019 12:00:00 AM -05:00","startdate":"6/24/2019 12:00:00 AM -05:00","flag":1,"setby":"6/5/2019 12:00:00 AM","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}
{"generated":"6/25/2019 6:27:10 AM -05:00","msgid":"SYSTEMID_115047234_3","servicenumber":"115047234","queueid":3,"expected":"7/8/2019 12:00:00 AM -05:00","startrange":"","endrange":"7/1/2019 12:00:00 AM -05:00","startdate":"7/1/2019 12:00:00 AM -05:00","flag":1,"setby":"7/1/2019 12:00:00 AM","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}S@{"msgid":"115047234_3","servicenumber":"115047234","queueid":"3","flag":0,"location":"11","generated":"6/26/2019 2:49:02 AM -05:00","type":"FDAAuthorize","generalinfo":"Authorize-All-06262019"}
{"generated":"6/19/2019 12:54:56 PM -05:00","msgid":"SYSTEMID_115035858_2","servicenumber":"115035858","queueid":2,"expected":"7/1/2019 12:00:00 AM -05:00","startrange":"","endrange":"6/24/2019 12:00:00 AM -05:00","startdate":"6/24/2019 12:00:00 AM -05:00","flag":1,"setby":"6/5/2019 12:00:00 AM","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}
{"generated":"6/25/2019 6:27:10 AM -05:00","msgid":"SYSTEMID_115035858_3","servicenumber":"115035858","queueid":3,"expected":"7/8/2019 12:00:00 AM -05:00","startrange":"","endrange":"7/1/2019 12:00:00 AM -05:00","startdate":"7/1/2019 12:00:00 AM -05:00","flag":1,"setby":"7/1/2019 12:00:00 AM","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}S@{"msgid":"115035858_3","servicenumber":"115035858","queueid":"3","flag":0,"location":"11","generated":"6/26/2019 1:19:08 AM -05:00","type":"FDAAuthorize","generalinfo":"Authorize-All-06262019"}S@{"msgid":"115035858_3","servicenumber":"115035858","queueid":"3","flag":0,"location":"11","generated":"6/26/2019 1:20:46 AM -05:00","type":"FDAAuthorize","generalinfo":"Authorize-All-06262019"}
{"generated":"6/19/2019 12:54:56 PM -05:00","msgid":"SYSTEMID_115036054_2","servicenumber":"115036054","queueid":2,"expected":"7/1/2019 12:00:00 AM -05:00","startrange":"","endrange":"6/24/2019 12:00:00 AM -05:00","startdate":"6/24/2019 12:00:00 AM -05:00","flag":1,"setby":"6/5/2019 12:00:00 AM","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}
{"generated":"6/25/2019 6:27:10 AM -05:00","msgid":"SYSTEMID_115036054_3","servicenumber":"115036054","queueid":3,"expected":"7/8/2019 12:00:00 AM -05:00","startrange":"","endrange":"7/1/2019 12:00:00 AM -05:00","startdate":"7/1/2019 12:00:00 AM -05:00","flag":1,"setby":"7/1/2019 12:00:00 AM","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}S@{"msgid":"115036054_3","servicenumber":"115036054","queueid":"3","flag":0,"location":"11","generated":"6/26/2019 1:38:55 AM -05:00","type":"FDAAuthorize","generalinfo":"Authorize-All-06262019"}
{"generated":"6/17/2019 7:50:06 AM -05:00","msgid":"SYSTEMID_116456178_2","servicenumber":"116456178","queueid":2,"expected":"6/24/2019 12:00:00 AM -05:00","startrange":"6/22/2019 12:00:00 AM -05:00","endrange":"6/18/2019 12:00:00 AM -05:00","startdate":"6/18/2019 12:00:00 AM -05:00","flag":1,"setby":"6/3/2019 12:00:00 AM","location":"11","consideredby":"ATS","type":"FDA","generalinfo":"NA"}
How to get the rows which has "generalinfo" having value and "NA" instead of only "NA" rows?
回答1:
If your DB version is 12c, then you can easily figure out by adding a check constraint provided your column (result
)'s format conforms with json as:
alter table table1
add constraints chk_result_json
check(result is json);
and check generalinfo is not NA
as :
select *
from table1 t
where t.result.generalinfo != 'NA'
Even easier for 18c version by using with treat(result AS json)
as :
select *
from ( select id, treat(result AS json) as result from table1 ) t
where t.result.generalinfo != 'NA'
Demo
来源:https://stackoverflow.com/questions/56801527/select-query-with-literal-characterscolon-semi-colon-in-oracle