SAP HANA - How to run alter table statement in HANA procedure?
I am trying to run alter table statement in a procedure. HANA gives error saying
SAP DBTech JDBC: [257] (at 1338): sql syntax error: ALTER TABLE is not allowed in SQLScript: line 36 col 8 (at pos 1338)
How to run alter table statements in procedure?
Thanks,
Suren.
Hi Rich Heilman,
Thanks for your response. I have tried with dynamic SQL. I am trying to add partitions to a non portioned table.
EXECUTE IMMEDIATE 'ALTER TABLE ' || :SCHEMA_NAME || '.TARGET_TABLE PARTITION BY RANGE (TARGET_TYPE_ID) (PARTITION VALUE = 1, PARTITION VALUE = 2, PARTITION VALUE = 3, PARTITION VALUE = 4, PARTITION OTHERS)';
Execution fails with error
Could not execute 'CALL PARTITION_TARGET_TABLE('SUREN_TEST')' in 1.160 seconds .
[129]: transaction rolled back by an internal error: [129] "SUREN_TEST"."PARTITION_TARGET_TABLE": line 53 col 3 (at pos 2173): [129] (range 3)
Any reasons for this error?
Thanks,
Suren.
Similar Messages
-
Performance for ALTER TABLE statements
Hi,
I'd like to improve performance for scripts running several ALTER TABLE statements. I have two questions regarding this.
This is the original code:
ALTER TABLE CUSTOMER_ORDER_DELIVERY_TAB ADD (
QTY_TO_INVOICE NUMBER NULL );
ALTER TABLE CUSTOMER_ORDER_DELIVERY_TAB ADD (
QTY_INVOICED NUMBER NULL );
1. Would I gain any performance by making the following changes?
ALTER TABLE CUSTOMER_ORDER_DELIVERY_TAB ADD (
QTY_TO_INVOICE NUMBER NULL,
QTY_INVOICED NUMBER NULL );
These columns are later on filled with values and then made NOT NULL.
2. Would I gain anything by make these columns NOT NULL with a DEFAULT value in the first statement and then later on insert the values?
/Roland Bali
null1. It wud definitely increase the performance.
2. You can only have NOT NULL columns added to an existing table if the table is empty.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Roland Bali ([email protected]):
Hi,
I'd like to improve performance for scripts running several ALTER TABLE statements. I have two questions regarding this.
This is the original code:
ALTER TABLE CUSTOMER_ORDER_DELIVERY_TAB ADD (
QTY_TO_INVOICE NUMBER NULL );
ALTER TABLE CUSTOMER_ORDER_DELIVERY_TAB ADD (
QTY_INVOICED NUMBER NULL );
1. Would I gain any performance by making the following changes?
ALTER TABLE CUSTOMER_ORDER_DELIVERY_TAB ADD (
QTY_TO_INVOICE NUMBER NULL,
QTY_INVOICED NUMBER NULL );
These columns are later on filled with values and then made NOT NULL.
2. Would I gain anything by make these columns NOT NULL with a DEFAULT value in the first statement and then later on insert the values?
/Roland Bali<HR></BLOCKQUOTE>
Naveen -
Alter Table Statements in Designer
Hi Guys,
Just wondering if anyone knows if it's possible to store Alter Table statements in Designer 9i?
AntonHi,
The designer generate alter statements for you.
e.g You have a table emp with empno number(8) in designer and in your application database. You cahnged empno to number(12) in designer. Generate ddl pointing to your application database. Designer generate an ALTER table script for you. -
How to run update query statement to update a table cell
I have a job within that has dataflow which loads data to target after teh dataflow is done loading, i would like to call to run the following: in the workflow context do i need to add a script object , plus also the below query is it the proper way to run an update statement.
sql('Target_DS','update tbl_job_status set endtime=sysdate() where endtime is null');
Thank you very much for the helpful info
kind regards.Arun,
Is this the right way instead of doing enable recovery.
Manaully taking care of recoverable workflow logic, by updating a table_job_status(starttime and end_time columns)?
the only advantage of going this way rather than using recover as a unit is, if i use recover as a unit.
then if any problem occurs in any dataflow, then all the dataflow one more time gets executed.
instead i want only the data flow with the error occur has to run. for delta's.
Kind regards.
Edited by: cplusplus1 on Feb 13, 2012 4:21 PM -
How to run a sql statement with bind variable in a test environment
Hello,
I have a sql statement in prod that I like to run in test. I got the sql statement from statspack, but the statement has bind variables. How do I get this statement to run in test? Thank you.Hi,
If you have the SQL statement and all the referenced objects are available in your test env then what is the problem to run it?
If I am not wront to get your reqmnt...
i.e
SQL> select * from emp
where emp_no = &empno
and dept_code = &deptcode;
Thanks -
Multiple Alter Table Statements in one batch
Hi Team,
We have in one of our upcoming release two columns being added to a table that has over 20 million records and 14 indexes.
We needed to add two columns to the table both not null (bit). Because it was taking a while to add the columns, we thought that putting these two alter statements in one batch would speed up the operation significantly but to my surprise it did not.
Conclusion from my test: individual alter statements or batch alter statements take the same time
Here are me test and results - table Order1 and Order2 are exactly the same structure and data.
Test case 1:
===================
ALTER TABLE Order1
ADD OR_N BIT DEFAULT 0 NOT NULL
go
ALTER TABLE AccountTradeConfirmation_Alter1
ADD OR_S BIT DEFAULT 0 NOT NULL
Go
Elapsed Time: 2 hrs
Mar 18 2015 5:56PM
(1 row affected)
Non-clustered index (index id = 3) is being rebuilt.
Non-clustered index (index id = 4) is being rebuilt.
Non-clustered index (index id = 5) is being rebuilt.
Non-clustered index (index id = 6) is being rebuilt.
Non-clustered index (index id = 7) is being rebuilt.
Non-clustered index (index id = 8) is being rebuilt.
Non-clustered index (index id = 9) is being rebuilt.
Non-clustered index (index id = 10) is being rebuilt.
Non-clustered index (index id = 11) is being rebuilt.
Non-clustered index (index id = 12) is being rebuilt.
Non-clustered index (index id = 13) is being rebuilt.
Non-clustered index (index id = 14) is being rebuilt.
(21777920 rows affected)
Non-clustered index (index id = 3) is being rebuilt.
Non-clustered index (index id = 4) is being rebuilt.
Non-clustered index (index id = 5) is being rebuilt.
Non-clustered index (index id = 6) is being rebuilt.
Non-clustered index (index id = 7) is being rebuilt.
Non-clustered index (index id = 8) is being rebuilt.
Non-clustered index (index id = 9) is being rebuilt.
Non-clustered index (index id = 10) is being rebuilt.
Non-clustered index (index id = 11) is being rebuilt.
Non-clustered index (index id = 12) is being rebuilt.
Non-clustered index (index id = 13) is being rebuilt.
Non-clustered index (index id = 14) is being rebuilt.
(21777920 rows affected)
Mar 18 2015 7:52PM
Test case 2:
===================
ALTER TABLE Order2
ADD OR_N BIT DEFAULT 0 NOT NULL, OR_S BIT DEFAULT 0 NOT NULL
go
2 hrs elapsed time
Mar 20 2015 11:10AM
(1 row affected)
Non-clustered index (index id = 3) is being rebuilt.
Non-clustered index (index id = 4) is being rebuilt.
Non-clustered index (index id = 5) is being rebuilt.
Non-clustered index (index id = 6) is being rebuilt.
Non-clustered index (index id = 7) is being rebuilt.
Non-clustered index (index id = 8) is being rebuilt.
Non-clustered index (index id = 9) is being rebuilt.
Non-clustered index (index id = 10) is being rebuilt.
Non-clustered index (index id = 11) is being rebuilt.
Non-clustered index (index id = 12) is being rebuilt.
Non-clustered index (index id = 13) is being rebuilt.
Non-clustered index (index id = 14) is being rebuilt.
(21777920 rows affected)
Mar 20 2015 1:12PMHi Kiran,
I have read your response a few times and I was not able to understand your angle. I assume based on the results of my test that Sybase does the following in processing the alter statements
ALTER TABLE Order2
ADD OR_N BIT DEFAULT 0 NOT NULL, OR_S BIT DEFAULT 0 NOT NULL
go
process alter ADD OR_N BIT
-- > make copy of table
---> alter original table
--> put data back in
process alterOR_S BIT
-- > make copy of table
---> alter original table
--> put data back in
rebuild index
my expectation was that it would make a copy of the table only once and process the two alter statements. Also when doing the alter separately (test1) it rebuilt the index twice, however using the batch the index was rebuilt once (at least only one message displayed).
Regards. -
Commit after alter table statement or not?
Hi,
Is it necessary to put the a commit after the following statement or is it automatically committed:
Alter table tab_name drop column col_name;
ThanksKhurram,
Isnt Eric you are , i mean isnt yours synonym :)Erm...simple answer. No. We are not the same person. I just know that Eric, like yourself, makes good contributions to these threads and then someone like that is coming on the forums and trying to make himself look better and put down the regular contributors which isn't really on is it, I think you'll agree.
CREATE PUBLIC SYNONYM Eric FOR Blushadow;
hehe. -
What privs r required to run Alter table truncate partition update indexes?
I rebuilt the indexes on the table. Know my problem is that when I truncate a partition on the table the unique index whic consist of the primary key fields becomes unusable which causes my to have to rebuild it after each truncate. I tried to runm the following statement from the master schema on but get
an insufficient privs error when I use "update indexes":
Alter table schema_name.table_name truncate partition partition_name storage update indexes;
What priv does master need to perform statement successfully when there's data in it?
Does using 'update indexes' needs extra priveleges?
Thanks in Advance
GaganHi Its Oracle 10.2.0.4 64 Bit on HP UX.
I dont have the exact error as I got this much information only from the end user....It will be couple of hours more then he will be available again
ok so for Truncate we need 'Drop any' privs but to use clause 'update indexes' alongwith do we need some extra privelege?
Thanks again
Gagan -
Difference between alter table statements to add primary keys
Hi,
Can someone explain what the difference between these 2 statements are and if & when one should be used over the other?
Also, are the brackets around the column name necessary?
Thanks!
ALTER TABLE xyz ADD CONSTRAINT id_pk PRIMARY KEY (id);
ALTER TABLE xyz ADD PRIMARY KEY (id);Hi,
As every one has explained that there is no difference in the actual functioning of the two constraints except that the first statement will create Primary Key constraint with user defined name as id_pk whereas in the second statement Primary key will be created with system generated name like SYS....
Normally name for the constraints are needed when you are working on constraints like need to enable or disable the constraints or need to drop the constraints.
We can say that names for primary key are least required when it comes to the usage except better recognization.
Because we can drop primary key, disable primary key,enable primary key without giving the name for the primary key as there can only be one primary key in the table. So not much an issue with the name.
But as earlier post say its better than nothing,, i will add to it that its almost same as that with names constrained in case of Primary Keys taking into account the usage of the named primary key.
Regards -
Table compression and alter table statement
Friends
I am trying to add columns to a table which is compressed. Since Oracle treats compressed tables as Object tables, I cannot add columns directly so I tried to uncompress table first and then add columns. This doesnt seems to work.
What could be issue.
Thanks
Vishal V.
Script to test is here and results are below.
-- Test1 => add columns to uncompressed table -> Success
DROP TABLE TAB_COMP;
CREATE TABLE TAB_COMP(ID NUMBER) NOCOMPRESS;
ALTER TABLE TAB_COMP ADD (NAME VARCHAR2(10));
-- Test2 =. try adding columns to compressed tables, uncompress it and then try again -> Fails
DROP TABLE TAB_COMP;
CREATE TABLE TAB_COMP(ID NUMBER) COMPRESS;
ALTER TABLE TAB_COMP ADD (NAME VARCHAR2(10));
ALTER TABLE TAB_COMP move NOCOMPRESS;
ALTER TABLE TAB_COMP ADD (NAME VARCHAR2(10));
SQL> -- Test1 => add columns to uncompressed table -> Success
SQL> DROP TABLE TAB_COMP;
Table dropped.
SQL> CREATE TABLE TAB_COMP(ID NUMBER) NOCOMPRESS;
Table created.
SQL> ALTER TABLE TAB_COMP ADD (NAME VARCHAR2(10));
Table altered.
SQL>
SQL> -- Test2 =. try adding columns to compressed tables, uncompress it and then try again -> Fails
SQL> DROP TABLE TAB_COMP;
Table dropped.
SQL> CREATE TABLE TAB_COMP(ID NUMBER) COMPRESS;
Table created.
SQL> ALTER TABLE TAB_COMP ADD (NAME VARCHAR2(10));
ALTER TABLE TAB_COMP ADD (NAME VARCHAR2(10))
ERROR at line 1:
ORA-22856: cannot add columns to object tables
SQL> ALTER TABLE TAB_COMP move NOCOMPRESS;
Table altered.
SQL> ALTER TABLE TAB_COMP ADD (NAME VARCHAR2(10));
ALTER TABLE TAB_COMP ADD (NAME VARCHAR2(10))
ERROR at line 1:
ORA-22856: cannot add columns to object tablesWhich version of oracle you are using?
1* create table test1234(a number) compress
SQL> /
Table created.
Elapsed: 00:00:00.02
SQL> alter table test1234 add(b varchar2(200));
Table altered.
Elapsed: 00:00:00.02 -
Create table statement inside a procedure.
Hi,
I'm trying to write a procedure creates some tables. The procedure has not arguments. I have written it in this way:
CREATE OR REPLACE PROCEDURE MIGRAZIONE
IS
var varchar2(2000);
BEGIN
--INIZIO tabella dominio spr_klers_bor_borsa
CREATE TABLE SPR_KLERS_BOR_BORSA34
ID VARCHAR2(4 BYTE) NOT NULL,
DESCRIPTION VARCHAR2(80 BYTE)
CREATE UNIQUE INDEX SPR_KLERS_IAZ_BORSA_PK ON SPR_KLERS_BOR_BORSA
(ID)
LOGGING
TABLESPACE FIN_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
NOPARALLEL;
ALTER TABLE SPR_KLERS_BOR_BORSA ADD (
CONSTRAINT SPR_KLERS_IAZ_BORSA_PK
PRIMARY KEY
(ID)
USING INDEX
TABLESPACE FIN_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
--FINE tabella spr_klers_bor_borsa
END MIGRAZIONE;When I compile I receive this message:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
What does it mean?
How can I solve?
I have tried to change the procedure in this way:
CREATE OR REPLACE PROCEDURE MIGRAZIONE
IS
var varchar2(2000);
BEGIN
--INIZIO tabella dominio spr_klers_bor_borsa
var := 'CREATE TABLE SPR_KLERS_BOR_BORSA
ID VARCHAR2(4 BYTE) NOT NULL,
DESCRIPTION VARCHAR2(80 BYTE)
CREATE UNIQUE INDEX SPR_KLERS_IAZ_BORSA_PK ON SPR_KLERS_BOR_BORSA
(ID)
LOGGING
TABLESPACE FIN_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
NOPARALLEL;
ALTER TABLE SPR_KLERS_BOR_BORSA ADD (
CONSTRAINT SPR_KLERS_IAZ_BORSA_PK
PRIMARY KEY
(ID)
USING INDEX
TABLESPACE FIN_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
execute immediate var;
--FINE tabella spr_klers_bor_borsa
END MIGRAZIONE;And when I compile the version above I receive:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
How can I solve?
Thanks all, bye bye.Here you have to user dynamic sql for create table, cerate index etc.
like
CREATE OR REPLACE PROCEDURE MIGRAZIONE
IS
var varchar2(2000);
BEGIN
--INIZIO tabella dominio spr_klers_bor_borsa
var := 'CREATE TABLE SPR_KLERS_BOR_BORSA
ID VARCHAR2(4 BYTE) NOT NULL,
DESCRIPTION VARCHAR2(80 BYTE)
Execute immediate var;
var := 'CREATE UNIQUE INDEX SPR_KLERS_IAZ_BORSA_PK ON SPR_KLERS_BOR_BORSA
(ID)
LOGGING
TABLESPACE FIN_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
NOPARALLEL' ;
Execute immediate var;
var := 'ALTER TABLE SPR_KLERS_BOR_BORSA ADD (
CONSTRAINT SPR_KLERS_IAZ_BORSA_PK
PRIMARY KEY
(ID)
USING INDEX
TABLESPACE FIN_DATA
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
execute immediate var;
--FINE tabella spr_klers_bor_borsa
END MIGRAZIONE;YOu can specify all the ddl statements in one execute immediate.
Edited by: s_2 on Oct 17, 2008 6:59 PM -
How to run dynamic SQL from an ODI procedure step
I am on ODI 11.1.1.6.4. From within an ODI IKM step I have no problem running a procedure step like the following which calls a pl/sql procedure to get SQL text then later runs that code. Is there anyway to do the same from within an ODI procedure? I've tried a couple of variations and can not seem to get the parsing levels to resolve within a procedure like they resolve from within a KM step.
<@
/* Setup Java variables */
String out_SQL = "";
try
java.sql.Connection sourceConnection = odiRef.getJDBCConnection("SRC");
String sqltxt = "{call set_sql(?)}";
java.sql.CallableStatement pstmt = sourceConnection.prepareCall(sqltxt);
try
pstmt.registerOutParameter( 1, java.sql.Types.VARCHAR);
pstmt.execute();
out_SQL = pstmt.getString(1);
catch(java.sql.SQLException ex)
errMessage = ex.getMessage();
errMessage = errMessage.replace("'","");
finally
pstmt.close();
catch(java.lang.Exception e)
errMessage = e.getMessage();
errMessage = errMessage.replace("'","");
@>
BEGIN
-- The SQL that I want to run
<@
out.println(out_SQL);
@>
-- Error handling
<@ if ( out_SQL.length() ==0 ) { @>
raise_application_error(-20101, '<@=errMessage@>');
<@ } else { @>
dbms_output.put_line('Successful.');
<@ } @>
END;
------Please understand that I know that I can do this all within PL/SQL -- I am explicitly doing it the way I have outlined because I want to better understand the parsing levels/behavior within ODI procedures and I want to understand why KMs steps behave differently.
Another observation -- putting this all within a pl/sql block prevents ODI from properly capturing insert/update/delete row counts like it would if it were running a SQL statement.
So the question remains -- is there a way to run a dynamic SQL statement in an ODI procedure where the SQL statement is generated from within an Oracle procedure call and then run as SQL within an ODI procedure step? Best would be if there is an example of how this can be done. -
Privilege error while running Create Table Script inside Stored Procedure.
Hello All,
I have Oracle 10G server and SQL Developer Client,
I have One User with Appropriate Rights, Login with that user from SQL Developer(client),
Within my Procedure, Dynamic SQL script is like If I pass in a TABLE NAME as parameter, It Creates that table, but now problem is It throws an error for Privilege.
Where as if I Execute Create table script outside the procedure(as Normal SQL), it executes Ok, but why it throws Privilege error within procedure ?
Whether any extra Rights needed for this user to execute such Create Table Dynamic SQL?
Please Help.
Thanks,
j@yElic
Thanks a lot dude...
It works now,
regards,
j@y -
How to run a SQL statement which is stored inside an SQL Table
Hello,
If anyone please help me with the following problem I would be forever grateful
I have an SQL statement which is stored inside a certain SQL table, I want to use that SQL statement inside my PL/SQL procedure.
Was thinking of a simple solution of obtaining the SQL statement into an array and then execute it, yet how could I do so exactly with PL/SQL? I've only started playing around with PL/SQL in the last few days.
Thanks in advance!
This is how it looks like more or less:
Displaying result for:
SELECT TRIM(OBJ_VALU_TXT)
FROM OBJ_VALU_DOC
WHERE OBJECT_TYPE = 'FLD'
AND OBJECT_CODE = 15443
AND OBJ_VALU_CD = 'ACR'
ORDER BYDOC_SEQ_NO
00001
SELECT
VALUE(MAX(RECEIPT_NO) + 1, :OUT-COMP-FACTOR)
FROM RECEIPT
WHERE (RECEIPT_NO BETWEEN
:OUT-COMP-FACTOR AND :OUT-TO-NUMBER) OR
(RECEIPT_NO > :OUT-COMP-FACTOR AND
:OUT-TO-NUMBER = 0)Here's a demo of your requirement.
create table t ( col1 varchar2(200));
table created
insert into t values('select * from dual');
1 row inserted
declare
v_col varchar2(200);
v_val varchar2(200);
begin
select col1 into v_col from t;
execute immediate v_col into v_val;
dbms_output.put_line(v_val);
end;
X
Using into clause, you can use as many variables as required. But the basic approach reamins the same.
But storing SQL in DB is not an efficient design.
Ishan -
Urgent-how to run 'alter system kill session 'sid, serial#' in form 6i ?
I want to write a procedure in Form 6i so that user can kill the session by herself.
I know kill session sql is 'alter system kill session 'sid, serial#'', however, I fould that I can only run it it sql plus screen, how can I run it in Form or in Stored procedure?
Urgent....Please!try using Forms_ddl('alter system......'); in the forms. it will execute the dml statements in the form.
zaibi.
Maybe you are looking for
-
Updated mac to snow leopard now safari won't open
I just updated my iMac to snow leopard, as I was having problems updating iTunes. Now safari says it can't open with this version of mac snow leopard. Any suggestions?
-
Can FLASH program be pasted on Labview
Hi everyone, Newbie here, I would like to know whether a Flash program can be pasted on a Labview program, just like the Flash program can be pasted on the Dreamweaver. Thank you all. Regards, Tay
-
CIPTUG Annual Conference around the corner!
For those of you who are not aware, CIPTUG, the official Cisco IP Telecommunications user group, holds an annual conference in the Fall to bring users and vendors together to share information and resources. For more information, please see: www.cipt
-
Report fetched by windows OS report "Performance by System"
When we fetch the report from the reporting pane in "Windows server operating server reporting" (Performance by System), sometimes the data shown in the column form comes in the yellow and red color (which shows warning and critical respectively). M
-
Videos loading slowly and often only partially
Sorry if this has already been adressed somewhere, I could not find an answer to my problem. For the last week all videos I've been attempting to stream have been loading very slowly or only partially (it's taking me at least 4 times the norm to load