plsql - Need help solving Pl/sql issue -
i trying fill database random data, primary key needs still unique. can fill database random data, trying solve primary key issue.
when running code errors.
set serveroutput on create or replace procedure filldatabase(tablein in varchar2, amount in number) columndata varchar2(50); columnnr number(10); str varchar2(500); sqlstatement varchar2(500); l_ran_time timestamp; intlol number(38); prmname varchar2(50); prmtab varchar2(50); prmkey number(10); temp number(30); tempstr varchar2(50); lolnr number(10); strq varchar2(50); begin lolnr := 1; select count(*) columnnr user_tab_columns table_name=tablein; counter in 1..amount loop sqlstatement := 'insert '|| tablein ||' values ('; counter2 in 1..columnnr loop select cols.table_name, cols.column_name prmtab, prmname all_constraints cons, all_cons_columns cols cols.table_name = tablein , cons.constraint_type = 'p' , cons.constraint_name = cols.constraint_name , cons.owner = cols.owner order cols.table_name, cols.position; tempstr := 'select count(*) temp '|| prmtab; dbms_output.put_line('test'); dbms_output.put_line(temp); execute immediate tempstr; if temp = 0 strq := 'select max(' || prmname || ') prmkey '|| prmtab || ' order '|| prmname; dbms_output.put_line(strq); execute immediate strq; end if; select dbms_random.value(0, 20) intlol dual; select dbms_random.string('u', 20) str dual; select sysdate + dbms_random.value(0, sysdate - sysdate+1) l_ran_time dual; select data_type columndata user_tab_columns table_name= tablein , column_id = counter2; dbms_output.put_line(columndata); case when columndata = 'varchar2' sqlstatement := sqlstatement ||''''|| str ||''', '; when columndata = 'number' sqlstatement := sqlstatement || intlol ||', '; when columndata = 'timestamp(6)' sqlstatement := sqlstatement ||''''|| l_ran_time ||''', '; else sqlstatement := sqlstatement || null || ', '; end case; end loop; sqlstatement := substr(sqlstatement, 0, length(sqlstatement) -2); sqlstatement := sqlstatement || ')'; dbms_output.put_line(sqlstatement); execute immediate sqlstatement; end loop; end filldatabase;
can guys me solve this?
use pattern
str := 'select x t where...'; execute immediate str var;
instead of
str := 'select x var t where...'; execute immediate str;
Comments
Post a Comment