Inserir dados de um arquivo no banco sql server
11/06/2011
0
Olá pessoal este é meu primeiro post, porque estou com um problema de ler um arquivo e inserir suas informações num tabela. Sou iniciante em sql e estou apanhando aqui. Gostaria da ajuda de vocês.
Segue o codigo.
create or replace procedure pr_cliente(linha in varchar2)
as
BEGIN
arquivo_ler:=UTL_File.File_Type;
arquivo_ler:=UTL_File.Fopen('c:\','cliente.txt', 'r');
Loop
UTL_File.Get_Line(arquivo_ler, Linha);
for i in 0..length(linha) loop
if substr(linha,i,1)=';'
then begin
cod_cliente:=substr(linha,0,i);
for x in i..length(linha) Loop
if substr(linha,x,1)=';'
then begin
nome_cliente:=substr(linha,i+1,x);
for y in i..length(linha) loop
if substr(linha,y,1)=';'
then begin
end_cliente:=substr(linha,i+1,y);
for z in i..length(linha) loop
if substr(linha,z,1)=';'
then begin
cod_bairro:=substr(linha,i+1,z);
tel_cliente:=substr(linha,z);
insert into cliente values (cod_cliente, nome_cliente, end_cliente, cod_bairro, tel_cliente);
End Loop;
UTL_File.Fclose(arquivo_ler);
END
/
Segue o codigo.
create or replace procedure pr_cliente(linha in varchar2)
as
BEGIN
arquivo_ler:=UTL_File.File_Type;
arquivo_ler:=UTL_File.Fopen('c:\','cliente.txt', 'r');
Loop
UTL_File.Get_Line(arquivo_ler, Linha);
for i in 0..length(linha) loop
if substr(linha,i,1)=';'
then begin
cod_cliente:=substr(linha,0,i);
for x in i..length(linha) Loop
if substr(linha,x,1)=';'
then begin
nome_cliente:=substr(linha,i+1,x);
for y in i..length(linha) loop
if substr(linha,y,1)=';'
then begin
end_cliente:=substr(linha,i+1,y);
for z in i..length(linha) loop
if substr(linha,z,1)=';'
then begin
cod_bairro:=substr(linha,i+1,z);
tel_cliente:=substr(linha,z);
insert into cliente values (cod_cliente, nome_cliente, end_cliente, cod_bairro, tel_cliente);
End Loop;
UTL_File.Fclose(arquivo_ler);
END
/
Marcelo Marino
Curtir tópico
+ 0
Responder
Posts
10/07/2011
Marco Pinheiro
Marcelo,
Este código está em Oracle, porém vc postou na area de SQL. Vc está rodando onde esta procedure?
Att.,
Marco.
Responder
Clique aqui para fazer login e interagir na Comunidade :)