I have a table(table_clob) which has follwing field
create table table_clob ( file_data CLOB);
above table has only one row . file_data has following data:
"A00",399,"yhnj",20150302,055522,100215
"E51",987456111,147852,10000,"bnncnf","abc","I","XYZ","EA","PO16", Z99,3
"E51",985856111,147852,10000,"wertt","tgb","I","XYZ","EA","PO16","7GZ",29
"E51",456987123,"469555",155000,"reeggdd","edc","D","ABC","EM","GU16","7HF" 52
"E51",456456852,125500,468566,"wsxcde","BUS","I","ABC","SE","MT12","8JG",18
"E51",987456111,147852,10000,"pokmhj","BUS","I","XYZ","EA","PO16","7GZ",
i have insert above data into a table(including column names and types) . i don't want to insert row starting with 'AOO' and 'Z99' ; after inserting into a table .It should have 6 rows and should look like:
"E51",987456111,147852,10000,"bnncnf","abc","I","XYZ","EA","PO16", "E51",985856111,147852,10000,"ABC Power Station","BUS","I","XYZ","EA","PO16","7GZ",29 "E51",985856111,147852,10000,"wertt","tgb","I","XYZ","EA","PO16","7GZ",29
"E51",456987123,"469555",155000,"reeggdd","edc","D","ABC","EM","GU16","7HF",52
"E51",456456852,125500,468566,"wsxcde","yhn","I","ABC","SE","MT12","8JG",18
"E51",987456111,147852,10000,"pokmhj","tgb","I","XYZ","EA","PO16","7GZ",
can anyone help me to get above result
You can use dbms_log.instr packaged function to do this , check the following:
select file_data from table_clob
where dbms_lob.instr(file_data,'AOO')=0
or dbms_lob.instr(file_data,'Z99')=0 ;
This query divides clob into individual lines:
select
substr(file_data, instr(file_data, '"E51"', 1, level),
decode(instr(file_data, '"E51"', 1, level + 1), 0, length(file_data),
instr(file_data, '"E51"', 1, level + 1) - instr(file_data, '"E51"', 1, level)-1)
) data
from table_clob
connect by instr(file_data, '"E51"', 1, level) > 0
Output:
DATA
--------------------------------------------------------------------------------
"E51",987456111,147852,10000,"bnncnf","abc","I","XYZ","EA","PO16", Z99,3
"E51",985856111,147852,10000,"wertt","tgb","I","XYZ","EA","PO16","7GZ",29
"E51",456987123,"469555",155000,"reeggdd","edc","D","ABC","EM","GU16","7HF",52
"E51",456456852,125500,468566,"wsxcde","BUS","I","ABC","SE","MT12","8JG",18
"E51",987456111,147852,10000,"pokmhj","BUS","I","XYZ","EA","PO16","7GZ"
Eliminate unwanted rows for instance where data not like 'Z99'
and insert into table like here:
insert into table_clob (file_data)
select data from
(select
substr(file_data, instr(file_data, '"E51"', 1, level),
decode(instr(file_data, '"E51"', 1, level + 1), 0, length(file_data),
instr(file_data, '"E51"', 1, level + 1) - instr(file_data, '"E51"', 1, level)-1)
) data
from table_clob
connect by instr(file_data, '"E51"', 1, level) > 0)
where data not like 'Z99'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.