Eu tenho um arquivo de dados (veja o exemplo de três linhas abaixo), separado por tubos.
O que eu quero fazer é "cortar" os campos e colocá-los em variáveis. Eles são de comprimentos pré-definidos. Eu quero transformar o arquivo em um script SQL como por:
Entrada:
| 416|CAWNBORE LIMITED |CAWNBORE | 8| 0| 0|00.00 | 0| 0|********NO ADDRESS DETAILS******* |********NO ADDRESS DETAILS******* |********NO ADDRESS DETAILS******* |********NO ADDRESS DETAILS******* | 0| 0| 0| 0| 0|
| 431|MAIN HOLDINGS LIMITED |MAINHOLDINGSCHA | 8| 0| 0|00.00 | 0| 0|********NO ADDRESS DETAILS******* |********NO ADDRESS DETAILS******* |********NO ADDRESS DETAILS******* |********NO ADDRESS DETAILS******* | 0| 19650509| 0| 0| 0|
| 432|DUBLIN NORTH CITY MILLING COMPANY LIMITED |DUBLINNORTHCITY | 8| 0| 1|00.00 | 18750125| 19830124|113 PHIBSBORO ROAD |DUBLIN | | | 216410| 19901106| 0| 20030124| 0|
Basicamente, retire os canais - separe os dados com vírgulas e insira a string SQL INSERT INTO .... VALUES (data_in_here separada por vírgula);
Saída desejada:
INSERT INTO tbcrocompany (id_company, nm_company, id_keyword, cd_status, dt_company_status, cd_type, cd_principle_obj, dt_register, dt_last_ar, ad_line_1, ad_line_2, ad_line_3, ad_line_4, cd_town_number, dt_dissolved, dt_bond_expiry, dt_next_ar, dt_last_accounts) VALUES (416,'CAWNBORE LI|MITED','CAWNBORE',8,0,0, '00.00', 0, 0, '********NO ADDRESS DETAILS*******', '********NO ADDRESS DETAILS*******', '********NO ADDRESS DETAILS*******', '********NO ADDRESS DETAILS*******', 0, 0, 0, 0, 0);
INSERT INTO tbcrocompany (id_company, nm_company, id_keyword, cd_status, dt_company_status, cd_type, cd_principle_obj, dt_register, dt_last_ar, ad_line_1, ad_line_2, ad_line_3, ad_line_4, cd_town_number, dt_dissolved, dt_bond_expiry, dt_next_ar, dt_last_accounts) VALUES (431,'MAIN HOLDIN|GS LIMITED','MAINHOLDINGSCHA',8,0,0, '00.00', 0, 0, '********NO ADDRESS DETAILS*******', '********NO ADDRESS DETAILS*******', '********NO ADDRESS DETAILS*******', '********NO ADDRESS DETAILS*******', 0, 19650509, 0, 0, 0);
INSERT INTO tbcrocompany (id_company, nm_company, id_keyword, cd_status, dt_company_status, cd_type, cd_principle_obj, dt_register, dt_last_ar, ad_line_1, ad_line_2, ad_line_3, ad_line_4, cd_town_number, dt_dissolved, dt_bond_expiry, dt_next_ar, dt_last_accounts) VALUES (432,'DUBLIN NORTH CITY MILLING COMPANY LIMITED','DUBLINNORTHCITY',8,0,1, '00.00', 18750125, 19830124, '113 PHIBSBORO ROAD', 'DUBLIN', '', '', 216410, 19901106, 0, 20030124, 0);