pl / sql - ORA-01702 - неверный номер - PullRequest
0 голосов
/ 09 марта 2012

У меня есть целевая схема адрес , где plz - число и схема источника, где plz - varchar2.

Следующий код выдает ORA-01722 - ошибка неверного номера, но я не могу определить, почему.Есть около 30 PLZ, как «26189» или «38108» и 5 пустых значений.

create or replace
procedure f1_get_adresses is
  cursor c_adresse is 
   select id, strasse, hausnummer, to_number(to_nchar(postleitzahl)) 
   as postleitzahl, ort, land
   from db2_lsg2.f1_adresse;
  rec c_adresse%rowtype;
  counter number(10);
  val_plz number(10);
begin
  for rec in c_adresse
  loop

    -- PLZ
    select count(*) into counter from postleitzahl 
      where plz = rec.postleitzahl and ort = rec.ort;
    if counter = 0 then
      if rec.postleitzahl is null then
        val_plz := 0;
      else
        val_plz := rec.postleitzahl;
      end if;
      insert into postleitzahl (plz, ort) values (rec.ort, val_plz);
    end if;

    -- Land
    select count(*) into counter from land
      where land_name = rec.land;
    if counter = 0 then
      insert into land (land_name) values (rec.land);
    end if;

    --Adresse
    select count(*) into counter from adresse
      where strasse = rec.strasse
        and hausnummer = rec.hausnummer
        and plz = rec.postleitzahl
        and (select land_name from land where land_name = rec.land) = rec.land;
    if counter = 0 then
      insert into adresse (strasse, hausnummer, plz, land_id)
      values (
        rec.strasse,
        rec.hausnummer,
        rec.postleitzahl,
        (select land_id from land where land_name = rec.land)
      );
    end if;
  end loop;
end;

1 Ответ

3 голосов
/ 09 марта 2012

Не так много деталей, которые вы нам дали, поэтому давайте догадаемся .. Какого типа rec.ort?

insert into postleitzahl (plz, ort) values (rec.ort, val_plz); 

, если это не так (другой порядок)

insert into postleitzahl (plz, ort) values (val_plz, rec.ort);  ?
...