Insert first in the results of the empty table in ORA-00001: unique constraint
Hi allWe are running Oracle 10 g. I modified an Oracle stored procedure instead of using the cursor for loops or bulk collect for use INSERT with the SELECT statement. When I run this version, I get ORA-00001 on first insertion. ONCE the exception is thrown. I checked that the array is empty. I don't think the ORA-00001 is the real cause of the problem. I have a syntax problem I'm not aware of.
Here's the script:
CREATE OR REPLACE PROCEDURE SP_LOAD_TEST
(p_rpt_month varchar2)
IS
--===================================================
-- define exceptions
--===================================================
DUP_VAL_ON_INDEX EXCEPTION;
--===================================================
-- read the USER data
--===================================================
CURSOR c_get_USERS_TBL IS
select DIV_CD,
WRKR_USER_ID,
RPT_MONTH
from USERS_TBL
WHERE RPT_MONTH = P_RPT_MONTH
ORDER BY DIV_CD,
WRKR_USER_ID;
--===================================================
-- get the location name from the TLOC_DMSN table
--===================================================
CURSOR c_wrkr_loc_name ( p_wrkr_user_id varchar2) IS
select WRKR_LOC
from .TLOC_DMSN
WHERE TRIM(wrkr_user_id) = TRIM(p_wrkr_user_id);
--===================================================
-- define a place holder for each row fetched from each cursor
--===================================================
c_get_USERS_TBL_row c_get_USERS_TBL%ROWTYPE;
--===================================================
-- define variables
--===================================================
v_elapsed_time VARCHAR2(50);
v_elapsed_time_hh FLOAT;
v_elapsed_time_mi FLOAT;
v_elapsed_time_ss FLOAT;
v_mod_ss FLOAT;
v_mod_mi FLOAT;
v_elapsed_time_minus_ss FLOAT;
v_div_cd1 USERS_TBL.div_cd%TYPE;
v_wrkr_user_id1 USERS_TBL.wrkr_user_id%TYPE;
v_rpt_month1 USERS_TBL.wrkr_user_id%TYPE;
v_div_cd2 USERS_TBL.div_cd%TYPE;
v_wrkr_user_id2 USERS_TBL.wrkr_user_id%TYPE;
V_rpt_month2 USERS_TBL.rpt_month%TYPE;
v_usage_hour FACT_TBL.usage_hour%TYPE;
v_bytes_sent FACT_TBL.bytes_sent%TYPE;
v_bytes_rcvd FACT_TBL.bytes_rcvd%TYPE;
v_total_bytes FACT_TBL.total_bytes%TYPE;
v_div_nm FACT_TBL.div_nm%TYPE;
v_wrkr_loc .TLOC_DMSN.WRKR_LOC%TYPE;
v_wrkr_dspl_nm FACT_TBL.wrkr_dspl_nm%TYPE;
v_wrkr_ph FACT_TBL.wrkr_ph%TYPE;
v_url FACT_TBL.url%TYPE;
v_divcd_userid VARCHAR2(12);
v_prev_divcd_userid VARCHAR2(12);
v_prev_div_cd USERS_TBL.div_cd%TYPE;
v_prev_wrkr_user_id FACT_TBL.wrkr_user_id%TYPE;
v_date_id NUMBER(10);
v_user CHAR(8);
v_seq_id NUMBER;
v_insert_counter NUMBER;
v_mmyyyy VARCHAR2(6);
v_mm VARCHAR2(2);
BEGIN
--===================================================
-- initialize variables
--===================================================
v_div_cd1 := ' ';
v_prev_div_cd := ' ';
v_wrkr_user_id1 := ' ';
v_wrkr_loc := ' ';
v_rpt_month1 := ' ';
v_divcd_userid := ' ';
v_prev_divcd_userid := ' ';
v_prev_wrkr_user_id := ' ';
v_insert_counter := 0;
v_seq_id := 0;
v_mmyyyy := ' ';
--===================================================
-- build run month in mmyyyy format before writing to TLOAD_LOG table
--===================================================
CASE
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'JANUARY' THEN v_mm := '01';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'FEBRUARY' THEN v_mm := '02';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'MARCH' THEN v_mm := '03';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'APRIL' THEN v_mm := '04';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'MAY' THEN v_mm := '05';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'JUNE' THEN v_mm := '06';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'JULY' THEN v_mm := '07';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'AUGUST' THEN v_mm := '08';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'SEPTEMBER' THEN v_mm := '09';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'OCTOBER' THEN v_mm := '10';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'NOVEMBER' THEN v_mm := '11';
WHEN UPPER(SUBSTR(p_rpt_month,1,INSTRB(p_rpt_month,'-',1,1)-1)) = 'DECEMBER' THEN v_mm := '12';
END CASE;
v_mmyyyy := v_mm||substr(p_rpt_month,INSTRB(p_rpt_month,'-',1,1)+1,4);
--===================================================
-- get the name of user running this procedure
--===================================================
v_user := ' ';
select user into v_user from dual;
--===================================================
-- get date id for the current date
--===================================================
v_date_id := 0;
select date_id into v_date_id from .dwtime5 where DWDATE = trunc(sysdate);
--===================================================
-- read each ROW IN the users TABLE
--===================================================
-- Open the cursor and intialize the active set
Open c_get_USERS_TBL;
-- Retrieve the first row, to setup for the WHILE loop
FETCH c_get_USERS_TBL into c_get_USERS_TBL_row;
-- Continue looping while there are more rows to fetch
WHILE c_get_USERS_TBL%FOUND LOOP
v_div_cd1 := c_get_USERS_TBL_row.div_cd;
v_wrkr_user_id1 := c_get_USERS_TBL_row.wrkr_user_id;
v_rpt_month1 := c_get_USERS_TBL_row.rpt_month;
CASE
WHEN v_div_cd1 <> v_prev_div_cd THEN
v_prev_divcd_userid := v_divcd_userid;
v_divcd_userid := v_div_cd1||v_wrkr_user_id1;
WHEN v_wrkr_user_id1 <> v_prev_wrkr_user_id THEN
v_prev_divcd_userid := v_prev_div_cd||v_prev_wrkr_user_id;
v_divcd_userid := v_div_cd1||v_wrkr_user_id1;
END CASE;
Open c_wrkr_loc_name(v_wrkr_user_id1);
Fetch c_wrkr_loc_name INTO v_wrkr_loc;
IF c_wrkr_loc_name%NOTFOUND THEN
v_wrkr_loc := NULL;
END IF;
Close c_wrkr_loc_name ;
v_seq_id := 0;
select SEQ_USER_ID.nextval into v_seq_id from dual;
INSERT INTO DETAIL_TBL_TEST(DETAIL_PK_ID,
DIVCD_USERID,
WRKR_USER_ID,
WRKR_DSPL_NM,
RPT_MONTH,
USAGE_HOUR,
DIV_CD,
DIV_NM,
WRKR_LOC,
BYTES_RCVD,
BYTES_SENT,
TOTAL_BYTES,
WRKR_PH,
URL,
CREATE_DT,
CREATE_USER,
CREATE_PGM,
UPDATE_DT,
UPDATE_USER,
UPDATE_PGM )
SELECT v_seq_id,
v_divcd_userid,
wrkr_user_id,
wrkr_dspl_nm,
rpt_month,
usage_hour,
div_cd,
div_nm,
v_wrkr_loc,
bytes_rcvd,
bytes_sent,
total_bytes,
wrkr_ph,
url,
SYSDATE,
v_user,
'SP_LOAD_DETAIL_TBL',
SYSDATE,
v_user,
'SP_LOAD_DETAIL_TBL'
FROM FACT_TBL,
DUAL
WHERE DIV_CD = v_div_cd1
AND TRIM(wrkr_user_id) = TRIM(v_wrkr_user_id1)
AND rpt_month = v_rpt_month1
ORDER BY DIV_CD,
WRKR_USER_ID;
v_insert_counter := v_insert_counter + 1;
IF v_insert_counter >= 500 THEN
-- commit changes
COMMIT;
v_insert_counter := 0;
END IF;
FETCH c_get_USERS_TBL into c_get_USERS_TBL_row;
END LOOP;
Close c_get_USERS_TBL;
--===================================================
-- final commit
--===================================================
COMMIT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
DBMS_OUTPUT.PUT_LINE('Attempting to insert a row that already exists!!!');
WHEN OTHERS THEN RAISE;
--END;
--===================================================
-- procedure ended.
--===================================================
END;
Thank you for your help,Seyed
Hello
I guess that the error you receive notice when you were in that sequence was ORA-02287: unauthorized by sequence number. This is because you had the ORDER BY clause in there. If you get rid of it, you can just use the sequence number in the insert without the need first to select it...
With ORDER BY
XXXX> insert
2 into
3 dt_t1
4 SELECT
5 dt_seq.NEXTVAL,
6 SYSDATE
7 FROM
8 dual
9 CONNECT BY LEVEL
10 <=10
11 ORDER BY
12 1
13 /
dt_seq.NEXTVAL,
*
ERROR at line 5:
ORA-02287: sequence number not allowed here
No ORDER OF
XXXX> insert
2 into
3 dt_t1
4 SELECT
5 dt_seq.NEXTVAL,
6 SYSDATE
7 FROM
8 dual
9 CONNECT BY LEVEL
10 <=10
11 /
10 rows created.
Of course, I guess you want a new id for each row, as seems to be the name of the primary key column.
HTH
David
Published by: Bravid on December 19, 2011 16:07
Published by: Bravid on December 19, 2011 16:08
Tags: Database
Similar Questions
-
Error inserting line in the w_etl_run_s table
Hello
I'm below every time error performance DAC. I don't know why it's existing row_wid integration or integration id in the table w_etl_run_s. no idea please advise...
Severity: ERROR
Timestamp: 2011-07-26 10:12:36
Node: node01_hdcbitest
Thread: WRITER_1_ * _1
Process ID: 11304
A message Code: WRT_8229
Message: Database error occurred:
ORA-00001: unique constraint (BIDATA. W_ETL_RUN_S_P1) violated
Database driver error...
Function name: run
Stmt SQL: INSERT INTO W_ETL_RUN_S (DATAMART_ID, DATASOURCE_NUM_ID, DATASRC_ID, INTEGRATION_ID, NAME, NUMERIC_ROW_ID, ROW_WID, ACTUAL_START_TS, LOAD_DT, LOAD_DT_WID, STATUS_CD) VALUES (?,?,?,?,?,?,?,?,?,?,?)
Database driver error...
Name of the function: Execute Multiple
Stmt SQL: INSERT INTO W_ETL_RUN_S (DATAMART_ID, DATASOURCE_NUM_ID, DATASRC_ID, INTEGRATION_ID, NAME, NUMERIC_ROW_ID, ROW_WID, ACTUAL_START_TS, LOAD_DT, LOAD_DT_WID, STATUS_CD) VALUES (?,?,?,?,?,?,?,?,?,?,?)
Gravity: INFO
Timestamp: 2011-07-26 10:12:36
Node: node01_test
Thread: WRITER_1_ * _1
Process ID: 11304
A message Code: CMN_1053
Message: Rowdata: (RowType = 0 (insert) CBC Rowid = Rowid Targ = 1 1
DATAMART_ID (DATAMART_ID:UniChar.15 :): '1')
DATASOURCE_NUM_ID (DATASOURCE_NUM_ID:Double :): "1.000000000000000")
DATASRC_ID (DATASRC_ID:UniChar.15 :): '1')
INTEGRATION_ID (INTEGRATION_ID:UniChar.30 :): "477")
NAME (NAME:UniChar.100 :): "ETL: 26/07/2011-10:12:35 ')
NUMERIC_ROW_ID (NUMERIC_ROW_ID:Double :): "476.0000000000000")
ROW_WID (ROW_WID:Double :): "476.0000000000000")
ACTUAL_START_TS (ACTUAL_START_TS:Date :): '2011-07-26 10:12:35 ')
LOAD_DT (LOAD_DT:Date :): '2011-07-26 10:12:35 ')
LOAD_DT_WID (LOAD_DT_WID:Double :): "20110726.00000000")
STATUS_CD (STATUS_CD:UniChar.50 :): 'How TO')
)Following a note (545761.1) Metalink notes can help:
1 - DO NOT restart an ETL from the beginning when it fails in the middle. Difficulty regardless of the problem, then continue the series where it was stopped.
2 - If do you restart an ETL from the beginning instead of continuing where he left off, you must first delete the record in the table w_etl_run with the status "Running" OR update this record if its status is "completed."If this was helpful, please mark as answered.
-
Insert newspapers in the errors table
Hello
I want to insert errors in the custom error message table.
eventhogh is runs properly but I cannot insert rows in the error table.
This is the code.
DECLARE
v_status VARCHAR2 (20);
cursor c1
is
Select * from all_errors
When type = 'PROCEDURE '.
and name = upper ('updatecourse');
v_rec c1% rowtype;
BEGIN
Select the State
in v_status
of object
where object_type = upper ('PROCEDURE')
and object_name = upper ('updatecourse');
If v_status = "INVALID" Then
Open c1;
loop
Fetch c1 in v_rec;
When exit c1% notfound;
insert into values of error_log (owner, name, type, text) (v_rec.owner, v_rec.name, v_rec.type, v_rec.text);
end loop;
Close c1;
end if;
END;
Please let me know what to do.
Thank you
Rami Reddy.Why a loop?
You can manage in a simple SQL statement... (Not tested, just to give an idea). I hope that you don't have the name of this procedure in the two schemas
insert into error_log(owner,name,type,text) select owner,name,type,text from all_errors where type='PROCEDURE' and name=upper('updatecourse') and 'INVALID' = ( select o.status from all_objects o where o.object_type=upper('PROCEDURE') and o.object_name=upper('updatecourse'); );
-
Insert and update the nested table
Hello
I created a nested table containing the following columns. I need to insert records into the nested table. And also I have to update the nested table. Please find below my table and get error message.
Please advose...!
Can I use '&' while inserting records in the nested table? Yes / No?SQL> create type details as object( 2 basic number(7,2), 3 da number(6,2), 4 hra number(6,2), 5 pf number(6,2), 6 it number(6,2), 7 gross number(7,2), 8 ded number(6,2), 9 net number(8,2)); 10 / Type created. SQL> create type details_t is table of details; 2 / Type created. SQL> ed Wrote file afiedt.buf 1 create table emp_tab(empno number(4),name varchar2(10),details_tab details_t) 2* nested table details_tab store as empl_details SQL> / Table created. SQL> ed Wrote file afiedt.buf 1* insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null))) SQL> / Enter value for empno: 1 Enter value for name: asdf Enter value for da: 120 Enter value for hra: 130 Enter value for pf: 120 Enter value for it: 120 old 1: insert into emp_tab values(&empno,'&name',details_t(details(&da,&hra,&pf,&it,null,null,null new 1: insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null))) insert into emp_tab values(1,'asdf',details_t(details(120,130,120,120,null,null,null))) * ERROR at line 1: ORA-02315: incorrect number of arguments for default constructor
I do need to update also net gross, ded, columns... !!
Please help me... !!
Concerning
A$ sqlplus scott/tiger SQL*Plus: Release 10.2.0.2.0 - Production on Thu Apr 21 16:18:16 2011 Copyright (c) 1982, 2005, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production With the Partitioning, OLAP and Data Mining options SQL> CREATE TYPE details AS OBJECT( basic NUMBER(7,2), da NUMBER(6,2), hra NUMBER(6,2), pf NUMBER(6,2), it NUMBER(6,2), gross NUMBER(7,2), ded NUMBER(6,2), net NUMBER(8,2)); 2 3 4 5 6 7 8 9 10 / Type created. SQL> CREATE TYPE details_t IS TABLE OF details; 2 / Type created. SQL> CREATE TABLE emp_tab(empno NUMBER(4),name VARCHAR2(10),details_tab details_t) NESTED TABLE details_tab store as empl_details 2 3 / Table created. SQL> INSERT INTO emp_tab VALUES(7001,'Saubhik',details_t(details(100,100,50,10,10,null,null,null))); 1 row created. SQL> SELECT * FROM TABLE (SELECT details_tab FROM emp_tab WHERE empno=7001); BASIC DA HRA PF IT GROSS DED ---------- ---------- ---------- ---------- ---------- ---------- ---------- NET ---------- 100 100 50 10 10 SQL> ^C SQL> ed Wrote file afiedt.buf 1 UPDATE TABLE (SELECT details_tab FROM emp_tab WHERE empno=7001) 2 emp_sal 3* SET emp_sal.net=emp_sal.basic+emp_sal.da+emp_sal.hra SQL> / 1 row updated. SQL> SELECT * FRM emp_tab; SELECT * FRM emp_tab * ERROR at line 1: ORA-00923: FROM keyword not found where expected SQL> SELECT * FROM emp_tab; EMPNO NAME ---------- ---------- DETAILS_TAB(BASIC, DA, HRA, PF, IT, GROSS, DED, NET) -------------------------------------------------------------------------------- 7001 Saubhik DETAILS_T(DETAILS(100, 100, 50, 10, 10, NULL, NULL, 250)) SQL>
-
See the empty table if there is no data
Hello
I have a line chart in a dashboard page, which shows sales of the company in a given country (chosen by guest). When I choose a country that has no data, the system displays message: "no results - specified criteria result in all data. I want that in this scenario, appears an empty array. Is it possible? How do I change my application? Thank you
GiancarloOK, in this case, you must change the join in the repository. Let's say you have a table 'months' and a fact table. Join the two tables, but use a right join (where the table is the table with the months). This way, you will get all values in the table of months, associated with the data in the fact table. During these months does not, you will see the value null. You can set a zero with a case statement.
I hope this helps.
J. -. -
Add more than 2 lines for a select statement without inserting rows in the base table
Hi all
I have a below a simple select statement that is querying a table.
Select * from STUDY_SCHED_INTERVAL_TEMP
where STUDY_KEY = 1063;
but here's the situation. As you can see its return 7 ranks. But I must add
2 rows more... with everything else, default or what exist... except the adding more than 2 lines.
I can't insert in the base table. I want my results to end incrementing by 2 days in
measurement_date_Taken on 01-APR-09... so big measurement_date_taken expected to
end at study_end_Date...
IS IT STILL POSSIBLE WITHOUT INSERT ROWS IN THE TABLE AND PLAYIHY ALL AROUND WITH
THE SELECT STATEMENT?
Sorry if this is confusing... I'm on 10.2.0.3
Published by: S2K on August 13, 2009 14:19Well, I don't know if this request is as beautiful as my lawn, but seems to work even when ;)
I used the "simplified" version, but the principle should work for your table, S2K.
As Frank has already pointed out (and I fell on it while clunging): simply select your already existing lines and union them with the 'missing documents', you calculate the number of days that you are "missing" based on the study_end_date:MHO%xe> alter session set nls_date_language='AMERICAN'; Sessie is gewijzigd. Verstreken: 00:00:00.01 MHO%xe> with t as ( -- generating your data here, simplified by me due to cat and lawn 2 select 1063 study_key 3 , to_date('01-MAR-09', 'dd-mon-rr') phase_start_date 4 , to_date('02-MAR-09', 'dd-mon-rr') measurement_date_taken 5 , to_date('01-APR-09', 'dd-mon-rr') study_end_date 6 from dual union all 7 select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('04-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 8 select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('09-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 9 select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('14-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 10 select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('19-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 11 select 1063, to_date('22-MAR-09', 'dd-mon-rr') , to_date('23-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all 12 select 1063, to_date('22-MAR-09', 'dd-mon-rr') , to_date('30-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual 13 ) -- actual query: 14 select study_key 15 , phase_start_date 16 , measurement_date_taken 17 , study_end_date 18 from t 19 union all 20 select study_key 21 , phase_start_date 22 , measurement_date_taken + level -- or rownum 23 , study_end_date 24 from ( select study_key 25 , phase_start_date 26 , measurement_date_taken 27 , study_end_date 28 , add_up 29 from ( 30 select study_key 31 , phase_start_date 32 , measurement_date_taken 33 , study_end_date 34 , study_end_date - max(measurement_date_taken) over (partition by study_key 35 order by measurement_date_taken ) add_up 36 , lead(measurement_date_taken) over (partition by study_key 37 order by measurement_date_taken ) last_rec 38 from t 39 ) 40 where last_rec is null 41 ) 42 where rownum <= add_up 43 connect by level <= add_up; STUDY_KEY PHASE_START_DATE MEASUREMENT_DATE_TA STUDY_END_DATE ---------- ------------------- ------------------- ------------------- 1063 01-03-2009 00:00:00 02-03-2009 00:00:00 01-04-2009 00:00:00 1063 03-03-2009 00:00:00 04-03-2009 00:00:00 01-04-2009 00:00:00 1063 03-03-2009 00:00:00 09-03-2009 00:00:00 01-04-2009 00:00:00 1063 03-03-2009 00:00:00 14-03-2009 00:00:00 01-04-2009 00:00:00 1063 03-03-2009 00:00:00 19-03-2009 00:00:00 01-04-2009 00:00:00 1063 22-03-2009 00:00:00 23-03-2009 00:00:00 01-04-2009 00:00:00 1063 22-03-2009 00:00:00 30-03-2009 00:00:00 01-04-2009 00:00:00 1063 22-03-2009 00:00:00 31-03-2009 00:00:00 01-04-2009 00:00:00 1063 22-03-2009 00:00:00 01-04-2009 00:00:00 01-04-2009 00:00:00 9 rijen zijn geselecteerd.
Is there a simpler way (in SQL), I hope that others join, and share their ideas/example/thoughts.
I feel that it is using more resources there.
But I have to cut the daisies before now, they interfere my 'grass-green-ess";) -
How can I do a new insert data in the other table extrancting?
Hello, I'm looking how to do an insertion of two tables save values and apply to other tables like this:
The insert I'm looking for is something like this:
Have two tables, the first table is emp1 and contains the column: data 1 and 2 with line of data1: 1234 and line data 2:5555, therefore,.
I want to create an insert on a new table called (emp2) that contain the data in the column: data 1, data 2 (from the first table demo1), data 3, data 4, etc.
How insert again I can put / call data from another table insert in this table (emp2).
I don't know if my example is correct (my English is very bad).
This is an example: (sorry for the points).
table EMP2:
1 data... 2 data... 3 data... data 4... data 5
(from emp1)... (from emp1)... 8534... 2347... 4544
Thanks for the help.
Published by: user10182692 on 24-May-2009 08:39
Published by: user10182692 on 24-May-2009 08:40
Published by: user10182692 on 24-May-2009 08:45Welcome! on the forum.
You can include the code and data in the {code} tags
If I'm good, and I know what is your condition
insert into emp2 ( data1, data2) select data1, data2 from emp1
SS
-
Insert select on the same table: possible without side effects?
I have a very large table T1 containing millions of records. I need to treat its lines and create a few new lines based on selection.
Table T1 contains events and one of them, with the code 100, is created by the further development of other events inside the table.
My code is as follows:
insert /*+append */ into T1 (code,...) values (100, c1,c2,...) select c1,c2... from T1 where (code=20 or code=10) and <other conditions>...
as you can see I'm extract T1 lines to insert again in T1 with a different code and I use the direct path in order to get good performance.
My fear is: choose is made from the same table I risk data loss? In general it is a good practice? Or is it better to create another table?
Hello
No I don't think that there may be loss of data. But that may depend on the behavior of the application and your where clause.
I will explain how it is treated, so you can see if it's ok:
1. the table is locked because of the insert add, (as)
2 lines are read by select and make compatible from the State that was at the beginning of the query - 1.
3 rows are inserted at the end, after the high-water line
4 columns for new lines are sorted to be merged in the index
5. high watermark is adjusted - visible new lines and lock is released
Note that 2. and 3. occur at the same time: rows are inserted all read.
Note that anyone can choose in the table during the operation - they see the changes committed only - if the State 1.
all other DML are waiting for the lock being released, and will see new ranks and then
If you have things that prevent the direct-path insert, append the hint will be ignored. So, if you must rely on close to 1. then the best lock explicitly with table lock. But I don't think that you need.
Kind regards
Franck.
-
Insert data into the same table based on certain conditions
Hello. I'm new to this forum.
I have to write a stored procedure to insert data in a table MYTABLE say, having a structure like:
Col1 Col2 Col3... TotalInstallments CurrentInstallment PaidAmount MonthYear
I have to insert all the data that it is in the same table (MYTABLE) except change some fields based on certain conditions:
1. if PaidAmount > 0 & & CurrentInstallment < TotalInstallment then
CurrentInstallment = CurrentInstallment + 1
2. in the field MonthYear I have data ex. 01/2012, 11/2012 formate(month/year)...
So, I have to insert data by incrementing the month and year. for example:
If currentdata is 11/2012 next data will be 12/2012
But following will be 01, 2013
I have to select all records that belongs to the previous month (across the field MonthYear) and put the audit on each record selected and insert data and then turns them into table (MYTABLE) even.
How to achieve that?
Thank you.978184 wrote:
Hello. I'm new to this forum.
I have to write a stored procedure to insert data in a table MYTABLE say, having a structure like:Col1 Col2 Col3... TotalInstallments CurrentInstallment PaidAmount MonthYear
I have to insert all the data that it is in the same table (MYTABLE) except change some fields based on certain conditions:1. if PaidAmount > 0 & CurrentInstallment
CurrentInstallment = CurrentInstallment + 1
2. in the field MonthYear I have data ex. 01/2012, 11/2012 formate(month/year)...
So, I have to insert data by incrementing the month and year. for example:
If currentdata is 11/2012 next data will be 12/2012
But following will be 01, 2013
I have to select all records that belongs to the previous month (across the field MonthYear) and put the audit & on each of the selected data record and insert then turns them into table (MYTABLE).You can do this way:
This is not tested, but if you can provide the example of table structure and data (IN create table and insert scripts), it can be put to the test.
insert into your_table (col1, col2, col3...current_installment, month_field) select col1, col2, col3.., current_installment + case when paidamount > 0 and current_installment < total_installment then row_number() over ( partition by column1, column2,.. columnn -->You may choose partition if you want the --Increment of Current_installment to reset after particular combination ends order by primary_key -->Order the Increment, you may choose to add more columns to order by ) else 0 --> if condition is not met, then Add 0 end curr_installment, add_months(to_date(month_field, 'MM/YYYY'), 1) nxt_month from your_table;
-
Insert records in the W_EXCH_RATE_G table.
Hi all
Can someone help me with the following scenario.
I would like to know how to insert additional record of exchange rates in the W_EXCH_RATE_G table in the data warehouse.
I checked records in this table ate PS_RT_RATE_TBL of peoplesoft.
But I have just a flat file and I have to complete additional registration.
Can you let me know if I have to use and update the query to do the same thing or do I change the mapping in Informatica?
Thanks for the help in advance!
-NikkiNikki, see also my response to your similar message: -.
Change SIL_GLBalanceFact to populate the Balance_Global1_Amt column.
Please indicate if helpful/useful.
Andy. -
cannot insert data into the PRODUCT_USER_PROFILE table
I've connected to the database as the sysdba, which is installed on VMWARE. database is oracle 11g.
whenever I insert data in the table PRODUCT_USER_PROFILE that the database returns 1 row inserted and then when I try to show everything on the table before or after the statement commit is made the database returns "No. LINES SELECTED.
guys any idea about this problem...Hello
Try to connect as a system and make the insert and check. Always think about the issue.
-Pavan Kumar N
Oracle 9i / 10g - OCP
http://oracleinternals.blogspot.com/Published by: pounet on January 4, 2010 16:29
-
Support for mandatory request - insert, select from the same table
Hi all
I need your help to write queries effectively.
Oracle Version: 10.2.0.3.0
OPERATING SYSTEM: UNIX
I have a METRICS_TBL that is mentioned below table.
CYCLE_DATE METRIC VALUE
08/17/2008 COST-TV 100
08/17/2008 COST-JOURNAL 50
08/17/2008 COST-POSTALMAIL 25
08/17/2008-PROD-TV 10
08/17/2008-PROD-JOURNAL 25
08/17/2008-PROD-POSTALMAIL 5
Any data above, I have to add (Insert into select METRICS_TBL METRICS_TBL) at the same table with the records as mentioned below.
2008-08-17 COSTPERPROD-TV 10
08/17/2008-COSTPERPROD-LOG 2
2008-08-17 COST PROD-POSTALMAIL 5
Basically, I need to calculate the cost per product for each category. Depending on the settings available, metric should also be changed as COSTPERPROD and values should be cost/prod under each category.
Can someone help me with the query.
Thank youSomething like this:
INSERT INTO metrics_tbl (cycle_date, metrics, value) SELECT cost.cycle_date , 'COSTPERPROD-'||cost.mtype ,cost.value / prod.value FROM ( select cycle_date,substr(metrics, 1, 4) mtype, substrmetrics,instr(metrics,'-')+1) mmetric where substr(metrics, 1, 4) = 'PROD' ) prod INNER JOIN ( select cycle_date,substr(metrics, 1, 4) mtype, substrmetrics,instr(metrics,'-')+1) mmetric where substr(metrics, 1, 4) = 'COST' ) cost on cost.cycle_date = prod.cycle_date and cost.mmetric = prod.mmetric
Ideally you would divide your METRICS column into two: one for the thing you're measuring (e.g. TV or NEWSPAPER) and the other for the metric (COST, PROD, COSTPERPROD etc.). That's what I did in the views online. Without it, it's kinda a mess and behave so, if the table becomes much more.
HTH
Nigel cordially
Edited by: nthomas on January 14, 2009 15:57 - small correction SQL
-
Inserting data in the PLSQL table
Hello
I'm trying to create a table of records and try to insert some data into it. But it is throwing error when compiling. Can someone help me solve the problem. My procedure is:
create or replace
procedure 'IL_BAL_CAL_PROC' is
type il_bal_cal_acc_tab_rec is record (GID_NO VARCHAR2 (4), REG_CODE VARCHAR2 (2), VAC VARCHAR2 (10), BRANCH_CODE VARCHAR2 (4), CTL VARCHAR2 (4), OPEN_DT DATE, RECORD_STAT VARCHAR2 (1), CLOSE_DT DATE);
type il_bal_cal_acc_tab_type is table of the il_bal_cal_acc_tab_rec;
il_bal_cal_acc_tab il_bal_cal_acc_tab_type:=il_bal_cal_acc_tab_type();
BEGIN
-first approach
insert into il_bal_cal_acc_tab values('12');
--deuxieme approach
/ * Insert in il_bal_cal_acc_tab
Select p_gidno,
p_region,
a.ACC,
a.brncd,
a.CCY,
a.accopendt,
a.record_stat,
NULL as closdt
stvws_cust_account_if a.,
b stvws_branch_dates,
sttms_account_class c,
sttms_dda_maininfo d
where a.acc = d.customer_account
and a.brncd = b.branch_code
and b.branch_code = d.branch_code
and a.account_class = c.account_class
and a.accopendt < trunc (to_date(b.today,'dd-mon-yy'), 'mm')
and a.record_stat = 'O'
and I'm c.dda_account_type <>'
and a.auth_stat = 'A'
and d.region_code = p_region
Union
Select p_gidno,
p_region,
a.ACC,
a.brncd,
a.CCY,
a.accopendt,
a.record_stat,
c.closdt
stvws_cust_account_if a.,
b stvws_branch_dates,
stvws_cust_ac_closure_if c,
sttms_dda_maininfo d
where a.acc = c.ac_no
and c.ac_no = d.customer_account
and a.brncd = b.branch_code
and b.branch_code = c.branch_code
and c.branch_code = d.branch_code
and a.record_stat =' it
and c.closdt > = trunc (b.today, 'mm')
and d.region_code = p_region;
commit; * /
END;
Please tell me how to insert data into tables of this kind?I generally do like this
CREATE OR REPLACE PROCEDURE "IL_BAL_CAL_PROC" IS CURSOR cur_il_bal_cal_acc_tab_type IS SELECT p_gidno, p_region, a.acc, a.brncd, a.ccy, a.accopendt, a.record_stat, NULL AS closdt FROM stvws_cust_account_if a, stvws_branch_dates b, sttms_account_class c, sttms_dda_maininfo d WHERE a.acc = d.customer_account AND a.brncd = b.branch_code AND b.branch_code = d.branch_code AND a.account_class = c.account_class AND a.accopendt < TRUNC (TO_DATE (b.today, 'dd-mon-yy'), 'mm') AND a.record_stat = 'O' AND c.dda_account_type <> 'M' AND a.auth_stat = 'A' AND d.region_code = p_region UNION SELECT p_gidno, p_region, a.acc, a.brncd, a.ccy, a.accopendt, a.record_stat, c.closdt FROM stvws_cust_account_if a, stvws_branch_dates b, stvws_cust_ac_closure_if c, sttms_dda_maininfo d WHERE a.acc = c.ac_no AND c.ac_no = d.customer_account AND a.brncd = b.branch_code AND b.branch_code = c.branch_code AND c.branch_code = d.branch_code AND a.record_stat = 'C' AND c.closdt >= TRUNC (b.today, 'mm') AND d.region_code = p_region; TYPE il_bal_cal_acc_tab_type IS TABLE OF cur_il_bal_cal_acc_tab_type%ROWTYPE INDEX BY BINARY_INTEGER; il_bal_cal_acc_tab il_bal_cal_acc_tab_type; BEGIN OPEN cur_il_bal_cal_acc_tab_type; FETCH cur_il_bal_cal_acc_tab_type BULK COLLECT INTO il_bal_cal_acc_tab; CLOSE cur_il_bal_cal_acc_tab_type; END;
-
Inserting data in the nested table
I explore the differences between the OBJECT and RECORD.
As I'm still learning, I found that both are structures which essentially brings together different elements of types of different data or columns of data types, one is used in SQL and other is used in PL/SQL, please correct me if I'm wrong in my understanding.
Below, I am trying to insert data into an array of type object, but I can't can you please help.
CREATE OR REPLACE type sam as OBJECT ( v1 NUMBER, v2 VARCHAR2(20 CHAR) ); ---Nested Table--- create or replace type t_sam as table of sam; --Inserting data---- insert into table(t_sam) values(sam(10,'Dsouza'));
Error message:
Error starting at line 22 in command: insert into table(t_sam) values(sam(10,'Dsouza')) Error at Command Line:22 Column:13 Error report: SQL Error: ORA-00903: invalid table name 00903. 00000 - "invalid table name" *Cause: *Action:
Ariean wrote:
So the only purpose of the equivalent concept of SQL types of nested tables is to use one of the data types when you define an actual table?
So-you can certainly use more that a simple "set an actual table. (I'm fairly certain that you can pass a table nested within a procedure, for example - try it, though - I'm not 100% sure on that - it just 'logic'.) If you can define a type, you can use it, pass it around, whatever.).
Ariean wrote:
And this nested table could be a record in SQL or object in PLSQL or simple data type (varchar number, etc.)?
Nested tables are just like any other type of custom data. You can create a nested table of other types of data. You can create a custom of nested tables data type.
Stupidly, he could become... uh, stupid O_0
CREATE TYPE o_myobj1 AS object ( id1 number, cdate1 date ); CREATE TYPE t_mytype1 AS table of o_myobj1; CREATE TYPE o_myobj2 AS object ( id2 number, dumb t_mytype1 ); CREATE TYPE t_dumber AS table of o_myobj2;
O_0
OK, my brain is starting to hurt - I hope you get the idea
Ariean wrote:
Second is my understanding correct any OBJECT & RECORD?
I see no benefit to describe another way.
-
Domain! = Insert then in the other Table
Hello
I can't figure out how to create a trigger that inserts data based on cases an old.field! = new.field. If the field has been changed to
a tbl_test table then insert this file into the other tbl_test_history of the table. It's a little different since I want to insert a record if an update
has taken place. The update will still take place at tbl_test, but I want an insert will be held at tbl_test_history.
I have a separate trigger that will insert records from tbl_test to tbl_test_history. This trigger compiles without error but when ICREATE OR REPLACE TRIGGER AU_INSERT_TEST_HISTORY AFTER UPDATE ON TBL_TEST FOR EACH ROW WHEN ( OLD.Orange != NEW.Orange OR OLD.Apple != NEW.Apple ) BEGIN INSERT INTO TBL_TEST_HISTORY (ORANGE, APPLE BANANA, GRAPE ) select ORANGE, APPLE BANANA, GRAPE FROM TBL_TEST, TBL_TEST_HISTORY WHERE TBL_TEST.PK_TEST_ID = TBL_TEST_HISTORY.PK_TEST_ID; END AU_INSERT_TEST_HISTORY; /
create a record in tbl_test I have an error message. I don't know if the syntax is correct, can someone help me with this?My bad. I put the colon: in the when clause. They were not there in your code. I usually use an if condition, which is a little different.
I added a NEW logic to also consider the comparison of NULL values.
CREATE OR REPLACE TRIGGER AU_INSERT_TEST_HISTORY AFTER UPDATE ON TBL_TEST FOR EACH ROW BEGIN if nvl(:old.ORANGE,'xxx') != nvl(:new.ORANGE,'yyy') OR nvl(:old.APPLE,'xxx') != nvl(:new.APPLE,'yyy') then INSERT INTO TBL_TEST_HISTORY (ORANGE, APPLE, BANANA, GRAPE) values (:new.ORANGE, :new.APPLE, :new.BANANA, :new.GRAPE); end if; END AU_INSERT_TEST_HISTORY; /
In addition, you can consider making trigger a trigger AFTER INSERT or UPDATE.
Then you would also put the values inserted early in your history table.
Published by: Sven w. August 9, 2012 16:14
Maybe you are looking for
-
Is it safe to delete the original score after successful cloning?
I have a Mac mini mid2010. I swapped his optical drive to an SSD. Then I cloned the operating system partition and everything works perfectly. My question is whether it is safe to delete the original "Macintosh HD" that I cloned, or if there is a way
-
Disabled AGP on Satellite L40 - 14n
Hi all! I have Toshiba Satellite L40 - 14n. When I try to run any game, I see the following message "the game may not be coherent agp is off." Please enable agp for consistency. Tell me please how I can do this.
-
the LAST_VALUE function and forecasts
Dear gurus,I need to return a result set with the last value from the last date of my contracts, table of projects; that later, I'll have to use this game to project values for the months remaining of my earnings forecasts.I don't seem to be getting
-
Hoe kan ik mijn opzeggen zonder 150 euro box subscription?
IK heb per ongeluk en zonder dat ik dat kan een verlegd naar een jaarabonnement subscription staying recovering. DAT kost 30,24 euro per month. DAT vind ik you veel voor hoe ik Adobe-our use. Hoe kan ik mijn Adobe-CC opzeggen zonder dat ik 150 euro b
-
I need to reactivate my photoshop CS3
I installed the new Windows 10 and when I opened my old Photoshop CS3 Extended-he asked to reactivate the software, but I couldn't achieve through the internet so I have to do it by phone, but using phone activation is no longer available, what shoul