how to populate database using procedures

前端 未结 2 1264
天涯浪人
天涯浪人 2021-01-25 22:03

I have about 15 different Tables filled with different data and different entity relationships.

I need to create a script which will populate my database with the conten

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-25 22:38

    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
    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.

提交回复
热议问题