how to populate database using procedures

本秂侑毒 提交于 2019-12-02 09:21:55

Unless I'm missing it... COMMIT;
Based on the screenshot you issued, add a / to the end of your body and procedure definitions.

Firstly, the package posted doesn't compile without errors.

You would need to fix the following first:

  1. Terminate FOR LOOP statements with END LOOP
  2. Terminate BEGIN of procedures with END <procedure_name_here>
  3. PL/SQL variable names need to be different than the actual column name to avoid ambiguity in the INSERT statement. [ You can't have LOCATION the column name and PL/SQL variable with the same name. Oracle cannot resolve which is to be used where in the INSERT]

To get you started, I have fixed the fill_location procedure below. Proceed similarly for the other procedure.

create or replace package body apartment as
procedure fill_location(location_number number) is
p_location_name varchar2(20);
p_postcode number(10,2);
begin 
    for num in 1.. location_number loop
        p_location_name := 'location';
        p_postcode := dbms_random.value(1000,9600);
        p_location_name := p_location_name ||' '|| to_char(num);
        insert into location (id_location, location_name, postcode)
            values (num, p_location_name, p_postcode);
        dbms_output.put_line(num);
    end loop;
end fill_location;

Fix the above errors/suggestions until you get 'PL/SQL successfully compiled`. If you get 'compiled with errors' use "show errors" to find and fix any other errors.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!