SQL & PL/SQL :: Split Table Into Two Tables
Oct 16, 2013
There is a table with almost 60 million records. This is a temporary table or rather a staging table. I want to be able to split the table into two tables. This is an example of what the staging table looks like.
sales_persondeploy_adddayobjxobjyobjz
--------------------------------------------------------------
1001 900201201506080
1001 900201201646040
1001 958201202506080
1001 958201202407050
1002 141201201356080
1002 147201203502080
1002 147201203506010
1002 141201201506080
1002 147201203506010
1002 147201203506080
I am trying to split the table like the following
--------
Table 1:
--------
trns_idsales_persondeploy_addday
----------------------------------------------------------------------
65500 1001 900 201201
65501 1001 958 201202
65502 1002 141 201201
65503 1002 147 201203
And the detail line table which looks like following
------
Table 2:
--------
tr_dt_idtrns_trns_id xyz
----------------------------------------------------------
100165500 506080
100165500646040
100165501506080
100165501407050
100265502356080
100265503502080
100265503506010
100265502506080
100265503506010
100265503506080
I come up with two ideas for the problem.
1. The straightforward loop. Read each record > Go through table 1 , get a count of similar records> If exists, use that ID to populate detail table > If doesn't exist create a new ID and populate the detail table
2. Use two cursors. First cursor goes through all the records (*). Takes 1 line, creates an ID on 1st table. Second cursor finds all records that are similar to the first line. Populates the detail table using the ID and then deletes currently inserted rows from the staging table.
I have got the first idea working. It works fine but takes forever since it has to go through the whole table for selecting the count for each record.I tried implementing the second idea but I believe the cursor creates a snapshot of table at runtime so within the loop if it finds out record has been deleted, throws me an error.
View 9 Replies
ADVERTISEMENT
May 3, 2010
I'm needing to pull data into a cursor, then split this data into 3 different tables, each having the same number of rows and a select number of columns from the original. i can pull the data, but then i can only access it one row at a time via FETCH, then i can't load into the 3 new CURSORS one row at a time.
View 11 Replies
View Related
Jun 2, 2011
i'm working on this database assignment...and basically, no matter what I do my table seems to automatically split into a different table after 8 rows...i've tried googling it and using commands like....
set wrap off;
set numwidth 20;
and fiddling with the format of each column but nothing seems to work...i just want my table to show as one table
here's my script
create table patient
(patient_number number(4) primary key,
patient_name varchar(15) NOT NULL,
address varchar(30) NOT NULL,
telephone number(7) NOT NULL,
patient_status char(1) NOT NULL,
next_appt date,
balance number(5,2),
CHECK (balance >= 0),
CHECK (patient_status='N' OR patient_status='A' OR patient_status='I'));
[code]...
12 rows selected.the columns are actually aligned so don't worry about that...it's just the splitting of the rows.
View 5 Replies
View Related
Feb 20, 2012
I have a table with following values in a column
Table A
col1
10
35
20
25
I need to form a query which will take these four values in rownum part and split the records into 4 groups in Table B.
Table B- 90 records (10 + 35 + 20 + 25)
Now for example, the Table B is having emp no, order by ascending and i need to split into 4 groups,
with first group having start value -1 and end value -10
second group - start value -11 and end value-45
third group - start value -46 and end value -65
fourth group - start value - 66 and end value-90
one way i can do it by using union and count, which was a bit tedious if the no. of group goes upto 10.
note that the values in Table A is dynamically changing, so not able to hard code values.
View 2 Replies
View Related
Aug 7, 2013
I've an Oracle Table which has around 300 columns. I've a requirement to split this single table into two tables (150 columns each) by a foreign key.
Now I want to know how to maintain the data integrity while I insert the data into two tables. which means each table should have equal number of rows as we insert the 300 columns data into tables each at a time.
View 8 Replies
View Related
Nov 8, 2012
I have two tables T1 and T2. T1 is the original backup snapshot for changed records from overnight batch in a big table and T2 is the overnight batch changed records. Both tables have similar number of rows (T2 might have more for newly inserted rows) and you can find out the differences by comparing these two according to action column in T2 (C - Update, A - Insert and D - Delete)
how to compare these two tables to generate something like the following. I can join these two tables to generate the diff but it is one row per account.
client_nbr branch_cd, account_cd, action column, old_value, new_value
8888 123 45678 C account_clsfn_cd 004 005
8888 123 45678 C buy_cd 98 99
8888 012 34546 A sell_cd 12
8888 321 98765 D dividend_cd 1
I am using Oracle 10g so Unpivot cannot be used.
CREATE TABLE T1
(
CLIENT_NBR CHAR(4 BYTE) NOT NULL,
BRANCH_CD CHAR(3 BYTE) NOT NULL,
ACCOUNT_CD CHAR(5 BYTE) NOT NULL,
ACCOUNT_CLSFN_CD CHAR(3 BYTE),
SELL_CD CHAR(2 BYTE),
BUY_CD CHAR(2 BYTE),
[code]....
View 4 Replies
View Related
Mar 28, 2011
I have several large tables in the live system! Those table are store historical information.
current situation:
Now, A table record was 129 million rows.
Every month added 4.5M records to this table.
This table data size 17GB and index size 28GB.
I have only 30 GB available free space on disk!
How to split this table to small pieces (partition table by month)?
What is the best approach?
I would like to do partitioning on this table month by month.
View 12 Replies
View Related
Aug 30, 2007
I have a table with over 100000 records.
The format and data is something like this:
Region Code,Name,Surname,ID_Number
1,John,Doe,67
1,Sarah,Jason,45
2,Bob,Marley,69
3,Steven,Johnson,900
2,Harry,Potter,890
3,Sandy,Bay,567
3,Else,Taylor,789 .....
I have about over 100 region codes and each region would like to get their own data. I can manually do the extraction and create a new table for every region, but it's going to take too long.
View 7 Replies
View Related
Aug 20, 2012
We are running an Oracle 10g server.
We are adding support for barcode scanner in one part of our information system. So that the mechanics can add parts to an work orders bill of material themselves using barcode scanner to scan the part and enter the qty.
I can via SQL add a part to the bill of materials and reserve the part. But then the part needs to be issued to make it disappear from the stock.
I have found a table that contains information about the part and the bill of material, it has a column named "QTY ISSUED" I have tried via an update command to set the qty issued = 1 for the reserved part. The table is updated, and via SQL everything looks fine, but the part doesn't disappear from the stock. So my guess is that there is a trigger or function somewhere that I need for this.
View 13 Replies
View Related
Oct 31, 2013
I have 2 tables that doesn't have primary keys. These 2 tables have same number of rows. I want to create a new table from getting some columns from table1 and some columns from table 2. I want to combine first row from table1 and first row from table2.
Below is example
TABLE1
ACOL1 ACOL2 ACOL3
A1 A2 A3
B1 B2 B3
C1 C2 C3
TABLE2
BCOL1 BCOL2 BCOL3
11 12 13
21 22 23
31 32 33
COMBINED_TABLE
ACOL1 BCOL2 BCOL3
A1 12 13
B1 22 23
C1 32 33
I tried below query but no luck. It gives below error:
Query : create table COMBINED_TABLE AS select a.ACOL1, b.BCOL2, b.BCOL3 from (select ACOL1,rownum from TABLE1) a, (select BCOL2, BCOL3, rownum from TABLE2) b WHERE a.rownum = b.rownum
Error : ORA-01747:"invalid user.table.column, table.column, or column specification"
View 7 Replies
View Related
Oct 30, 2013
How does one select * from one table without selecting * from other tables that are included in a query? For example, if in the query below I want to view all fields in some_table, but not the fields from other_table, how do it?
select *
from some_table st,
other_table ot
where st.id = ot.id
View 15 Replies
View Related
Mar 1, 2010
I have 2 tables as shown below. I have to join those tables and get data as in table 3. Condition is I have to get sum of scores for each student where category is 1 and active is Y.
Table1:
col1col2category
A 10 1
A 10 2
B 10 1
B 20 2
C 10 1
D 20 1
J 30 1
Table2:
colAcolBActive
A10Y
A20N
B30Y
B40N
Z35Y
Table3:
STUDENTSCORE
A20
B40
C10
D20
J30
Z35
query to show student name and sum of his score where category is 1 and active is Y. I am using Oracle 8i.
View 8 Replies
View Related
Oct 15, 2012
I want to read 1 table. If the date is less than today, I want to update 4 other tables. I only want to do this update once a day.
While the 4 other tables are being updated, I want the other web users to pause for the update while this procedure runs.
Is there a better way to do this?
Here is what I have:
CREATE OR REPLACE PROCEDURE TEST_TODAY2 AS
-- to create the table
-- create table test_today(updated_date date);
-- insert into test_today(updated_date) values (sysdate-1);
-- select * from test_today;
cursor daily_update_cur is
select updated_date from test_today
for update of updated_date;
[Code]...
Please use {noformat}{noformat} tags before and after your code as described in the FAQ: {message:id=9360002}.
I've corrected it this time for you.
View 6 Replies
View Related
Nov 2, 2013
I have 2 tables Table a(girlscoutid, item, quarter)Table b(girlscoutid, fname, lname) I want to get the names of ppl who did not sell any item/s for the
4th quarter
girlscoutid item quarter7771
drinks 4QS9000
tickets 4QW7771
cookies 2QS5085books 3QF3010tickets3QW5085
cookies1QF lscoutid
fnamelname7771 jenn richochet9000 laura wilkins5085sally mae3010dora mckenzie
This is what I have, however, I get duplicates and also 7771 shows up on the list even though she sold an item on the 4Q.
SELECT fname, lname, a.girlscoutid
FROM a,b
WHERE a.girlscoutid = b.girlscoutidAND term NOT LIKE '4Q_';
View 4 Replies
View Related
Dec 21, 2011
I have strings like
1) ICE_10001 ICE_10002 ICE_10003
2) ICE_10005 ICE_10006
i want to split above strings like
1)ICE_10001
2)ICE_10002
3)ICE_10003
4)ICE_10005
5)ICE_10006
If it is possible in oracle sql
View 15 Replies
View Related
Oct 18, 2013
PROCEDURE COLUMN_SPLIT (p_def IN VARCHAR2, p_sch OUT VARCHAR2, p_table OUT VARCHAR2, p_column OUT VARCHAR2)
IS
BEGIN
NULL;
END;
END;
I want to split p_def by dots, check for 3 elements, and return them in p_sch, p_table and p_column for example p_sch will be like hello.howare.you.I want to split it to hellohowareyouI have very limited knowledge with pl/sql.
View 13 Replies
View Related
May 15, 2009
I have to reorganize one table that related to several other tables. The reorg is too slow when it runs on this table. I would like to create one image of the table and synch it with the original one in real time. So when I run the reorg, I will use the image table that does not constrained by indexes and other objects. Once the reorg is done, I would like to rename the table. how could I do the replication in real time?
View 2 Replies
View Related
May 29, 2011
I need to implement the foreign key on a column of a table from 2 tables. My requirement is in bellow.
drop table t1;
create table t1 (slno number, acc_no number);
drop table t2;
create table t2 (acc_no number primary key, acc_name varchar2(100));
drop table t3;
create table t3 (acc_no1 number primary key, acc_name1 varchar2(100));
[code]...
It is provided that the values of acc_no in t2 and acc_no1 in t3 are unique.Now it required that while inserting into t1 , the system will check either t2 or t3 tables.
View 7 Replies
View Related
Mar 6, 2013
I have one control table as below.I want to rebuild all indexes for the tables in control table.
The control table is having the following data.
SEQ_IDTABLENAME SCHEMA_NAME
1GEDIS_ORDER_FORM_STATES ALL
2GEDIS_NOTES ALL
3GEDIS_CARD_TYPE_AUDIT APRT
4FAX_HEADER OMS
In the control_table schema_name "ALL" means this is for 30 schemas(The table is existed in 30 schemas).Except for schema_name "ALL" ,the table is existed in the particular schema(The table is existed in the only one schema).
I tried the following code it is executing for all 30 schemas(ALL).But it is not executing for specific schemas.
CREATE OR REPLACE PROCEDURE Rebuilding_index
IS
l_sql VARCHAR2(4000);
CURSOR cur_tab_schema
IS
SELECT tablename,schema_name
FROM control_table3;
[code]....
This contains the 30 schema names.
SELECT owner_name FROM global_bu_mapping;
View 4 Replies
View Related
Apr 25, 2013
I want to select data from different tables and insert this into one table based on some conditions:
SELECT *
FROM welltest_msr
WHERE well_s = 3419740
AND check_ind = 1
[Code]....
So I tried doing this with selecting the data and looping through it to do the insert.
DECLARE
--
-- WELLS
--
CURSOR c_well
[code].....
View 6 Replies
View Related
Jan 24, 2013
In a query can we have the same alias for more than 1 table as in the following example
Select C.ContractNum, B.Billnum, B.Billamt,A.
From Contractmaster C,
Billdetails B,
Address A,
Currencymaster c,
Where B.billtype = 1
and C.Contractnum = B.Contractnum
and C.customerref = A.Customerref
and c.currencycode ='EUR'
In the above query, Table Contractmaster has an alias C --in capitals while table Currencymaster has an alias c - in small caps ...
Is this possible in Oracle 11g ? Also i found that the table Currencymaster has no Join conditions I executed the query, without any errors!
View 4 Replies
View Related
Sep 27, 2010
I have a string like '9999999;A' one field as numeric & other as char.Now i want to split this string into two values removing the ; delimiter in oracle using for loop.
View 2 Replies
View Related
Jun 19, 2008
i have a column called name in a table. now what iwould like to do is to check if it has two parts "paulh some" and then output the second part!
SELECT LTRIM(name,' '), length(name) length
FROM list
WHERE INSTR(name,' ') = 1;
but that doesnt work.. the fucntion is NOT checking for the space! if i use another character (a or b etc) it works..
View 2 Replies
View Related
Dec 11, 2008
I have a field called fullname that outputs records with fullname of people.
Here is what I have when I do this sql:
Select fullname from tableOne;
John Jones
Bill Aronsen
Sam Baker
George Williams
Dave Smith
I would like to sort in order of last name but cant figure out how to do the sql:
Bill Aronsen
Sam Baker
John Jones
Dave Smith
George Williams
View 1 Replies
View Related
Feb 19, 2013
how I can change this function to pass argument that length is 32676 .
create or replace TYPE "HRS_SPLIT_TBL_T" as table of varchar2(32767);
create or replace function hrs_split
(
p_list varchar2,
p_del varchar2 := ','
) return hrs_split_tbl_t pipelined
is
[Code]...
I got error String literal too long when execute select below
select distinct COLUMN_VALUE Tbat_latn
from table(
HRS_SPLIT( 'PER0000002,PER0000094,PER0000094,PER0000096,PER0000096,
PER0000024,PER0000024,SAB0000001,SAB0000001,PER0000002,
PER0000096,PER0000094,PER0000094,PER0000002,PER0000024,
PER0000024,PER0000096,PER0000096,PER0000094,PER0000094,
PER0000002,PER0000024,PER0000024,PER0000096,PER0000096,
PER0000094,PER0000094,PER0000002,PER0000024,PER0000024,
[Code]....
View 12 Replies
View Related
Oct 23, 2013
I want to split any user given string into two parts, how can I do it.
suppose some sample inputs may be:
'123456' splits into '123','456' ,'123456789' splits into '12345','6789'
NOTE: the first half splitted string length is greater in case of odd no. string as in second example
How can I do it?
View 13 Replies
View Related
Jul 14, 2010
How to split the values from a column?
For example: i had table T1 with below structue
Table T1
userid
-------
sandy1234
raj6785
Andrew12367
Michael56098
i need output like below structure
Nameid
---- ----
Sandy1234
Raj6785
Andrew12367
Michael56098
View 5 Replies
View Related
Feb 8, 2012
I have a table like follows
Name Gender
-------------
Arun M
Anitha F
Bala M
Banu F
I need the output as follows
Male Female
-----------------
Arun Anitha
Bala Banu
What are the ways can we generate the above query
View 14 Replies
View Related
Jun 18, 2013
I have a small requirement...
Create table temp_a (source_code varchar2(100), target_code varchar2(1000));
Insert into temp_a values ('1','002.0 AND 002.9');
Insert into temp_a values ('2','729.90 AND 079.99 AND 002.9');
Output :
1 002.0
1 002.9
2 729.90
2 079.99
2 002.9
So, once we get the output, it needs to be joined to another table. I did Google search, but most of them are retuning collections / arrays as output. Not sure how I join the collection with the table.
create or replace function splits
(
p_list varchar2,
p_del varchar2
) return split_tbl pipelined
is
l_idx pls_integer;
[code].......
View 3 Replies
View Related
Aug 17, 2012
i have a table emp with three column
columns are (empid varchar,empnomini varchar,nominitype varchar), data in table like
empid empnomini nominitype
1 x B
1 y c
2 xx B
2 yyyy c
and i want data comes like
empid nominitype b nominitype c
1 x y
2 xx yyyy.
View 6 Replies
View Related