Problem with alter table in execute immediate
We have PL/SQL scripts which modify the data structure, add data etc to en existing database. These scripts basically ensure that the db is compatible with what the software expects.
The reason for doing it in PL/SQL rather than SQL script is A) The scripts are launched using GUI so that they are more user friendly. sqlplus is launched as a background process which executes these scripts. All the scripts have EXIT FAILURE WHENEVER SQLERROR as first line to ensure that the control does not hang in the sqlplus background process.
Going from one version to other, we have added a few tables to the database and also modified a few tables. since (i think) DDL is not allowed in PL/SQL block, we had to resort to putting them in EXECUTE IMMEDIATE enclosures.
Now for the real question,
If I create a table using EXECUTE IMMEDIATE clause, I can immediately have insert as a next statement to insert data in this table. but, if I alter the table and add a column to the existing table, I cannot immediately add data to that column, it throws an error saying 'invalid identifier'
At code level, the following is allowed :
EXECUTE IMMEDIATE 'CREATE TABLE SP_TEST_TABLE
ID NUMBER,
NAME Varchar2(40)
INSERT INTO SP_TEST_TABLE(ID, NAME) Values(1, 'SP');
but I get error for the following :
EXECUTE IMMEDIATE 'ALTER TABLE SP_TEST_TWO ADD
ANOTHER_COLUMN number
UPDATE SP_TEST_TWO SET ANOTHER_COLUMN = 1;
In this case, it says ANOTHER_COLUMN invalid identifier
Does anybody know why?
any workaround will be greatly appreciated.
--SP
Friends,
Thanks to all of you for your help. The spelling mistakes might have occurred becuase i changed the actual script to something 'short and complete' to show the problem.
I could solve the problem by having more than one PL/SQL block within my file. something like :
BEGIN
--alter table statements here
END;
BEGIN
--insert the values in column here.
END;
I am still not sure why the error is presented only on alter table statement and not for create table statement. Probably somebody with the knowledge of oracle internals will be able to throw more light on it. I am trying to get the naswers, if I get the answer, I'll surely post it here.
Regards,
--Saurabh
Similar Messages
-
Problem with truncate table in procedure ora -00054
hi do anybody know where is mistake ???
the procedure has problem with truncate table
ora - 00054: resource busy and acquire with NOWAIT specified
ora - 06512 at "POVAPSYS.HMAN_P_REFRESH", line 6
ora - 06512 at "POVAPSYS.POVAPSYS", line 6
ora - 06512 at line 1
this is my procedure....
AS
BEGIN
execute immediate 'TRUNCATE TABLE hman_t_max';
INSERT INTO hman_t_max SELECT * FROM hman_v_max;
COMMIT;
END;2.MAKE SURE THAT OTHER THAN YOU ANYBODY IS TRYING TO
COMPILE AND RUN THE PROCEDUREShould he make sure that anybody is running the procedure?
3.MAKE SURE THAT ANY PARALLEL QUERY IS RUNNING IN THE
SERVER SIDE,THATS KEEPS THE RESOURCE BUSYShould he make sure any parallel query is running in the server side to keep the resource busy?
Gita,
I COULDN'T RESIST HAVING ONE SUGGESTION FOR YOU. Please look at the impact of your English in the reply before posting. Check if that sends reverse message!
Cheers
Sarma. -
Selecting data from a table using Execute Immediate in 9i
Hi,
I was wondering how I would be able to do a SELECT on a table using EXECUTE IMMEDIATE. When I tried it (with the proc below), I got the following below. Can anyone tell me what I am doing wrong?
Using Scott/Tiger I tried this:
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE PROCEDURE P2
2 IS
3 v_SQL VARCHAR2(100);
4 BEGIN
5 v_SQL := 'Select * from Emp';
6 EXECUTE IMMEDIATE v_SQL;
7* END;
SQL> /
Procedure created.
SQL> exec p2
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> exec p2
PL/SQL procedure successfully completed.
SQL>
Thanks in advance.
Sincerely,
Nikhil Kulkarni1 CREATE OR REPLACE PROCEDURE P2
2 IS
3 v_SQL VARCHAR2(100);
erec emp%rowtype;
4 BEGIN
5 v_SQL := 'Select * from Emp';
6 EXECUTE IMMEDIATE v_SQL into erec;
7* END;
SQL> / -
CREATE TEMPORARY TABLE USING EXECUTE IMMEDIATE
Hi All,
i have a question,
how can i create a temporary table using EXECUTE IMMEDIATE ??
Like:
CREATE GLOBAL TEMPORARY table new_table as (Select * from old_table);
Thanks,
Edited by: xDeviates on Jun 11, 2012 3:13 PMIt looks like you are approaching the problem incorrectly. As I suggested in Dynamic Select, it sounds like you, at most, want a function that returns a SYS_REFCURSOR (it's still not obvious to me why you would even want/ need to resort to dynamic SQL in the first place)
CREATE OR REPLACE FUNCTION get_dynamic_cursor( p_table_name IN VARCHAR2 )
RETURN sys_refcursor
IS
l_rc sys_refcursor;
BEGIN
OPEN l_rc FOR 'SELECT * FROM ' || dbms_assert.sql_object_name( p_table_name );
RETURN l_rc;
END;which you can then call from your application
SQL> variable rc refcursor;
SQL> exec :rc := get_dynamic_cursor( 'EMP' );
PL/SQL procedure successfully completed.
SQL> print rc
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 801
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1601 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1251 500
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7566 JONES MANAGER 7839 02-APR-81 2976
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1251 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2851
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7782 CLARK MANAGER 7839 09-JUN-81 2451
10
7788 SCOTT ANALYST 7566 19-APR-87 3001
20
7839 KING PRESIDENT 17-NOV-81 5001
10
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7844 TURNER SALESMAN 7698 08-SEP-81 1501 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1101
20
7900 JAMES CLERK 7698 03-DEC-81 951
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7902 FORD ANALYST 7566 03-DEC-81 3001
20
7934 MILLER CLERK 7782 23-JAN-82 1301
10
14 rows selected.Justin -
Problems with a table in PDF`S footer
Dear sirs,
We are having problems when trying to run a PDF with Adobe LiveCycle Designer tool.
We are working with a PDF which is composed of a header, the main body and a footer. We have created a table (table1) at the footer and
another one at the main body (table2). This last table (table2) may overflow therefore it will genarate two pages for our PDF.
On both pages appear the header and the footer correctly but in the last page it does not write the data from the table included in the footer (table1).
We have no problems with the table included in the main body
In the attachments, I send you the screenshots of both pages in which I have marked in red the part where we have error.
May you help us to solve our problem?
Thanks in advance your help.
Edited by: emgaitan on Mar 16, 2010 2:18 PMWardell,
Check the data in RSA3 for the extractor that you use to bring data .
You must be using the data source 0CO_OM_CCA_09. Check the data and reconcile and you will get it.
Let me know if you need anything else.
Thanks
Ravi Thothadri
[email protected] -
I am getting problem with internal table & work area declaration.
I am working with 'makt' table ..with the table makt i need to work with styles attributes ..so i declared like this
TYPES : BEGIN OF ty_makt,
matnr TYPE makt-matnr,
spras TYPE makt-spras,
maktx TYPE makt-maktx,
maktg TYPE makt-maktg,
celltab TYPE lvc_t_styl,
END OF ty_makt.
DATA : i_makt TYPE TABLE OF ty_makt.
DATA : wa_makt TYPE ty_makt .
But end of program i need to update dbtable "makt"...i am getting problem with internal table & work area declaration.
i think makt table fields mapping and internal table/work area mapping is not correct. so please help me to get out from this.Hi Nagasankar,
TYPES : BEGIN OF TY_MATNR,
MATNR TYPE MAKT-MATNR,
SPRAS TYPE MAKT-SPRAS,
MAKTX TYPE MAKT-MAKTX,
MAKTX TYPE MAKT-MAKTG,
CELLTAB TYPE LVC_T_STYL, " Its Working perfectly fine..
END OF TY_MAKT.
DATA: IT_MAKT TYPE STANDARD TABLE OF TY_MAKT,
WA_MAKT TYPE TY_MAKT.
Its working perfectly fine. if still you are facing any issue post your complete code.
Thanks,
Sandeep -
Hi gurus,
I´ve a problem with a table control. It has 3 columns which one is a checkbox.
I can fill all fields but in the moment I mark the checkbox this line must be unwritable. How can I do it?
Thanks for all
DaniAssign a function code to the checkbox column....
so when u check / uncheck any entry, PAI + PBO will be triggered....
In the PBO during the loop of table control, check the checkbox field value. if it is 'X', make the row readonly
by looping at screen and setting screen-input = 0 for rest of the columns.
like ...
LOOP AT tc_itab
WITH CONTROL tc_test
CURSOR tc_test-current_line.
module set_row_readonly. " loop at screen and set input = '0' if checkbox is checked...
ENDLOOP. -
Create temp table using EXECUTE IMMEDIATE
Is there any performance issue in creating globally temp table
using EXECUTE IMMEDIATE or creating globally temp table from
SQL PLUS.
Any response will be greatly appreciated.
nullAnish,
Creating tables is likely to be an expensive operation.
Performance issues can only be considered in comparison to
alternatives.
Alternatives include: PLSQL tables, cursors and/or recoding so
that tmp tables are not required. (One of our consultants reckons
that sqlserver temp tables are usually used to get around
limitations in sqlserver, ie slightly more complicated sql
statements could be used instead of simpler sql and temporary
tables).
I would think creating the temp table once during sqlplus would
be cheaper than creating and deleting it repeatedly at run time.
Note that EXECUTE IMMEDIATE may do an implicit commit (dbms_sql
certainly does). This may be got over my using the PRAGMA
AUTONOMOUS_TRANSACTION; direction which places a
procedure/function in a seperate transaction.
Turloch
P.S. We have some difficulty in getting information back from the
field/customer sites. If you have questions and answers that are
likely to be useful to other Oracle Migration Workbench
users, and migrators in general, please send them in for possible
inclusion in our Frequently Asked Question list.
Oracle Migration Workbench Team
Anish (guest) wrote:
: Is there any performance issue in creating globally temp table
: using EXECUTE IMMEDIATE or creating globally temp table from
: SQL PLUS.
: Any response will be greatly appreciated.
Oracle Technology Network
http://technet.oracle.com
null -
Problem with maintain table views SM30 Transaction
Hello All,
i have a problem with the table maintenance view SM30, it doesn't permit me to modify the rows in the table.
we have added a field into the table and when i tried to change the table view from menu: Utilities ==> table maintenance generator==> change the system propose me a message that the screen 0001 will be deleted and recreated...but the system has deleted the screen and doesn't recreate it...in somewehere on internet we find that we should use the transaction SE55 menu:
Environment==> modification ==> Maintenance screen ==> button Layout which open the tool Screen Painter and from that we have created our screen with 4 fields of our table...our result that the screen is created and i can see it from the SM30 transaction but i can't insert rows in the table...when i try to go to maintain table: menu: Utilities ==> Table maintenance generator to try if i can modify something the system give me a message: "set the compare flag dialog ZIV_DP_PLCHAR_LA"
the ZIV_DP_PLCHAR_LA is the name of my table...
can you give me some advices please how should i do to fix this problem to insert rows in table throughout the transaction
SM30 "maintain table views: initial screen"
if i want to delete the screen from the SE55 transaction to recreate it newly what should i do to take care about some options
to have a new screen?
thanks for all
BilalHi
First delete the old table maintainence generator.
Now Recreate the screen and your table is good to go..
These error messages come when we add new fields and different version of the table maintainence generator in database. -
Problem with Pivot Table with Graph: Line Bar Combo
Hello people!
I have a problem with pivot table and line bar combo (all in the same view (pivot table))
I have some measures and one dimension in my report.
--------------measure1---measure2---measure3
Dim A.1
Dim A.2
Dim A.3
If I choose my graph line bar combo automatically choose "line" measure 3 (last measure in "Show Controls"). How can I do if I want my measure1 for line and I don't want modify my pivot table?
Thank you very much!Ok, I'll explain my problem again. In my pivot table I add graph vision and I want in the same view (Pivot table). My graph is "Line Bar Combo" and I don't know how but the last of my measures belongs to right AXIS, if I change order of my measures I can see in my graph the measure that I want in my right axis BUT also it changes the order of my pivot table.
This is my problem. I think that I can do that with different views but I lose my selector view to view graphic and my pivot table at the same time. -
Problems with partition tables
Hi all,
I've got some problems with partition tables. The script at the bottom run but when I wanna insert some values it returns me an error
(ORA-06550: line 1, column 30: PL/SQL: ORA-06552: PL/SQL: Compilation unit analysis terminated
ORA-06553: PLS-320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored)
and I can't understand why!
There's something incorrect in the script or not?
Please help me
Thanks in advance
Steve
CREATE TABLE TW_E_CUSTOMER_UNIFIED
ID_CUSTOMER_UNIFIED VARCHAR2 (27) NOT NULL ,
START_VALIDITY_DATE DATE NOT NULL ,
END_VALIDITY_DATE DATE ,
CUSTOMER_STATUS VARCHAR2 (255)
PARTITION BY RANGE (START_VALIDITY_DATE)
SUBPARTITION BY LIST (END_VALIDITY_DATE)
PARTITION M200909 VALUES LESS THAN (TO_DATE('20091001','YYYYMMDD'))
(SUBPARTITION M200909_N VALUES (NULL), SUBPARTITION M200909_NN VALUES (DEFAULT)),
PARTITION M200910 VALUES LESS THAN (TO_DATE('20091101','YYYYMMDD'))
(SUBPARTITION M200910_N VALUES (NULL), SUBPARTITION M200910_NN VALUES (DEFAULT)),
PARTITION M200911 VALUES LESS THAN (TO_DATE('20091201','YYYYMMDD'))
(SUBPARTITION M200911_N VALUES (NULL), SUBPARTITION M200911_NN VALUES (DEFAULT)),
PARTITION M200912 VALUES LESS THAN (TO_DATE('20100101','YYYYMMDD'))
(SUBPARTITION M200912_N VALUES (NULL), SUBPARTITION M200912_NN VALUES (DEFAULT)),
PARTITION M201001 VALUES LESS THAN (TO_DATE('20100201','YYYYMMDD'))
(SUBPARTITION M201001_N VALUES (NULL), SUBPARTITION M201001_NN VALUES (DEFAULT)),
PARTITION M201002 VALUES LESS THAN (TO_DATE('20100301','YYYYMMDD'))
(SUBPARTITION M201002_N VALUES (NULL), SUBPARTITION M201002_NN VALUES (DEFAULT)),
PARTITION M210001 VALUES LESS THAN (MAXVALUE))
(SUBPARTITION M210001_N VALUES (NULL), SUBPARTITION M210001_NN VALUES (DEFAULT))
;Hi Hoek,
the DB version is 10.2 (italian version, then SET is correct).
...there's something strange: now I can INSERT rows but I can't update them!
I'm using this command string:
UPDATE TW_E_CUSTOMER_UNIFIED SET END_VALIDITY_DATE = TO_DATE('09-SET-09', 'DD-MON-RR') WHERE
id_customer_unified = '123' and start_validity_date = TO_DATE('09-SET-09', 'DD-MON-RR');
And this is the error:
Error SQL: ORA-14402: updating partition key column would cause a partition change
14402. 00000 - "updating partition key column would cause a partition change"
*Cause: An UPDATE statement attempted to change the value of a partition
key column causing migration of the row to another partition
*Action: Do not attempt to update a partition key column or make sure that
the new partition key is within the range containing the old
partition key.
I think that is impossible to use a PARTITION/SUBPARTITION like that: in fact the update of "END_VALIDITY_DATE" cause a partition change.
Do u agree or it's possible an update on a field that implies a partition change?
Regards Steve -
Problem with the table control BDC in FV60 transaction
Hi All,
I got the problem with the table control in FV60 transaction.
This is working for 900 line items.After 900 line items it is giving the problem like it is 1000th line item.You can post only 999 line items.
I know we can post only 999 line items,but in my file only 920 line items.
Please give me solution,if anybody come across this situation.
Thanks & regards,
rakesh.Hello Rakesh ,
your file may have only 920 line items , but based on those line items, SAP may create few more new lines ( based on the clearing recon accounts , inter company transaction ...etc )...
regards
Prabhu -
Problem with temporary table refresh
Hi,
I running a process before validation on a page to populate a temporary table when I click a button.
On the following page I've built a shuttle on the temporary table. Not the most elegant solution, but the shuttle LOV box wouldn't process the oracle text commands in the SQL.
I'm not getting any error, but I have an unusual problem
It takes two passes for the data to be replaced. i.e I enter 'ABCD' in the filter and it returns data with 'ABCD'
If I return to the page and change the filter to 'EFGH' I still get 'ABCD'. I return to the page and click the button again and I get 'EFGH' results
I've checked the data in the temporay table and that is updating in line with the problem.
I've looked at the debug and that seems fine (i.e I can see the changed filter value), I've tried moving the truncate to a different process, that didn't help.
I've run it in SQL developer and it seems to work fine.
I've included the code below, but I can't see a problem with it.
Can anybody help?
begin
EXECUTE IMMEDIATE('TRUNCATE TABLE temp_cat');
commit;
if length(:P26_ADD_FILTER) > 0 then
insert into temp_cat (core_cat_id, core_cat_code, core_cat_desc)
select core_cat_id,core_cat_code,core_cat_desc from core_cat where CONTAINS (core_cat_desc, '
<query>
<textquery lang="ENGLISH" grammar="CONTEXT">&P26_ADD_FILTER.
<progression>
<seq><rewrite>transform((TOKENS, "{", "}", " "))</rewrite></seq>
<seq><rewrite>transform((TOKENS, "{", "}", " ; "))</rewrite></seq>
<seq><rewrite>transform((TOKENS, "{", "}", "AND"))</rewrite></seq>
<seq><rewrite>transform((TOKENS, "{", "}", "ACCUM"))</rewrite></seq>
</progression>
</textquery>
<score datatype="INTEGER" algorithm="COUNT"/>
</query>')>0 and core_cat_id not in (select pipe_project_cat.core_cat_id from pipe_project_cat where txtpamref = :p26_pamref);
else
insert into temp_cat (core_cat_id, core_cat_code, core_cat_desc)
select core_cat_id,core_cat_code,core_cat_desc from core_cat where
core_cat_id not in (select pipe_project_cat.core_cat_id from pipe_project_cat where txtpamref = :p26_pamref);
end if;
end;Hi,
Apex does not work well with temporary tables as you cannot guarantee which session from the pool will be used to serve each page.
In your case, it looks like the second page is using temporary data from the wrong session.
Have you considered using Apex Collections instead?
Luis -
Deadlocks with ALTER TABLE DISABLE CONSTRAINT
Hello,
We're deleting millions of redundant rows from a particular table in our live 10g database. This is being done online because the downtime would be unacceptable. The table in question has 30 child tables, so for speed I am disabling the foreign keys using ALTER TABLE DISABLE CONSTRAINT before the deletion (we haven't had any constraint violations for ages). Without this, deletion takes about 1 second per row i.e. a very long time.
However, we're finding that ALTER TABLE DISABLE CONSTRAINT often reports ORA-00060: deadlock detected. This is causing problems with the live system. Can anyone think of the reason why a deadlock might occur in this situation and what we could do to prevent it happening? Note that any solution has to be doable without downtime unless it takes less than 30 minutes.
Thanks a lot
Ed
Edited by: edwiles on Feb 4, 2009 6:02 AMlook suggestions in the similar thread:
Re: Deadlock when deleting a not linked data record in a parent table -
Oracle 11G Copying a table using execute immediate
I want to copy the contents of one table into another using execute immediate.
This keeps failing with the following error
ORA-00903: invalid table name
ORA-06512: at "TABLE_COPY", line 6
ORA-06512: at line 8
create or replace
procedure TABLE_COPY(
TABLE1 varchar2,
TABLE2 varchar2)
is
begin
execute immediate 'insert into '||TABLE2||' (select * from '||TABLE1||')';
end;
Edited by: user9213000 on 24-Jan-2013 07:38user9213000 wrote:
I want to copy the contents of one table into another using execute immediate.
This keeps failing with the following error
ORA-00903: invalid table name
ORA-06512: at "TABLE_COPY", line 6
ORA-06512: at line 8
create or replace
procedure TABLE_COPY(
TABLE1 varchar2,
TABLE2 varchar2)
is
begin
execute immediate 'insert into '||TABLE2||' (select * from '||TABLE1||')';
end;
Edited by: user9213000 on 24-Jan-2013 07:38The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
Then print the variable before passing it to EXECUTE IMMEDIATE.
COPY the statement & PASTE into sqlplus to validate its correctness.
Maybe you are looking for
-
How to get Item-Code wise stock quantity and value for a previous date
Dear Sir, As per the government legal requirement , we are required to furnish a list for items having stock as on a date ( date is not the current date but it is some past date) and in the list we need to provide material wise stock quantity and v
-
Error message Pendrell64/shared/adobemediacore/medialayer/videofilterhost/make/mac/.../.../src/aeplugin videofiltermodule.cpp-108 Also: Process: Adobe Premiere Pro CS5 [191] Path: /Applications/Adobe Premiere Pro CS5/Adobe Premiere
-
Writing scripts to edit or parse txt file How To?
Not sure if this is the correct forum for programming type question. If not someone point me in the right direction? I'm a programming student and I'd like to teach myself some scripting skills over the summer break. In particular, I've got a txt fil
-
Approval Process in SSHR using Approval Management
Could any one suggest for the below mentioned issue ? I have set up the approval process using approval management. But when I tried to test the approval process in both the ways ('Create a test transaction' and 'View a real transaction's approval pr
-
Using iDVD 3.0.1 -- can't get a MPEG4 tune to burn w/slideshow
Hey there -- I'm fairly new to using iPhoto & iDVD so I don't really want to spedn money on upgrading it yet! I have played with these programs and successfully made some nice DVD slideshows with audio. I'll try to make my points brief, and appreciat