oracle-databasesqlfiddle

SQL Fiddle - ORACLE 11G and Stored procedure


I wanted to ask about another problem and another one came out;)

I wanted to use SQL Fiddle for example, but it doesn't work for me to create a table and a procedure that generates random data...

Why this example not work (build schema not work)?

http://sqlfiddle.com/#!4/6915f/2

create table tab (
     id_tab integer not null,
     val1 integer,
     val2 integer,
     val3 integer,
     val4 integer,
     val5 integer,
     val6 integer,
     val7 integer,
     val8 integer,
     val9 integer,
     CONSTRAINT tab_pk PRIMARY KEY (id_tab)
  );
  
  create index val1_index on tab (val1);
  create index val2_index on tab (val2);
  create index val3_index on tab (val3);
  create index val4_index on tab (val4);
  create index val5_index on tab (val5);
  create index val6_index on tab (val6);
  create index val7_index on tab (val7);
  create index val8_index on tab (val8);
  create index val9_index on tab (val9);
  
  create procedure test1 as
  begin
    for x in 1..1000
    loop
      insert into tab(id_tab, val1, val2, val3, val4, val5, val6, val7, val8, val9)
      values ((select nvl(max(id_tab), 0) + 1 from tab), 
              dbms_random.value(1,9), 
              dbms_random.value(1,9), 
              dbms_random.value(1,9), 
              dbms_random.value(1,9), 
              dbms_random.value(1,9), 
              dbms_random.value(1,9),
              dbms_random.value(1,9), 
              dbms_random.value(1,9), 
              dbms_random.value(1,9));
    end loop;
  end;

result:

ORA-00900: invalid SQL statement

Solution

  • The procedure has to be ended with a slash; so you need to add that, and change the build-schema command separator from the default ; to / - and then change all of the other separators in your code from semicolons to slashes:

    create table tab (
         id_tab integer not null,
         val1 integer,
         val2 integer,
         val3 integer,
         val4 integer,
         val5 integer,
         val6 integer,
         val7 integer,
         val8 integer,
         val9 integer,
         CONSTRAINT tab_pk PRIMARY KEY (id_tab)
    )
    /
      
    create index val1_index on tab (val1)
    /
    create index val2_index on tab (val2)
    /
    create index val3_index on tab (val3)
    /
    create index val4_index on tab (val4)
    /
    create index val5_index on tab (val5)
    /
    create index val6_index on tab (val6)
    /
    create index val7_index on tab (val7)
    /
    create index val8_index on tab (val8)
    /  
    create index val9_index on tab (val9)
    /
      
    create procedure test1 as
    begin
      for x in 1..1000
      loop
        insert into tab(id_tab, val1, val2, val3, val4, val5, val6, val7, val8, val9)
        values ((select nvl(max(id_tab), 0) + 1 from tab), 
                dbms_random.value(1,9), 
                dbms_random.value(1,9), 
                dbms_random.value(1,9), 
                dbms_random.value(1,9), 
                dbms_random.value(1,9), 
                dbms_random.value(1,9),
                dbms_random.value(1,9), 
                dbms_random.value(1,9), 
                dbms_random.value(1,9));
      end loop;
    end;
    /
    

    As you need an anonymous block to call the procedure, you need to do the same thing - including changing the default separator - in the other section too:

    begin
      test1;
    end;
    /
    
    select * from tab
    /
    

    SQL Fiddle