DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: PLS-00103 error using Alter Table command

  1. #1
    Join Date
    Dec 2000
    Posts
    2
    Hello All,

    I am trying to alter table within a for loop in stored procedure and am getting following error.

    OPEN mytbl_cursor;
    FOR i IN 1..v_count LOOP
    FETCH mytbl_cursor INTO n_abbr;
    EXIT WHEN mytbl_cursor%notfound;
    ALTER TABLE cmbc_tmptrips2 ADD(n_abbr varchar2(10));
    dbms_output.put_line(n_abbr);
    END LOOP;
    CLOSE mytbl_cursor;

    The error is

    1 58 9 PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    begin declare end exit for goto if loop mod null pragma raise
    return select update while <an identifier>
    <a double-quoted delimited-identifier> <a bind variable>
    << close current delete fetch lock insert open rollback
    savepoint set sql commit <a single-quoted SQL string>


    Would appreciate any comments.

    Thanks in advance

    Samir

  2. #2
    Join Date
    Aug 2000
    Location
    Ny
    Posts
    105
    You can't use DDL this way, look into EXCEUTE IMMEDIATE.

  3. #3
    Join Date
    Jul 2000
    Posts
    296
    In 8.0 you can use procedure EXEC_DDL_STATEMENT in package DBMS_UTILITY.

    OPEN mytbl_cursor;
    FOR i IN 1..v_count LOOP
    FETCH mytbl_cursor INTO n_abbr;
    EXIT WHEN mytbl_cursor%notfound;
    dbms_utility.exec_ddl_statement('ALTER TABLE cmbc_tmptrips2 ADD('||n_abbr||' varchar2(10))');
    dbms_output.put_line(n_abbr);
    END LOOP;
    CLOSE mytbl_cursor;




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width