Oracle Apex Interactive Grid not saving updated values - oracle

I'm working with an Interactive Grid, while updating a value I get success message but nothing really happens (I update the value, click on save, message pop-up appears: changes saved. But the values remain the same).
This is my query:
select
PRODUCT_SECTION,
PRODUCT_ID,
PRODUCT_NAME,
MIN_QUANTITY,
QUANTITY, --This is the column available for updates
MY_PRIMARY_KEY
FROM MY_TABLE
WHERE USER = lower(v('APP_USER'))
AND ID = :P31_MY_ID
AND DEAL_ID = nvl(:P31_MY_DEAL, 'No Deal')
Can anyone help me please?
Thanks!

Related

Oracle Apex Interactive Grid - Add new row not inserting

I have a page on my app that allows the user to create (insert) a new row on my table:
Employee Manager id Status
john ryan 1 Active
angela ryan 2 Active
steve jim 3 Inactive
Id column acting as primary key.
My Interactive Grid is working ok for updates, the 'add row' button works (a new row is displayed and info can be added into it). But when clicking on save, this 'new row added' disappears, info doesn't get inserted into the table at all.
My query as follows:
select
--PK
id,
Manager,
Employee,
--Update only available when Status is active:
decode(Status,'Active', 'U',
'X') as Editable
from my_table
IG attributes:
Edit = enabled
Allowed Operations = update row, add row
Allowed Row Operations Column = Editable
Lost Update Type = row value
Add row if empty = Yes
Anybody has any idea why?
Thank you all

Cascading LOV - Invalid number while updating record - Oracle Apex

I have a select list based on other select list. It works fine on the create screen but gives 'Invalid number' error in update screen.
SQL query:
select description, account_id
from t_account
where chart_id = :P15_chart_name
Please help me out!
You are trying to convert a string into a number, and that failed.
As Select List item has 2 values: 1st being display and the 2nd return value, it is the 2nd value that causes problems - account_id in your case.
For example, it contains value A while column that is supposed to accept this value is declared as NUMBER. Oracle can't convert A into a number and raises an error.
What to do?
make sure that Select List item LoV query returns only numbers, or
modify column's datatype to varchar2
If that's not it, then :P15_CHART_NAME item and chart_id table column differ in datatypes; a simple option is to fix page item's datatype.

Trying to delete a row based upon condition defined in my trigger (SQL)

I am trying to create a row level trigger to delete a row if a value in the row is being made NULL. My business parameters state that if a value is being made null, then the row must be deleted. Also, I cannot use a global variable.
BEGIN
IF :NEW.EXHIBIT_ID IS NULL THEN
DELETE SHOWING
WHERE EXHIBIT_ID = :OLD.EXHIBIT_ID;
END IF;
I get the following errors:
ORA-04091: table ISA722.SHOWING is mutating, trigger/function may not see it
ORA-06512: at "ISA722.TRG_EXPAINT", line 7
ORA-04088: error during execution of trigger 'ISA722.TRG_EXPAINT'
When executing this query:
UPDATE SHOWING
SET EXHIBIT_ID = NULL
WHERE PAINT_ID = 5104
As already indicated this is a terrible idea/design. Triggers are very poor methods for enforcing business rules. These should be enforced in the application or better (IMO) by a stored procedure called by the application. In this case not only is it a bad idea, but it cannot be implemented as desired. Within a trigger Oracle does not permit accessing the table the trigger fired was fired on. That is what mutating indicates. Think of trying to debug this or resolve a problem a week later. Nevertheless this non-sense can be accomplished by creating view and processing against it instead of the table.
-- setup
create table showing (exhibit_id integer, exhibit_name varchar2(50));
create view show as select * from showing;
-- trigger on VIEW
create or replace trigger show_iiur
instead of insert or update on show
for each row
begin
merge into showing
using (select :new.exhibit_id new_eid
, :old.exhibit_id old_eid
, :new.exhibit_name new_ename
from dual
) on (exhibit_id = old_eid)
when matched then
update set exhibit_name = new_ename
delete where new_eid is null
when not matched then
insert (exhibit_id, exhibit_name)
values (:new.exhibit_id, :new.exhibit_name);
end ;
-- test data
insert into show(exhibit_id, exhibit_name)
select 1,'abc' from dual union all
select 2,'def' from dual union all
select 3,'ghi' from dual;
-- 3 rows inserted
select * from show;
--- test
update show
set exhibit_name = 'XyZ'
where exhibit_id = 3;
-- 1 row updated
-- Now for the requested action. Turn the UPDATE into a DELETE
update show
set exhibit_id = null
where exhibit_name = 'def';
-- 1 row updated
select * from show;
-- table and view are the same (expect o rows)
select * from show MINUS select * from showing
UNION ALL
select * from showing MINUS select * from show;
Again this is a bad option yet you can do. But just because you can doesn't mean you should. Or that you'll be happy with the result. Good Luck.
You have written a trigger that fires after or before a row change. This is in the middle of an execution. You cannot delete a row from the same table in that moment.
So you must write an after statement trigger instead that only fires when the whole statement has run.
create or replace trigger mytrigger
after update of exhibit_id on showing
begin
delete from showing where exhibit_id is null;
end mytrigger;
Demo: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=dd5ade700d49daf14f4cdc71aed48e17
What you can do is create an extra column like is_to_be_deleted in the same table, and do this:
UPDATE SHOWING
SET EXHIBIT_ID = NULL, is_to_be_deleted = 'Y'
WHERE PAINT_ID = 5104;
You can use this parameter to implement your business logic of not showing the null details.
And later you can schedule a batch delete on that table to clean up these rows (or maybe archive it).
Benefit: you can avoid an extra unnecessary trigger on that table.
Nobody, will suggest you to use trigger to do this type of delete as it is expensive.

