0

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

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

4 Comments

I get: the amount or type of arguments in the call || is wrong (translated from german so it might not be the 100% english error message) Error report: ` ORA-06550: line 10, column 29:` ` PLS-00306: Falsche Anzahl oder Typen von Argumenten in Aufruf von '||'` ` ORA-06550: line 10, column 11:` PL/SQL: Statement ignored ` 06550. 00000 - "line %s, column %s:\n%s"` ` *Cause: Usually a PL/SQL compilation error.`
Sorry, I updated it. Note, you can change error messages to English by ALTER SESSION SET NLS_LANGUAGE = 'AMERICAN';
Thanks it is working now. However I get this: Error report: ORA-00955: name is already used by an existing object ORA-06512: at line 10 00955. 00000 - "name is already used by an existing object" *Cause: Why is that so?
After doing the whole thing with a temp table it is working great. THANKS!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.