Please help me, how to fill in the correct values?
Because the value is always less, and showing ERR not enough values the error is in here
Here is my code :
CREATE OR REPLACE TRIGGER REGION_HILMI_TRIGGER_WARNING
AFTER INSERT OR UPDATE OR DELETE ON REGION_HILMI
FOR EACH ROW
DECLARE
warning VARCHAR2(400);
BEGIN
IF INSERTING THEN
warning:='Terjadi penambahan data di tabel regions, dengan
nilai region_id='||:NEW.region_id||' dan
region_name='||:NEW.region_name;
ELSIF UPDATING THEN
warning:='Terjadi perubahan data di tabel regions, dengan
nilai lama region_id='||:OLD.region_id||',
region_name='||:OLD.region_name||' nilai baru
region_id='||:NEW.region_id||', region_name='||:NEW.region_name;
ELSIF DELETING THEN
warning:='Terjadi penghapusan data di tabel regions untuk
region_id='||:OLD.region_id||' dan region_name='||:OLD.region_name;
END IF;
INSERT INTO REGION_HILMI_HISTORY(OLD_REGION_ID,OLD_REGION_NAME,NEW_REGION_ID,NEW_REGION_NAME,CHANGE_TIME,DESCRIPTION)
VALUES(REGION_HILMI_SEQUENCE.NEXTVAL,USER,TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS'),warning);
END;
/
Your INSERT statement shows only 4 items in the VALUES clause but 6 in the column name list. They must both match.
thankss sir, #TenG
solved with adding this scripts :
INSERT INTO REGION_HILMI_HISTORY(OLD_REGION_ID,OLD_REGION_NAME,NEW_REGION_ID,NEW_REGION_NAME,CHANGE_TIME,DESCRIPTION)
VALUES(REGION_HILMI_SEQUENCE.NEXTVAL,:OLD.REGION_NAME,:NEW.REGION_ID,:NEW.REGION_NAME,TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS'),warning);
now then I tried to insert data into my primary table sir,
but it showing error like this appears, after i setting up the trigger
click to show image
now it solved....
problem on trigger,
i change (TO_CHAR) >>> (TO_DATE)
error :
VALUES(REGION_HILMI_SEQUENCE.NEXTVAL,:OLD.REGION_NAME,:NEW.REGION_ID,:NEW.REGION_NAME,TO_CHAR(SYSDATE,'DD-MON-YYYY HH24:MI:SS'),warning);
work :
VALUES(REGION_HILMI_SEQUENCE.NEXTVAL,:OLD.REGION_NAME,:NEW.REGION_ID,:NEW.REGION_NAME,TO_DATE(SYSDATE,'DD-MON-YYYY HH24:MI:SS'),warning);
Related
I'm trying to create a trigger in which, only under certain circumstances, an insert is performed on another table. Consider the following code:
create table journal (
pk integer primary key autoincrement,
dsc varchar(10) not null
);
create table users (
name varchar(30) primary key not null
);
create trigger users_ai
after insert on users
begin
select
case
when 1 then
insert into journal(dsc) values('foo')
end;
end;
I get the following error when I run this code:
Error: near line 10: near "insert": syntax error
In production, the "1" in the when clause would be replaced by a more complex expression. I've also tried "true" and get the same results. I've also tried surrounding the insert statement in parens and get the same results. Any ideas how to accomplish what I want?
If you look at the syntax diagram for "CREATE TRIGGER", you'll see your attempt just doesn't match. You can, however, simply use the WHEN branch (without needing FOR EACH ROW):
create trigger users_ai
after insert on users
when 1 begin
insert into journal(dsc) values('foo');
end;
OK, figured it out. Instead of putting a conditional expression in the block of the trigger, I used a when clause. Here's the code that works:
create trigger users_ai
after insert on users when 1
begin
insert into journal(dsc) values('foo');
end;
If that when expression is changed to something that returns false (say 0) then the insert isn't done. In production, the expression will sometimes return true, sometimes false, which, of course, is the point of this code. Thanks everybody!
I think that you want a CASE statement, not a CASE expression.
create trigger users_ai after insert on users
begin
case
when ... then insert into journal(dsc) values('foo');
when ... then ...;
else ...;
end case;
end;
Note: if your trigger needs access to the data that was just inserted, its definition should the for each row option.
You can try to use an INSERT ... SELECT and your expression in the WHERE clause.
...
INSERT INTO journal
(dsc)
SELECT 'foo'
WHERE 1 = 1;
...
1 = 1 needs to be replaced by your Boolean expression.
I have a table named 'uploaded_files' that stores *csv.files which are uploaded via dropzone (https://github.com/Dani3lSun/apex-plugin-dropzone) by a user in my webapplication. The content of that files is stored in a tablecolumn of datatype blob.
To insert the file-content I am using a package called 'csv_util_pkg' (https://github.com/mortenbra/alexandria-plsql-utils). I managed to convert the blob-datatype to clob-datatype and store the clob-data into another table called x_dump. X_Dump Table As you can see in the picture the clob_values are separated and stored in 'c001' and 'c002'. This is done by a function of the csv_util_pkg.
Now I want to take those two values and store them in a table called 'fahrzeug' but this doesn't work and I really don't know why. I am getting the following error code
ORA-01400: Einfügen von NULL in ("RESSOURCE_U"."FAHRZEUG"."VNUMMER") nicht möglich
ORA-06512: in Zeile 14
01400. 00000 - "cannot insert NULL into (%s)"
*Cause: An attempt was made to insert NULL into previously listed objects.
*Action: These objects cannot accept NULL values.
And here is my code:
DECLARE
file_content NUMBER (10);
l_clob CLOB;
BEGIN
SELECT TO_CLOB (
UTL_RAW.CAST_TO_VARCHAR2 (DBMS_LOB.SUBSTR (FILE_BLOB, 2000)))
INTO l_clob
FROM UPLOADED_FILES
WHERE UPLOADED_FILES.FILENAME LIKE 'A_%_Fahrzeug.csv';
INSERT INTO X_DUMP (CLOB_VALUE, DUMP_ID)
VALUES (l_clob, 1);
INSERT INTO fahrzeug (vnummer, baureihe)
SELECT c001, c002
FROM x_dump d, TABLE (csv_util_pkg.clob_to_csv (d.clob_value, ';'));
COMMIT;
END;
vnummer is the primary key of my table 'fahrzeug' and thus we can not insert null. But I don't understand that because c001 and c002 contain values so it can't be null..
Thanks for your help!
Did you debug or output the c001 during runtime? Try this:
for tmp IN (select c001 from x_dump d, table(csv_util_pkg.clob_to_csv(d.clob_value, ';')))
LOOP
DBMS_OUTPUT.put_line ('vnummer: ' || tmp.c001);
END LOOP;
I just start using apex from few time. So I hope you'll forgive me if I ask things that are very simple.
I have a select list populated by a SQL Query, my SQL instruction is SELECT NUM, ID FROM TABLE.
I'd like to change the query dynamically adding a " WHERE NUM LIKE %myVar%", where "MyVar" is the test of a text Item, so I'd like to change the content of the select list pressing the button.
Is it possible?
thanks in advance for any answer.
I find a partial solution. I bind to select list a PL/SQL function returning a SQL Script and I add an text item called filter.
My function is:
declare
q varchar2(4000);
begin
q:='select numero, ';
q:=q||'id from t_doc ';
q:=q||'where numero = :FILTROPT';
return q;
end;
But if I use like with a percent in the function instead of "=", apex raise me an error.
Any suggestion?
I have this trigger:
create or replace TRIGGER TR14_2
BEFORE INSERT OR UPDATE OF CANTIDAD ON DISTRIBUCION
FOR EACH ROW
DECLARE
total_cars NUMBER;
total_cars_potential NUMBER;
BEGIN
SELECT sum(cantidad) into total_cars
FROM DISTRIBUCION
WHERE cifc = :NEW.cifc;
total_cars_potential := total_cars + :NEW.cantidad;
IF INSERTING THEN
IF(total_cars_potential > 40) THEN
raise_application_error(-20005, 'Dealer [' || :NEW.cifc || '] already has 40 cars stocked');
END IF;
END IF;
IF UPDATING THEN
IF(total_cars_potential - :OLD.cantidad > 40) THEN
raise_application_error(-20006, 'That update of CANTIDAD makes the dealer exceeds the limit of 40 cars stocked');
END IF;
END IF;
END;
It gets a mutating table error, and I have checked that is because of the UPDATING block of code, the INSERTING goes ok; but why? And how can I fix it?
Just to clarify, I want that each dealer can have at maximum 40 cars stocked. So, if I add a row to DISTRIBUCION ("distribution") with cantidad ("quantity") that will make the dealer exceed its maximum stock, I will raise an error.
But, if I update a quantity of cars of a type, stocked already in the database, and I exceed 40 cars, I want also a exception to be thrown.
Thing is, I am not seeing the mutatig table error on the UPDATING block.
1st: The reason you get a mutating table syndrome is that you're reading from the table that is updated in the trigger (selecting the total cars).
2nd: Solution: I'd probably create 2 triggers: A for-each-row trigger as you did that collects the updated rows in a package variable
CREATE OR REPLACE PACKAGE PCK_TR14_2 IS
TYPE changed_row IS RECORD (
cantidad DISTRIBUCION.cantidad%TYPE,
);
TYPE changed_row_table IS TABLE OF changed_rows INDEX BY binary_integer;
changed_rows changed_row_table;
cnt_changed_rows BINARY_INTEGER DEFAULT 1;
END PCK_TR14_2;
/
The for-each-row trigger would look something like this (now an after insert!)
create or replace TRIGGER TR14_2
AFTER INSERT OR UPDATE OF CANTIDAD ON DISTRIBUCION
FOR EACH ROW
DECLARE
BEGIN
PCK_TR14_2.changed_rows(PCK_TR14_2.cnt_changed_rows).cantidad := :old.cantidad;
PCK_TR14_2.cnt_changed_rows := PCK_TR14_2.cnt_changed_rows + 1;
END;
/
Then in a after statement trigger implement your logic:
CREATE OR REPLACE TRIGGER TR14_2_S
AFTER INSERT OR UPDATE OF CANTIDAD ON DISTRIBUCION
BEGIN
FOR i IN PCK_TR14_2.changed_rows.FIRST..PCK_TR14_2.changed_rows.LAST LOOP
-- YOUR LOGIC HERE
null;
END LOOP;
END;
/
Access the candidat in the "virtuell" table as needed ( PCK_TR14_2.changed_rows(i). CANTIDAD)
A trigger can not change a table that it has read from. This is the mutating table error issue.
You can see the solutions provided in the below link
Mutating table error
avoiding_mutating_table_error
Please forgive me, somebody else from my class has asked this question but the answer didn't quite meet my needs. This is coursework so I do not want spoon feeding the answer but a nudge in the right direction would help. I also know that other class friends are using this forum to assist with their work so this answer would be really useful.
This is the question as it has been asked:
(a) A PL/SQL procedure called INIT_ACTOR_QUOTES with no parameters that:
i. Reads ALL the ACTORIDs from the ACTOR table and INSERTs them into the ACTORID attribute for each row the ACTOR_QUOTES table (the tables have the same cardinality) and at the same time INSERTs the following initial values into the first row only of the QUOTES nested table into each row of the ACTOR_QUOTES table;
(Movie_Title, Year, Role, Quote) are set respectively to (' ',NULL ,' ', ' ')
Also and at the same time immediately after each INSERT use DELETE to delete ALL the rows from the nested table in each row belonging to each ACTORID in the ACTOR_QUOTES table. (NB: this may seem strange but is necessary as the nested table cannot be populated (because it is atomically null) unless it is initialized, after which this initial data may be deleted).
This is what I have come up with and the response that I get:
CREATE OR REPLACE PROCEDURE INIT_ACTOR_QUOTES
AS
CURSOR actorID_cursor IS
SELECT actorID FROM Actor;
BEGIN
FOR row IN actorID_cursor LOOP
INSERT INTO actor VALUES (
'00001',
actor_quotes_NT (
quote ('', NULL, ' ', '')
);
DELETE (*) FROM Quotes_NT ('', NULL, ' ', '');
END LOOP;
END INIT_ACTOR_QUOTES ;
/
LINE/COL ERROR
-------- -----------------------------------------------------------------
8/1 PL/SQL: SQL Statement ignored
13/2 PL/SQL: ORA-00917: missing comma
16/1 PL/SQL: SQL Statement ignored
16/9 PL/SQL: ORA-00928: missing SELECT keyword
20/1 PLS-00103: Encountered the symbol "/"
I sort of get the principle of what my lecturer is asking but this is giving me a blooming headache. Please help.
Do you need any more information?