Execute Multiple Queries in Oracle Apex Pl/Sql

i have button with dynamic action execute pl/sql Code
on button click i have to execute two queries, initially insert in a table
and then update in another table
INSERT INTO student (student_name,
student_father,
student_dob,
student_gender,
country,
email_id,
whatsapp_number,
good_time_to_contact,
time_requested,
mobile_number,
state_province,
city,
zip_code,
skype_id,
street_adress,
course,
language_required,
class_days,
application_id,
updated_by)
SELECT first_name || ' ' || last_name AS StudentName,
father_name,
date_of_birth,
gender,
country_id,
email,
whatsapp_number,
time_to_contact,
learning_time,
mobile_number,
state_province,
city,
zip_code,
skype_id,
street_address,
course_id,
language,
class_days,
:P164_APP_ID,
:App_user
FROM student_app
WHERE app_id = :P164_APP_ID;
UPDATE student_app
SET gr_number =
(SELECT gr_number
FROM student
WHERE application_id = :P164_APP_ID),
updated_by = :App_user,
app_status = '6-STUDYING',
updated_ts = CURRENT_TIMESTAMP
WHERE app_id = :P164_APP_ID;
i am using these pl/sql code but does insert in the table nor update either.
while these code execute fine when i execute from oracle sql developer
please help me out i am using oracle apex 18.2
It seems that you didn't commit, did you?
Also, check whether you put page item(s) you use (P164_APP_ID) into the Items to submit dynamic action property (it is right below the PL/SQL code).
If your items do contain the values in the session (that you have to submit to the page, as Littlefoot said) and it still doesn't work, try adding your query to a Process in the Processing tab, with the server-side condition set to pressing the button you're pressing. I can't remember if you can set multiple statements to be run in a single process, but it's worth a try.
Something like:
Processing Tab
Code Section
Condition Section

update multiple table with the same trigger DB Oracle

i'm creating a trigger, for ibm maximo application, that has to start when the field mens_ack is updated;
when that happens, the 'status' field must become of a certain value
after that i have to update another table (longdescription table) based on the relationship workorderid=ldkey
create or replace TRIGGER "MAXIMO"."CHANGE_MENS_MAINT_T"
AFTER UPDATE OF MENS_ACK ON WORKORDER
BEGIN
update workorder
set status='SCHED', statusdate= sysdate
where mens_ack='1' and status!='SCHED';
update longdescription
set ldtext= concat(ldtext, 'scheduled maintenance - '+sysdate+' ')
where ldkey = ????;
END;
I can't use NEW and OLD in this trigger, so i doesn't know how to take the WORKORDERID (the key on which the relation is based) in order to specify what record i have to find in longdescription table
can anyone help me?
You could use the RETURNING INTO clause from the first update.
https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/returninginto_clause.htm
update workorder
set status='SCHED', statusdate= sysdate
where mens_ack='1' and status!='SCHED'
returning workorderid into v_workorderid;
Watch out for the number of updated workorders, since the v_workorderid might have to be declared as an array.

Resources