Trap update error for insert!
Hi, I have a table approx 2 million records which is updated daily from a staging table that is loaded from file. It's taking approx 7 hours as it searches for a record and if it exists, otherwise it inserts.
I was thinking that a faster method would be to bulk collect and update, then trap the error if the record to be updated doesn't exist, and insert the record.
I'm on Oracle 8i.
Question: Would this be the most efficient way to perform the task?
If so would anyone out there have some sample code to do it?
Your help would be very much appreciated.
Hi,
There's only one constraint on the target:
CREATE UNIQUE INDEX XPKGMENT_V ON GMENT_V
(DATE_START, DATE_END, ORI, FNUMBER,
CLASS_CD, DOW)
CURSOR cur IS
SELECT BEG_DATE,
END_DATE,
FNUMBER,
ORIG,
CLASS_CD,
DATA_TYPE_CD,
DOW,
TTC,
PSEUDO,
PRORATE
FROM stage_gment_v;
rec cur%rowtype;
rowcount number(7);
row_exists number(1);
BEGIN
OPEN cur;
rowcount := 0;
row_exists := 0;
LOOP
FETCH cur INTO rec;
EXIT WHEN cur%NOTFOUND;
rowcount := rowcount + 1;
row_exists := 0;
BEGIN
SELECT 1 INTO row_exists
FROM gment_v r
WHERE r.date_start = rec.beg_date
AND r.orig = rec.orig
AND r.class_cd = rec.class_cd
AND ( r.dow = rec.dow
OR ( rec.dow IS NULL AND r.dow IS NULL) )
AND ( r.fnumber = rec.fnumber
OR ( rec.fnumber IS NULL AND r.fnumber IS NULL));
EXCEPTION
WHEN NO_DATA_FOUND THEN
row_exists := 0;
END;
-- update if a row already exists
IF ( row_exists = 1 ) THEN
UPDATE gment_v r
SET TTC = rec.ttc,
PSEUDO = rec.pseudo,
PRORATE = rec.prorate
WHERE r.date_start = rec.beg_date
AND r.orig = rec.orig
AND r.class_cd = rec.class_cd
AND ( r.dow = rec.dow
OR ( rec.dow IS NULL AND r.dow IS NULL) )
AND ( r.fnumber = rec.fnumber
OR ( rec.fnumber IS NULL AND r.fnumber IS NULL));
updates := updates +1;
ELSE
-- create if does not exist already
INSERT INTO gment_v(
DATE_START,
DATE_END,
FNUMBER,
ORIG,
CLASS_CD,
DATA_TYPE_CD,
DOW,
TTC,
PSEUDO,
PRORATE)
VALUES ( rec.beg_date,
rec.end_date,
rec.fnumber,
rec.orig,
rec.class_cd,
rec.data_type_cd,
rec.dow,
rec.ttc,
rec.pseudo,
rec.prorate) ;
END IF;
END LOOP;
Similar Messages
-
Update errors for cs5 web premium (Mac)
Trying to do updates for cs5 web premium (Mac) but getting an update error. Support Chat said I had to ask in here. I am not getting a serial number prompt. I have registered my product already.
Kann keiner wissen. Keine Systeminfo, keine Install Logs.
Troubleshoot with install logs | CS5, CS5.5, CS6, CC
Mylenium -
SPAM update Error for patch level 42 on 7.01
Hi all,
While applying SPAM update 42 for 7.01, we received the error below. We also tried to apply a lower version with the same results. Your help is appreciated.
Class CL_OCS_RT_ANALYSIS,Method GET_XML
The row type of the table "ME->T_PATRTVERS" is not compatible with
field symbol type "<FS_PATRTVERS>".
from ST22:
Runtime Errors SYNTAX_ERROR
Date and Time 10/10/2011 05:16:00
Short text
Syntax error in program "CL_OCS_RT_ANALYSIS============CP ".
What happened?
Error in the ABAP Application Program
The current ABAP program "SAPLSPAM" had to be terminated because
it has
come across a statement that unfortunately cannot be executed.
The following syntax error occurred in program
"CL_OCS_RT_ANALYSIS============CP " in include
"CL_OCS_RT_ANALYSIS============CM002 " in
line 67:
"The row type of the table "ME->T_PATRTVERS" is not compatible
with fie"
"ld symbol type "<FS_PATRTVERS>"."
Thanks,
DomenickDear Domenick,
This issue you are facing is most probably because of a force reset of SPAM queue in IMPORT_PROPER phase.
You might have reset the queue forcibly which has created inconsistency in the system and has destoyed SPAM transaction
related program sources.
Now in order to resolve this you can try out a small fix.
You can pick up the class/interface CL_OCS_RT_ANALYSIS============CP from a system which has already been patched with SAPKD70142. You can transport this class to the affected system.
Once done, try to do the SPAM import. If the SPAM import is successfull it is fine.
If it not successfull, there is no other way apart from restoring the sytem since the SPAM sources are corrupt.
Best Regards,
Abhishek -
JDBC Receiver adapter Error for insert into DB2 table
Hi all,
I want to insert data into a DB2 table on AS400 via a Receiver JDBC adapter.
The communication channel seems to be ok but when I try to send the message, I obtain the following message on the adapter monitoring :
Error: TransformException error in xml processor class, rollback:
Error processing request in sax parser: Error when executing statement for table/stored proc. 'GIK.GDT01' (structure 'Statement'): java.sql.SQLException: La table GDT01 de la bibliothèque GIK est incorrecte pour cette opération.
Could someone help me?
In the communication channel I have seen we can choose "native SQL String" as message protocol.
Do you think it could be a workaround for me? if yes, could someone send me an example about it?
thanks a lot,
PhilippeHi,
Try to remove GIK.GDT01 in table tag of your XML structure and put GDT01 alone and see.
The solution to your problem is found on this particular link.
http://www.websina.com/bugzero/faq/exception-as400.html
Tell me if it works
Best regards,
Felix -
Result Set Update error for Timestamp
Hi,
I am using Oracle 9i DB with JBDC 2.0. I want to update a record present in a Resultset. Two fields are updated from this resultset. One is string and other is timestamp. Both these fields are present in select clause of the statement. The string field is updated (String.updateString(<field name>, value)) properly in to DB (Resultset.updateRow()). But if i include timestamp field for update (Resultset.updateTimestamp(<field name>, value)), it gives me error on this line.
Error message is as given below
java.sql.SQLException: Internal Error: Unable to construct a Datum from the specified input
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1130)
at oracle.sql.SQLUtil.makeDatum(SQLUtil.java:1100)
at oracle.sql.SQLUtil.makeOracleDatum(SQLUtil.java:1583)
at oracle.jdbc.driver.UpdatableResultSet.updateObject(UpdatableResultSet.java:1615)
at oracle.jdbc.driver.UpdatableResultSet.updateTimestamp(UpdatableResultSet.java:1492)
at oracle.jdbc.driver.OracleResultSet.updateTimestamp(OracleResultSet.java:2881)
If the timestamp update line is commeted then code work fine. Resultset.updateDate() is also working, but not Resultset.updateTimestamp();
Regards,
JayeshKshitiz & Jayesh,
Well, it works for me.
I ran Jayesh's "TestTimestamp" class (slightly modified) on a Windows XP machine with JDK 1.4.2_07 using "ojdbc14.jar" as the JDBC driver.
I created (and populated) the EMP table, as per Jayesh's instructions, on a Oracle 9.2.0.4 database running on SUN [sparc] Solaris 9.
Here is my code:
import java.sql.*;
public class TestTimestamp {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@host:1521:orcl",
"scott",
"tiger");
// connection.setAutoCommit(false);
ps = conn.prepareStatement("select EMPID,NAME,JOINDATE,JOINTS from EMP",
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs = ps.executeQuery();
System.out.println("EMDID NAME JOIN DATE JOIN TS");
while (rs.next()) {
System.out.print(rs.getInt("EMPID"));
System.out.print(" " + rs.getString("NAME"));
System.out.print(" " + rs.getDate("JOINDATE"));
System.out.println(" " + rs.getTimestamp("JOINTS"));
rs.updateTimestamp("JOINTS",
new Timestamp(System.currentTimeMillis())); //THIS WILL CREATE PROBLEM
rs.last();
catch (Exception e) {
e.printStackTrace(System.err);
finally {
if (rs != null) {
try {
rs.close();
catch (SQLException sqlEx) {
System.err.println("Failed to close 'Resultset'");
sqlEx.printStackTrace(System.err);
if (ps != null) {
try {
ps.close();
catch (SQLException sqlEx) {
System.err.println("Failed to close 'PreparedStatement'");
sqlEx.printStackTrace(System.err);
if (conn != null) {
try {
conn.close();
catch (SQLException sqlEx) {
System.err.println("Failed to close 'Connection'");
sqlEx.printStackTrace(System.err);
}And here is my output:
EMDID NAME JOIN DATE JOIN TS
6001 Jayesh 2021-12-03 2021-12-03 09:00:00.0
6002 Krupa 2021-12-03 2021-12-03 09:00:00.0
6003 Vinod 2021-12-03 2021-12-03 09:00:00.0
6004 Dylan 2021-12-03 2021-12-03 09:00:00.0Good Luck,
Avi. -
Ess wda: updating Iban for insert/copy/modify in bank detail screen for germany
Hi,
We are using standard detail screen HRESS_CC_PER_DTL_BANK_DE for Germany, We have observed that even if the user changes/updates/creates the new record without filling Iban field system will not throw any error which is correct as per V_T588MFPROPC as we have not made it mandatory. but we have an option to populate Iban using specific button in PA30, can we have the same functionality in ESS? Can we implement HRPAD00INFTYDB for this purpose? Is there any other option for this functionality?
Thank you,
Krishna kishore T.I can solve this issue implementing the BAdI HRPAD00INFTYDB
Summary of configuration options in ESS Personal Information scenario
Regards -
PO updation error for Requisitions (BANFN ) and Item (BNFPO) fields
Dear Friends,
I am updating the Requisitions (BANFN ) and Item (BNFPO) fields via ME22N with using BDC for my PO.
But I am getting the following error when I have checked in my session .the error is
" PO item cannot be retrosp. converted into order-dependent 3rd-party item "
What does it mean?
Thanks,
Sridhar Reddy.Hi Shanti,
What is the error message returned by the BAPI? you can have a look at the RETURN internal table, there you will find all errors passed by the BAPI.
To change the limit value of the PO you can use the following steps:
1. Declare the PO limit internal table:
t_polimit TYPE STANDARD TABLE OF bapiesuhc WITH HEADER LINE
2. Set the limit value of the PO:
t_polimit-limit = the desired LIMIT_VALUE
t_polimit-exp_value = the desired EXPECTED_VALUE
append t_polimit.
3. Call the BAPI and pass the limit internal table
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = g_purchaseorder
poheader = wa_poheader
poheaderx = wa_poheaderx
testrun = g_testrun
memory_uncomplete = g_memory_uncomplete
memory_complete = g_memory_complete
no_messaging = g_no_messaging
no_message_req = g_no_message_req
no_authority = g_no_authority
no_price_from_po = g_no_price_from_po
TABLES
return = t_bapi_return
poitem = t_poitem
poitemx = t_poitemx
polimits = t_polimit
EXCEPTIONS
OTHERS = 1.
If you pass the correct header value for the PO it should be updated accordingly.
Edited by: Fandi Kusmawardi on Mar 26, 2008 9:38 AM -
Update Error for Illustrator CC
I am regularly holder of a license for Illustrator CC. I downloaded the program but I can not install the 'latest update. I will signal error. My name is Angelo Morelli and since I pay you regularly have the right to have this update. If one could speak Italian would be much easier, but it is possible to communicate with you and also with difficulties in English only, solve the problem, thanks. Do you know this news to this e mail: possibly in Italian: angelo.morelli @ live.it
Have you already read through this page?
http://helpx.adobe.com/it/creative-cloud/help/install-apps.html
Also this forum might help quicker:
http://forums.adobe.com/community/download_install_setup
Please show a screenshot of the error.
There might be people who can either read or at least guess the meaning of it. -
I own a lumia 920. today i have been updated my phone for the Lumia black. After the update has been downloaded it has been installed also... But something went unexpected... Downloaded file can't be opened and a error has displayed with some code...
what happened and why this error has been occurred..?Hi, what's the status of the phone now? Did you manage to update the phone to Black or are you still getting the error upon installing it?
-
Javascript error for Inserting Pages from a source
Below is a script I wrote that isn't functioning properly on my large 200 page document that I need it to. Granted there might be a much easier way to script this, but I'm no expert. I have a 200 page document that needs to be 600 pages, basically every page needs to be copied twice (and obviously placed right after the original. So I have the original PDF, then I copied that PDF to use as a source document to copy from. (To clarify if I'm not being clear, the first 3 pages would be page 1, 2, 3,... it needs to be: 1,1,1,2,2,2,3,3,3 etc)
var targetpage = 0;
var sourcepage = 0;
while(sourcepage < 199)
this.insertPages({
nPage: targetpage,
cPath: "source.pdf",
nStart: sourcepage,
nEnd: sourcepage
targetpage++;
this.insertPages({
nPage: targetpage,
cPath: "source.pdf",
nStart: sourcepage,
nEnd: sourcepage
sourcepage++;
targetpage=targetpage+2;
It gives me an error that I have no idea means, nor how to correct after only placing a total of 3 pages - so the doc went from 200 to 203 (2 of page 1 as intended, then 1 page of page 2, then for some reason it stops...
InvalidArgsError: Invalid arguments.
Doc.insertPages:9:Batch undefined:Exec
Why is it stopping? And please don't assume I know what I'm doing Thank you.Have you read the Acrobat JS API Reference about the insertPages and the path value and restrictions?
insertPages now needs to use the "privileged context" when not being run as a console or batch event.
Safe path
Acrobat 6.0 introduced the concept of a safe path for JavaScript methods that write data to the local hard drive based on a path passed to it by one of its parameters.
A path cannot point to a system critical folder, for example a root, windows or system directory. A path is also subject to other unspecified tests.
For many methods, the file name must have an extension appropriate to the type of data that is to be saved. Some methods may have a no-overwrite restriction. These additional restrictions are noted in the documentation.
Generally, when a path is judged to be not safe, a NotAllowedError exception is thrown (see Error object) and the method fails. -
Update error for CC and CS6 in the cloud and in the program. says (49) after it
Please help! I have tried uninstalling, reinstalling etc to no avail. lightroom updated properly
getting download error 49 bridge CC may help
-
Errors when inserting and updating form using VIEW.
Here's my view:
CREATE OR REPLACE FORCE
VIEW "SH_ADD_EMPLOYEES_VW" ("EMP_ID", "DEPT_ID", "JOB_DESC_ID", "EMPNO", "EMP_FIRST", "EMP_LAST", "USER_NAME", "USER_INI", "DEPTNO", "DEPT_DESC", "ROLES_ID", "ADMIN", "CREATES", "APPROVES", "QUALITY", "CUST_SVC", "SH_LOCAL",
"SH_OFFICE", "SYSTEM")
AS
select
"SH_EMPLOYEES"."EMP_ID" as "EMP_ID",
"SH_EMPLOYEES"."DEPT_ID" as "DEPT_ID",
"SH_EMPLOYEES"."JOB_DESC_ID" as "JOB_DESC_ID",
"SH_EMPLOYEES"."EMPNO" as "EMPNO",
"SH_EMPLOYEES"."EMP_FIRST" as "EMP_FIRST",
"SH_EMPLOYEES"."EMP_LAST" as "EMP_LAST",
"SH_EMPLOYEES"."USER_NAME" as "USER_NAME",
"SH_EMPLOYEES"."USER_INI" as "USER_INI",
"SH_EMPLOYEES"."DEPTNO" as "DEPTNO",
"SH_EMPLOYEES"."DEPT_DESC" as "DEPT_DESC",
"DOC_ROLES"."ROLES_ID" as "ROLES_ID",
"DOC_ROLES"."ADMIN" as "ADMIN",
"DOC_ROLES"."CREATES" as "CREATES",
"DOC_ROLES"."APPROVES" as "APPROVES",
"DOC_ROLES"."QUALITY" as "QUALITY",
"DOC_ROLES"."CUST_SVC" as "CUST_SVC",
"DOC_ROLES"."SH_LOCAL" as "SH_LOCAL",
"DOC_ROLES"."SH_OFFICE" as "SH_OFFICE",
"DOC_ROLES"."SYSTEM" as "SYSTEM"
FROM "SH_EMPLOYEES" "SH_EMPLOYEES", "DOC_ROLES" "DOC_ROLES"
where "SH_EMPLOYEES"."EMP_ID" = "DOC_ROLES"."EMP_ID"
Here's my trigger (note - I am not using the EXCEPTION clause or (declaration of it) because it throws an error on msg=>: 'This is my message.' Any help here would be great as well.)
CREATE OR REPLACE TRIGGER bi_ADD_EMPLOYEES_VW
INSTEAD OF insert ON SH_ADD_EMPLOYEES_vw
for each row
declare
duplicate_info EXCEPTION;
PRAGMA EXCEPTION_INIT(duplicate_info, -00001);
begin
insert into SH_EMPLOYEES
(EMP_ID, DEPT_ID, JOB_DESC_ID, EMPNO, EMP_FIRST, EMP_LAST, USER_NAME, USER_INI, DEPTNO, DEPT_DESC)
values
(:new.EMP_ID, :new.DEPT_ID, :new.JOB_DESC_ID, :new.EMPNO, :new.EMP_FIRST, :new.EMP_LAST, :new.USER_NAME, :new.USER_INI, :new.DEPTNO, :new.DEPT_DESC);
insert into DOC_ROLES
(ROLES_ID, ADMIN, CREATES, APPROVES, QUALITY, CUST_SVC, SH_LOCAL, SH_OFFICE, SYSTEM)
VALUES (
:new.ROLES_ID, :new.ADMIN, :new.CREATES, :new.APPROVES, :new.QUALITY, :new.CUST_SVC, :new.SH_LOCAL, :new.SH_OFFICE, :new.SYSTEM);
EXCEPTION
WHEN duplicate_info THEN
RAISE_APPLICATION_ERROR (
num=> -20107
msg=> 'Duplicate employee');
END bi_ADD_EMPLOYEES_VW;
ERROR ON UPDATE:
ORA-20505: Error in DML: p_rowid=1001,
p_alt_rowid=EMP_ID, p_rowid2=2, p_alt_rowid2=ROLES_ID. ORA-01779: cannot modify
a column which maps to a non key-preserved table
ERROR ON INSERT:
ORA-01400: cannot insert NULL into
("SPICE_HUNTER1"."SH_EMPLOYEES"."EMP_ID") ORA-06512: at
"SPICE_HUNTER1.BI_SH_ADD_EMPLOYEES_VW", line 3 ORA-04088: error during execution
of trigger 'SPICE_HUNTER1.BI_SH_ADD_EMPLOYEES_VW' ORA-06512: at
"SYS.WWV_DBMS_SQL", line 549 ORA-06512: at "APEX_040000.WWV_FLOW_DML", line 1121
ORA-22816: unsupported feature with RETURNING clause
Error Unable to process row on table SH_ADD_EMPLOYEES_VWFrom what I see you are not handling emp_id when it is null.. you need to assign it a value when null from sequence.. that column cannot be null, hence the error, and in order to "modify" a column in that table the DML needs that id to have a value.
-
Error in Update Process for optimistic locking
Hello,
I tried to create a tabular form according to this How-To:
http://www.oracle.com/technology/products/database/application_express/howtos/tabular_form.html
which worked fine until I tried to implement the optimistic locking.
I use the same update process:
declare
l_cks wwv_flow_global.vc_arr2;
j pls_integer := 1;
begin
-- Get original MD5 checksum
select wwv_flow_item.md5(job,mgr,hiredate,sal,comm,deptno) cks
BULK COLLECT INTO
l_cks
from emp;
-- Compare the original checksum, l_cks,
-- with submitted checksum, htmldb_application.g_fcs.
-- If they are different, raise an error.
for i in 1..l_cks.count
loop
if htmldb_application.g_fcs(i) != l_cks(i) then
rollback;
raise_application_error(
-20001,
'Current version of data in database has changed '||
'since user initiated update process.');
return;
end if;
end loop;
but as soon as I try to apply the changes in the update process I get an error message saying: PLS-00503: RETURN statement required for this return from function
So, if i delete the row with the "return;" statement, I get no error anymore, but when I test the optimistic locking I get an error as soon as I try to update a row in the first place.
What am I doing wrong?
Johnny
P.S. : I am using Apex 1.6Hi Ant, of course......here is the customized pl/sql block I use:
declare
l_cks wwv_flow_global.vc_arr2;
j pls_integer := 1;
begin
-- Get original MD5 checksum
select wwv_flow_item.md5(partition,desig) cks
BULK COLLECT INTO
l_cks
from UNITS;
-- Compare the original checksum, l_cks,
-- with submitted checksum, htmldb_application.g_fcs.
-- If they are different, raise an error.
for i in 1..l_cks.count
loop
if htmldb_application.g_fcs(i) != l_cks(i) then
rollback;
raise_application_error(-20001,'Current version of data in database has changed ' || 'since user initiated update process.');
-- return;
end if;
end loop;
-- update UNITS
for i in 1..htmldb_application.g_f08.count
loop
if htmldb_application.g_f08(i) is not null then
update UNITS
set report_id = :P2_REPORT_ID,
partition = htmldb_application.g_f10(i),
desig = htmldb_application.g_f11(i)
where unit_id = htmldb_application.g_f08(i);
else
if htmldb_application.g_f10(i) is not null then
insert into UNITS
(report_id,
partition,
desig)
values
(:P2_REPORT_ID,
htmldb_application.g_f10(i),
htmldb_application.g_f11(i));
end if;
end if;
end loop;
end;
Thanks
Johnny -
How to avoid mutating error when insert or update record
Hi ,
I have one transaction table which is having some detail record under one transaction number, after the one transaction number is over by insert or update, i
want to check the total amounts of one flag should be matched on same table if it is not then give error message. But i am getting mutating error on insert or update event trigger on statement level trigger on above table.
Is there any other way to avoid mutating error to solve the above problem or some temp table concepts to be used. help me its urgent.
Thanks in advance,
Sachin Khaladkar
PuneSachin, here's as short of an example as I could come up with on the fly. The sample data is ficticious and for example only.
Let's say I need to keep a table of items by category and my business rule states that the items in the table within each category must total to 100% at all times. So I want to insert rows and then make sure any category added sums to 100% or I will rollback the transation. I can't sum the rows in a row-level trigger because I'd have to query the table and it is mutating (in the middle of being changed by a transaction). Even if I could query it while it is mutating, there may be multiple rows in a category with not all yet inserted, so checking the sum after each row is not useful.
So here I will create;
1. the item table
2. a package to hold my record collection (associative array) for the trigger code (the category is used as a key to the array; if I insert 3 rows for a given category, I only need to sum that category once, right?
3. a before statement trigger to initialize the record collection (since package variables hang around for the entire database session, I need to clear the array before the start of every DML (INSERT in this case) statement against the item table)
4. a before row trigger to collect categories being inserted
5. an after statement trigger to validate my business rule
I then insert some sample data so you can see how it works. Let me know if you have any questions about this.
SQL> CREATE TABLE item_t
2 (category NUMBER(2) NOT NULL
3 ,item_code VARCHAR2(2) NOT NULL
4 ,pct NUMBER(3,2) NOT NULL);
Table created.
SQL>
SQL> CREATE OR REPLACE PACKAGE trg_pkg IS
2 TYPE t_item_typ IS TABLE OF item_t.category%TYPE
3 INDEX BY PLS_INTEGER;
4 t_item t_item_typ;
5 t_empty_item t_item_typ;
6 END trg_pkg;
7 /
Package created.
SQL> SHOW ERRORS;
No errors.
SQL>
SQL> CREATE OR REPLACE TRIGGER item_bs_trg
2 BEFORE INSERT
3 ON item_t
4 BEGIN
5 DBMS_OUTPUT.put_line('Initializing...');
6 trg_pkg.t_item := trg_pkg.t_empty_item;
7 END item_bs_trg;
8 /
Trigger created.
SQL> SHOW ERRORS;
No errors.
SQL>
SQL> CREATE OR REPLACE TRIGGER item_br_trg
2 BEFORE INSERT
3 ON item_t
4 FOR EACH ROW
5 BEGIN
6 trg_pkg.t_item(:NEW.category) := :NEW.category;
7 DBMS_OUTPUT.put_line('Inserted Item for Category: '||:NEW.category);
8 END item_br_trg;
9 /
Trigger created.
SQL> SHOW ERRORS;
No errors.
SQL>
SQL> CREATE OR REPLACE TRIGGER item_as_trg
2 AFTER INSERT
3 ON item_t
4 DECLARE
5 CURSOR c_item (cp_category item_t.category%TYPE) IS
6 SELECT SUM(pct) pct
7 FROM item_t
8 WHERE category = cp_category;
9 BEGIN
10 DBMS_OUTPUT.put_line('Verifying...');
11 FOR i IN trg_pkg.t_item.FIRST..trg_pkg.t_item.LAST LOOP
12 DBMS_OUTPUT.put_line('Checking Category: '||trg_pkg.t_item(i));
13 FOR rec IN c_item(trg_pkg.t_item(i)) LOOP
14 IF rec.pct != 1 THEN
15 RAISE_APPLICATION_ERROR(-20001,'Category '||trg_pkg.t_item(i)||' total = '||rec.pct);
16 END IF;
17 END LOOP;
18 END LOOP;
19 END item_as_trg;
20 /
Trigger created.
SQL> SHOW ERRORS;
No errors.
SQL> INSERT INTO item_t
2 SELECT 1, 'AA', .3 FROM DUAL
3 UNION ALL
4 SELECT 2, 'AB', .6 FROM DUAL
5 UNION ALL
6 SELECT 1, 'AC', .2 FROM DUAL
7 UNION ALL
8 SELECT 3, 'AA', 1 FROM DUAL
9 UNION ALL
10 SELECT 1, 'AA', .5 FROM DUAL
11 UNION ALL
12 SELECT 2, 'AB', .4 FROM DUAL;
Initializing...
Inserted Item for Category: 1
Inserted Item for Category: 2
Inserted Item for Category: 1
Inserted Item for Category: 3
Inserted Item for Category: 1
Inserted Item for Category: 2
Verifying...
Checking Category: 1
Checking Category: 2
Checking Category: 3
6 rows created.
SQL>
SQL> SELECT * FROM item_t ORDER BY category, item_code, pct;
CATEGORY IT PCT
1 AA .3
1 AA .5
1 AC .2
2 AB .4
2 AB .6
3 AA 1
6 rows selected.
SQL>
SQL> INSERT INTO item_t
2 SELECT 4, 'AB', .5 FROM DUAL
3 UNION ALL
4 SELECT 5, 'AC', .2 FROM DUAL
5 UNION ALL
6 SELECT 5, 'AA', .5 FROM DUAL
7 UNION ALL
8 SELECT 4, 'AB', .5 FROM DUAL
9 UNION ALL
10 SELECT 4, 'AC', .4 FROM DUAL;
Initializing...
Inserted Item for Category: 4
Inserted Item for Category: 5
Inserted Item for Category: 5
Inserted Item for Category: 4
Inserted Item for Category: 4
Verifying...
Checking Category: 4
INSERT INTO item_t
ERROR at line 1:
ORA-20001: Category 4 total = 1.4
ORA-06512: at "PNOSKO.ITEM_AS_TRG", line 12
ORA-04088: error during execution of trigger 'PNOSKO.ITEM_AS_TRG'
SQL>
SQL> SELECT * FROM item_t ORDER BY category, item_code, pct;
CATEGORY IT PCT
1 AA .3
1 AA .5
1 AC .2
2 AB .4
2 AB .6
3 AA 1
6 rows selected.
SQL> -
'Missing select' error for update statement using WITH clause
Hi,
I am getting the below error for update statement using WITH clause
SQL Error: ORA-00928: missing SELECT keyword
UPDATE A
set A.col1 = 'val1'
where
A.col2 IN (
WITH D AS
SELECT col2 FROM
(SELECT col2, MIN(datecol) col3 FROM DS
WHERE <conditions>
GROUP BY PATIENT) D2
WHERE
<conditions on A.col4 and D2.col3>Hi,
The format of a query using WITH is:
WITH d AS
SELECT ... -- sub_query
SELECT ... -- main query
You don't have a main query. The keyword FROM has to come immediately after the right ')' that ends the last WITH clause sub-query.
That explains the problem based on what you posted. I can't tell if the real problem is in the conditions that you didn't post.
I hope this answers your question.
If not, post a complete test script that people can run to re-create the problem and test their ideas. Include a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
Maybe you are looking for
-
[SOLVED] Problem with UTC and CST
I probably made a mistake while installing Arch Linux and the clocks in my computer are all a mess. Right now the UTC time its 6+ hours, I changed it in the bios to the right hour but that give me -6 hours in the local time thats displayed in Arch Li
-
Error Message when starting Object Manager on the Client
I�ve installed sgd 4 successfully and I can start applications - except Array- and Objectmanager from my client. Here I get the message ErrTransportNotAvailable ErrTransportNotAvailable Standard error of script process: Third tier output log: Any ide
-
PM Order Operations Default Unit of Measurement
Halo Experts, We have a problem in UOM for PM/CS order operations. We have defined HR as default value of UOM for operations in IMG. Business wants to change at the order level to H as UOM and it is manually keyed in and saved. But when we check with
-
Content conversion at JMS sender communication channel
Hi friends, I have to convert fixed length flat structure to xml message.Therefor i have to do content conversion at the JMS sender comm channel.Can someone please explainthe procedure? data in the queue would be like as follows. 9999
-
I have a brand new W530. Once or twice a day, the monitor display goes beserk. The screen begins flashing bright pastel colors which alternate in rapid succession -- this is kind of like watching an anime cartoon. Occaisionally, instead of doing