Add a new column with DEC
Hi allI have tab_trans of transactions table which has nearly 20 million records.
He has entries of all transactions. If any transaction is canceled or partially canceled it also stored there.
To know entirely cancelled transactions currently, we need calculate the sum of the amount of the transaction based on trans_date and trans_id.
To avoid this, I want to add a new column to the table. But it takes a lot of time hell.
This is the structure of the table.
Trans_id Trans_date Ref_trans_id Ref_trans_date Trans_amount Trans_ind
10000 2/2/2010 13:12:10 100 0
10001 8/2/2010 12:43:55 300 0
10002 11/2/2010 09:23:24 10000 2/2/2010 13:12:10 -20 1
10003 22/2/2010 10:32:45 10000 2/2/2010 13:12:10 -40 1
10004 23/2/2010 09:45:23 10001 8/2/2010 12:43:55 -300 1
10005 24/2/2010 07:30:23 500 0
So I decided to create a temp_table using CTAS from tab_trans add the rest_amount column and update it with trans_amount in CTAS itself.
create table temp_tab_trans as select Trans_id,Trans_date,Ref_trans_id,Ref_trans_date,Trans_amount,Trans_amount rest_amount from tab_trans ;
Then I find out the rest_amount using correlated query.
update temp_tab_trans a set rest_amount =nvl (select sum(trans_amount) from tab_trans b where b.ref_trans_date=a.trans_date and b.trans_id=a.trans_id),trans_amount) where trans_id=0;
My intended result is :
Trans_id Trans_date Ref_trans_id Ref_trans_date Trans_amount Trans_ind Rest_amount
10000 2/2/2010 13:12:10 100 0 40
10001 8/2/2010 12:43:55 300 0 0
10002 11/2/2010 09:23:24 10000 2/2/2010 13:12:10 -20 1 -20
10003 22/2/2010 10:32:45 10000 2/2/2010 13:12:10 -40 1 -40
10004 23/2/2010 09:45:23 10001 8/2/2010 12:43:55 -300 1 -300
10005 24/2/2010 07:30:23 500 0 500
IE > partially/fully cancelled transactions should refresh the rest_amount in the original transaction (where trans_id = 0).After the temp_tab_trans, I create indexes as in tab_trans and deposit of tab_trans and rename temp_tab_trans to tab_trans.
Can I do the update in the ETG itself? Can someone help me...
Hello
You can get the sum without a subquery using the analytical SUM function, like this:
CREATE TABLE temp_tab_trans
AS
SELECT t.*
, CASE
WHEN trans_ind = 0
THEN SUM (trans_amount)
OVER ( PARTITION BY NVL (ref_trans_id, trans_id)
, NVL (ref_trans_date, trans_date)
)
ELSE trans_amount
END AS rest_amount
FROM tab_trans t
;
If you wish to post, CREATE TABLE and INSERT statements for your sample data, and then I could test it.
Tags: Database
Similar Questions
-
Hello
I have an emp_job_det with a, b, c columns table. Note that this TABLE ALREADY has DATA OF THESE COLUMNS
IAM now add a new column "D" with forced not null
Fistly I alter the table by adding the single column "D", if I do, the entire column would be created with alll of nulls for the column DEFAULT D
ALTER table emp_job_det Add number D; -do note not null CONSTRAINT is not added
Second... If I try to add the constraint not null, get an eoor as already conatained null values...
(GOLD)
In other words, if I put the query
ALTER table emp_job_det Add number D NOT NULL; -THROWS ERROR AS TABLE ALREADY CONTAINS DATA
So my question is how how can I add a new column with a constraint not null, table already has the data, without falling off the table
Please help me on this issue...
Add the column without constraint, then fill the column. Once all the rows in the table are given in the new column, and then add the constraint not null.
-
Add a new column in a CREATE - AS SELECT statement
I create a table using a select in an existing table. I would also like to add a new column (with nulls for all records). Is this possible? What is the syntax for this column?
Thank you
Kevinuser10856100 wrote:
I create a table using a select in an existing table. I would also like to add a new column (with nulls for all records). Is this possible? What is the syntax for this column?Thank you
KevinKevin,
In any case, create table will not accept one byte NULL for the column declaration.SQL> create table e(empno,ename, sal, new_co) as select empno,ename, sal, to_number(null) from emp; create table e(empno,ename, sal, new_co) as select empno,ename, sal, to_number(null) from emp * ERROR at line 1: ORA-01723: zero-length columns are not allowed SQL> create table e(empno,ename, sal, new_co) as select empno,ename, sal, to_number('12') from emp; Table created. SQL> desc e Name Null? Type ----------------------------------------- -------- ---------------------------- EMPNO NUMBER(4) ENAME VARCHAR2(10) SAL NUMBER(7,2) NEW_CO NUMBER SQL> select * from e; EMPNO ENAME SAL NEW_CO ---------- ---------- ---------- ---------- 7369 SMITH 0 12 7499 ALLEN 0 12 7521 WARD 0 12 7566 JONES 0 12 7654 MARTIN 0 12 7698 BLAKE 0 12 7782 CLARK 0 12 7788 SCOTT 0 12 7839 KING 0 12 7844 TURNER 0 12 7876 ADAMS 0 12 EMPNO ENAME SAL NEW_CO ---------- ---------- ---------- ---------- 7900 JAMES 0 12 7902 FORD 0 12 7934 MILLER 0 12 7369 SMITH 0 12 7499 ALLEN 0 12 16 rows selected.
HTH
Aman... -
Effect with application ADF Go-live when I add the new column to the database.
Hi all
My already deployed ADF application and entry into service.
I would add three columns of data.
I worried that if I have does not add the new column and will redeploy again, it will have an effect at my request.
Anyone here ever face with a kind of this problem
Kind regards
ZenoniHello
As the General best practices. You do not direct operations on the ACTIVE database rather test the application in the test environment.
on the other hand if your column is NOT NULL then it will affect your application otherwise no impact
-
Can we add a new column to a UNIQUE INDEX with out droping the same index?
Can one please let me know how to add a new column to the UNIQUE INDEX existing on the same fall.
DB: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production 64-bit
Thank you.
Mahi.TechMahi.com wrote:
Can one please let me know how to add a new column to the UNIQUE INDEX existing on the same fall.
DB: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production 64-bit
Thank you.
Mahi.I think that its doable and I don't think that it should be feasible to all too since that would disrupt the structure of index completely. I think, you must delete the existing one to add a new column that is do a composite index.
Aman...
-
I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?
Add two new columns after than the original with space separated values column.
Select cell B1 and type (or copy and paste it here) the formula:
= IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
shortcut for this is:
B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")
or
the formula of the C1 could also be:
= IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")
Select cells B1 and C1, copy
Select cells B1 at the end of the C column, paste
-
Hello
Previously in Windows XP and 2003, IColumnProvider is available using which it was possible to add a new column to Windows Explorer Details view, but with the removal of this API, the new columns are is not displayed in Windows Explorer on a Vista or Windows 2008 Server. It is said that there is a new concept of property system. So I would like to know if it is possible to implement something similar uses of property systems.These forums are for end users, rather than developers. You must use the MSDN Forums to get this kind of information.
-
How to add the new column to a specific position
Hello
My table looks like Fallows.
Select * from company
PRODUCT_ID COMPANY_ID COMPANY_SHORT_NAME COMPANY_LONG_NAME 1 1001 An Inc. Long name A Inc. 1 1002 B Inc. Long name B Inc. 1 1003 C Inc. Long name C Inc. 2 1004 D Inc. Long name D Inc. 2 1005 E Inc. Long name E Inc. 2 1006 F Inc. Long name F Inc. My requirement is I would LIKE to add A NEW COLUMN AS COMPANY_LOCATION NEXT TO COMPANY_SHORT_NAME
How to get there.
I tried like Fallows alter company table add company_location varchar2 (100) after company_short_name;
but this query shows the error
ORA-01735: invalid option of ALTER TABLE
If the query I've tried is correct?
Give me your suggestions.
Thanks in advance.
As long as you're on 11 GR 2 or lower, it will not work.
There is no Clause "AFTER"in the alter table do not add column."
You have the chance to use dbms_redefinition (when no interruption of service is possible) or manually create a new table with the columns in the order you need and then migrate the data and then drop the original and rename a new.
In case you are already on 12 c, you have a chance to add the column to the end and then make visible columns and invisible status in the right order. This way your column will get to the position that you want it to be.
Kind regards
Carsten
-
How to add the new column in existing table to our desired location?
How to add the new column in existing table to our desired location?
For example, I have to add the new column 'course' before the salary column in the emp table.
I think the best way is to add the column at the end of the table and create a new view with the order of the columns...
Another option...
places the data into a temporary table and recreate the table with the correct order of the columns, and then insert data to the table from the temporary table
Refer
Add column (from table) in the desired position
Example:
CREATE TABLE temp_my_user LIKE)
SELECT * FROM password);
DROP TABLE password;
(Password) CREATE TABLE
userID NUMBER
, first name VARCAHR2 (25)
, middleInitial VARCHAR2 (1)
(, name VARCHAR2 (25));
INSERT INTO password (userID, firstName, lastName)
(SELECT username
first name
lastName
OF temp_my_user);
DROP TABLE temp_user;
-
Add a new column and update of records
I have the DW (OBAW) loaded at full load. Everything works fine.
Now, I add a new column in a dimension in the DW (and in the ETL, RPD, CAD, etc.).
I know that new (incremental) charges will take care of this column for the new/changed records... but
Question is how can I update records, already loaded into PS for values in this column...?
(a) I guess I can do this particular task of this dimension marked as 'full' DAC
I'm not sure it's a good solution... I guess new ROW_WIDs will be generated and I have the connection with the fact table will be broken... Right?
(b) I could blank the date of updating for this table W_ and/or refresher for this table S_ (from Siebel)
I guess this could affect more than one task... or in other words all tasks dealing with this tables W_ and S_ - it also seems that the issue with the new ROW_WIDs will continue...
Pls someone care to comment or offer a better solution?
TXS. A lot.
Antonio
Assume that the table is W_ASSET_D or any other dimension...
Yes, I plan to the OOB card personalization (in the folder custom, etc.).
So if I'm correct... the option for setting null date discount for the W_ASSET_D table... and the use of DAC pointing to the custom task will take care of him...
Just to be sure... It will not create new ROW_WIDs for W_ASSET_D?
I'm worried by the _F FKs to this dimension tables...
TXS for your help.
-
How to add the new column in the tabular layout editor in Oracle Forms
Hello
I need to add the new column to a datablock and display the newly added column in the form. What are the steps I need to follow.
1. I chose the new column from the view to the datablock.
2. Add the text element in the layout editor. But this position is not correct. It overlaps with another column. How to add the new column to the layout editor?
Thank you
HCIn the layout editor, you can simply drag the fields so that they do not overlap.
See http://www.youtube.com/watch?v=7emNa7THMLgSandeep Gandhi
-
Add the new column on 25 million lines Table
Hi gurus,
I have to add the new column to a populated application table who get to each Transaction.
We can do this with no interruption of service and what are the things that I need to look after adding the peak of performance.
Something happened to my mind is re - run stats
Any Suggestion
Database version = 10.2.0.4
OS = RHEL4
I appreciate your help on this
Thank you789816 wrote:
If the GET of the table is locked, it means that the application cannot write any new transactions in the table until the new default values has been updated?, my understanding of the downtime to do this to*-Online Yes, you need downtime in 10 g *.
Another Question if we have default values as NULL will always be the table get locked?
*-ONLINE YES *.
11 g, this problem has been fixed by oracle: http://www.oracle-class.com/?p=1943
create table sales as select rownum as id, mod(rownum,5) as product_id, mod(rownum,100) as client_id, 2000 as price, to_date( '01.'||lpad(to_char(mod(rownum,3)+1),2,'0')||'.2011','dd.mm.yyyy') as c_date from dual 10 connect by level <= 2.5e5; Table created. SQL> select count(*) from sales; COUNT(*) ---------- 250000 ----session 1 SQL> begin 2 for i in 1..100000 loop 3 insert into sales (id) values(i); 4 end loop; 5 commit; 6 end; 7 / PL/SQL procedure successfully completed. SQL> When inserting into the table sales, the alter table add the new column was waiting for the inserts to finish -----session2: SQL> alter table sales add (provider_id NUMBER(2)); Table altered. SQL>
-
Unable to add a new column to the table of the LCD? Option, just usually add it.
I have a form of LCD with a table in it. Im trying to simply add a new column to the table. The option is there, but the column appear just after clicking Add the column to the left. I selected a column, right click the space > insert > column to the left. But the habit intsert. The object table properties tab shows lines and colum numbers, but they are grey.
See screenshots:
http://www.emermed.NET/staging/forums...
http://www.emermed.NET/staging/forums...
It is a dynamic array, where a new line can be inserted using a button. Is that the dynamic nature of the question? ID hate to cancel all the flow dynamics and programming just to add a column, and then reapply them all.
Thank you!Hello
You do not add the columns in the object > palette (screenshot 2) of the Table. I suspect that the problem is that it is not enough on the page (in the content area) to add the column. In the screenshot 1, if you look at the width of the column highlighted from the space to the right of the table, you will see that a column can be added due to restrictions of space.
Reduce the width of the column highlighted (temporarily), and then add a column. Once added, you can resize the columns to match the width of the page.
Hope that helps,
Niall
-
Mr President.
What is wrong with this sequence, it does not work when, after 3 inserts, I add a new record with the trigger it gives an error.
--SL_CUSTOMERS table data INSERT INTO SL_CUSTOMERS VALUES(1,'Kamrul Hasan',NULL,NULL,'Moghbazar', 'Dhaka','0456789123',NULL,NULL,NULL,'Y',NULL); INSERT INTO SL_CUSTOMERS VALUES(2,'Rabiul Alam',NULL,NULL,'Motijheel', 'Dhaka','0567891234',NULL,NULL,NULL,'Y',NULL); INSERT INTO SL_CUSTOMERS VALUES(3,'Shahed Hasan',NULL,NULL,'2-G/1,2-2,Mirpur', 'Dhaka','0678912345',NULL,NULL,NULL,'Y',NULL);
CREATE SEQUENCE "ALIZA"."SL_CUSTOMERS_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE ; CREATE OR REPLACE TRIGGER SL_CUSTOMERS_TRG BEFORE INSERT ON "ALIZA"."SL_CUSTOMERS" FOR EACH ROW BEGIN IF :NEW.CUSTOMER_ID IS NULL OR :NEW.CUSTOMER_ID < 0 THEN SELECT SL_CUSTOMERS_SEQ.nextval INTO :NEW.CUSTOMER_ID FROM DUAL; END IF; END; /
When I try to insert several records with the seq.nextval it gives error
violation of primary key.
INSERT INTO "ALIZA"."SL_CUSTOMERS" (CUSTOMER_NAME) VALUES ('sdfsd') ORA-00001: unique constraint (ALIZA.SL_CUSTOMERS_PK) violated ORA-06512: at line 1 One error saving changes to table "ALIZA"."SL_CUSTOMERS": Row 4: ORA-00001: unique constraint (ALIZA.SL_CUSTOMERS_PK) violated ORA-06512: at line 1
Concerning
Mr President.
I find the solution by creating a function before the triiger
as below
CREATE SEQUENCE "ALIZA"."SL_CUSTOMERS_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE ; CREATE OR REPLACE FUNCTION get_SL_CUSTOMERS_vId RETURN VARCHAR2 AS BEGIN RETURN SL_CUSTOMERS_SEQ.NEXTVAL; END; / CREATE OR REPLACE TRIGGER SL_CUSTOMERS_TRG BEFORE INSERT ON "ALIZA"."SL_CUSTOMERS" FOR EACH ROW DECLARE dummy VARCHAR2(200); BEGIN dummy := get_SL_CUSTOMERS_vId(); :NEW.CUSTOMER_ID := dummy; END; /
It works very well
Thank you all for the suggestions.
Concerning
-
Alter a table to add 2 new columns
Hi gurus!
Am editing a table to add 2 new columns... The total number of records in the table RAILWAY is -103002
Here is the news columns to add to the IRON table.
ALTER TABLE ADD IRON
(DLD VARCHAR2 (5))
ID NUMBER (38),
VARCHAR2 (1)) READY.
the statement takes more than 6 minutes to run, so I canceled the performance.
can someone pelase I would like to know what is the reason here.
Please ask your dBA to unlock it for you.
Kill the session that locks the table.
To view the session which can be locked using the below stated:
Select c.owner, c.object_name, c.object_type, select, b.serial #, b.status, b.osuser, b.machine
v $ locked_object a, v$ session b, c dba_objects
where select = a.session_id
and a.object_id = c.object_id;
Maybe you are looking for
-
I constantly get a pop up that Google Chrome is going to stop supporting my MacPro OSX lion v 10.7.5. What should I do next?
-
Can I use windows media player to play mp3 and have the recigition speech to convert to text?
-
Hi, I have a new laptop G550, which I am very satisfied. I am also pleased with Win7. But I want to get a rather than relying on the hidden partition Win7 install disc. Is this possible? In addition, the hidden partition has no equivalent to the Win
-
I can't access my 'deleted items folder.
I can't access my 'deleted items folder. I get a long message in the deleted items folder display."Unable to display the folder. Microsoft Office Outlook cannot access the specified folder location. The messaging interface has returned an unknown er
-
BlackBerry smartphones to connect to App world
I am registered and I have a password App world and Blackberry.com. When I enter and try to download new applications, such as facebook and appworld updates, it requires a password. I get my password and I get the following error message. Unable to v