Question

here is the problem.

I read year numbers from a table and insert them in another one (now static but in the end temp table)

Then I look over those numbers and create tables with them.

BEGIN 
 INSERT INTO temp_year
  ( year_column )
  ( 
    select extract(year from datum) from datetest
  ); 

FOR counter_id IN ( SELECT * FROM temp_year )
LOOP  
      EXECUTE IMMEDIATE 'Create table YEAR_' || counter_id || ' (year int, name char(50))'        
END LOOP; 
END; 
/

Temp_year has a column year_column (int) (filled like 2012) datatest has a date colum with values like 10.02.2012

The result should be a table named YEAR_2012 with columns year int and name char(50)

However this is not working. I quits at the execute immediate part, even when there are years in the temp_year table.

Any ideas??

Thanks in advance.

THeVagabond

Était-ce utile?

La solution

Try this one:

EXECUTE IMMEDIATE 'Create table YEAR_' || counter_id.year_column || ' (year integer, name varchar2(50))';

(Do not miss the semicolon at the end)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top