Oracle Apex delete entry from collection - checkbox

I have two interactive reports with check boxes. If the user select entries from interactive report1 and press a button, the selected entries will be added into a collection and displayed in interactive report2.
In interactive report2 I have again a checkbox and if the user select an entry, it should be deleted from the collection and interactive report2 by pressing a button.
I have defined a process which is fired when the button is pressed:
declare v_id number;
begin
FOR i in 1..APEX_APPLICATION.G_F03.count
LOOP
select id into v_id from apex_collections where collection_name = 'SELECTED2' and c001 = APEX_APPLICATION.G_F03(i);
apex_collection.delete_member(
p_collection_name => 'SELECTED2',
p_seq => v_id);
END LOOP;
end;
SELECTED2 is the name of the collection.
APEX_APPLICATION.G_F03 is the checkox value of the check box in interactive report2.
Problem, the entire collection is deleted and not only the selected rows in interactive report2. How could I delete only the selected rows?

This is an example on the emp/dept schema with 2 interactive reports:
IR_1 on emp with all records that are in table but not in collection
IR_2 on emp with all records that are in collection
When a user selects checkbox in IR_1 and submits, those records are put in a collection. When a user selects checkbox in IR_2 and submits, record is removed from collection.
IR_1 has query:
select EMPNO,
ENAME,
APEX_ITEM.CHECKBOX(1,empno,'UNCHECKED') AS CHECKBOX
from EMP
where NOT EXISTS (SELECT n001 FROM apex_collections WHERE collection_name = 'EMP' AND n001 = empno)
and a button "ADD" with action "Submit Page" in IR_1 region
IR_2 has query:
select EMPNO,
ENAME,
APEX_ITEM.CHECKBOX(2,empno,'UNCHECKED') AS CHECKBOX
from EMP WHERE empno IN (SELECT n001 FROM apex_collections WHERE collection_name = 'EMP')
and a button "REMOVE" with action "Submit Page" in IR_2 region.
Create 2 page processes of type Execute Code:
"Add to Collection"
IF NOT APEX_COLLECTION.COLLECTION_EXISTS ( p_collection_name => 'EMP') THEN
APEX_COLLECTION.CREATE_COLLECTION( p_collection_name => 'EMP');
END IF;
FOR I in 1..APEX_APPLICATION.G_F01.COUNT LOOP
APEX_COLLECTION.ADD_MEMBER (
p_collection_name => 'EMP',
p_n001 => to_number(APEX_APPLICATION.G_F01(i)));
END LOOP;
Condition: When button pressed = ADD
"Remove fromCollection"
FOR I in 1..APEX_APPLICATION.G_F02.COUNT LOOP
FOR j IN (SELECT seq_id FROM apex_collections WHERE collection_name = 'EMP' and n001 = to_number(APEX_APPLICATION.G_F02(i)))
LOOP
APEX_COLLECTION.DELETE_MEMBER (
p_collection_name => 'EMP',
p_seq => j.seq_id);
END LOOP;
END LOOP;
Condition: When button pressed = REMOVE
Note: Since those 2 interactive reports are on a single page 2 different ids need to be taken for the checkbox. IR_1 uses 1 (and APEX_APPLICATION.G_F01) in the page process and IR_2 uses 2 - (and APEX_APPLICATION.G_F02) in the page process.

Related

SQL Server WHERE clause with AND or OR

I have below search form which calls a stored procedure. Client requested a new feature which he needs to Search Product OR Items. To satisfy this new requirement I added a checkbox as in the image. If user check this checkbox, query should return either Products OR Items.
This is the existing query I used for the search,
Select * FROM PRODUCT P INNER JOIN ITEM I ON
P.ID = I.PID
WHERE
(#para_product_country is NULL OR #para_product_country = P.Country)
AND
(#para_product_city is NULL OR #para_product_city = P.City)
AND
(#para_product_street is NULL OR #para_product_street = P.Street)
AND
(#para_item_country is NULL OR #para_item_country = I.Country)
AND
(#para_item_city is NULL OR #para_item_city = I.City)
AND
(#para_item_street is NULL OR #para_item_street = I.Street)
How can I implement the query depending on users selection of checkbox which needs to search Products OR Items ? If user check the checkbox, query should return data either from Product OR Item. If user did not select the checkbox query should return data from Product AND Item.
I would like to know how to change the WHERE condition AND or OR according to checkbox selection ?

How to delete one/multiple row/s in two tables based on one table in SQL Server

I have two tables (to make things easier I will copy everything here)
that I need to delete from.
The main table to delete from is done based on another table, which this I could do as below
select
items.item, items.ORDERNO, items.LU_ON,
stock.NUMBER, stock.CUSTOMTEXT, stock.LU_ON
from
items, stock
where
items.item = stock.NUMBER
and items.LU_ON >= '2021-11-10'
and convert(VARCHAR, STOCK.CUSTOMTEXT) = 'breakout'
and convert(VARCHAR, ORDERNO) <> ''
delete from items
where items.item in (select stock.number
from stock
where items.item = stock.NUMBER
and items.LU_ON >= '2021-11-10'
and convert(VARCHAR, ORDERNO) <> ''
and convert(VARCHAR, STOCK.CUSTOMTEXT) = 'breakout')
However in order for this to fully work in SQL without touching the program on the front end i also need to delete the box (from the item which was deleted) from the box table based on the single item in the order which was deleted in the items table. Below are some columns/rows in the items table, i need to delete the first item, and that is based on this item being in the "stock" table which has the 'item' from the items table, just in the stock table 'item' is 'number' and i will delete from the items table any time the lu_on column (in both the stock and items table) has the date which i put in, and also has the word 'breakout' in the 'customtext' column from the stock table.
ORDERNO ITEM_ID ITEM
-------------------------------
1225971 4208453 HRE-IK.S
1225971 4208454 HRE-IK.B1
1225971 4208455 HRE-IK.B2
and below is the main columns of the 'box' table which i need to delete the row which is affected by me deleting it in the items table (this is the part i got stuck)
BOX_ID ORDERNO BOX BOXOF
-------------------------------
1027766 1225971 1 1
1027767 1225971 1 2
1027768 1225971 2 2
Below is the query i tried to find the correct items, and this query either showed no results, or too many that i don't need (as i am trying to sort only by date)
select
items.item, items.ORDERNO, items.LU_ON,
stock.NUMBER, stock.CUSTOMTEXT, stock.LU_ON,
box.orderno, box.LU_ON, box.BOX_ID, box.box
from
BOX, items, STOCK
where
box.boxof not in (select ORDERNO from items)
and items.item = stock.NUMBER
and box.LU_ON >= '2021-11-10'
and items.LU_ON >= '2021-11-10'
and convert(VARCHAR, STOCK.CUSTOMTEXT) = 'breakout'
and convert(VARCHAR, items.ORDERNO) <> ''
So with this too much info shows up, not sure how to isolate what I am looking for, also then i will need to delete what I found, once i know it is correct.
I hope my question was clear enough, it is my first time asking here, and would be happy to clarify/ take pointers.
Thank you!

Oracle Apex: Add custom column into interactive report

I create a page and add an interactive report to show data of view
CREATE OR REPLACE VIEW FAC_FILE_MANAGEMENT_VIEW AS
SELECT FAC_FILE.NAME as FILE_NAME, FAC_NHAN_VIEN.USERNAME as USERNAME,
FAC_FILE_MANAGEMENT.FAC_MONTH as FAC_MONTH, FAC_FILE_MANAGEMENT.FAC_YEAR as FAC_YEAR, FAC_FILE_UPLOAD.LAST_UPDATED as LAST_UPDATED,
CASE IS_COMPLETED
WHEN 0 THEN 'Not Upload'
WHEN 1 THEN 'Completed'
END as IS_COMPLETED
FROM FAC_FILE_MANAGEMENT left join FAC_FILE on FAC_FILE_MANAGEMENT.FILE_ID = FAC_FILE.ID
left join FAC_FILE_UPLOAD on FAC_FILE_MANAGEMENT.FILE_UPLOAD_ID = FAC_FILE_UPLOAD.ID
left join FAC_NHAN_VIEN on FAC_FILE_MANAGEMENT.UPLOADED_BY = FAC_NHAN_VIEN.ID;
Now, I want to create new custom column nam 'View Detail'. This column is a link based on value of IS_COMPLETED
Completed: Show link to view detail
Not Upload: Blank
How can I add a custom column into interactive report?
Its much easier if you just add NULL to the query like this
SELECT NULL as View_Detail, <insert other columns>
FROM TABLE
add column to your report query like:
,DECODE(IS_COMPLETED,'Y','View Detail','N','') AS 'Detail'
This will add new column to your report.
Now go to your Report Attributes tab and edit Detail Column.
and change Display As to Standard Report Column.
Also, you need to select column in interactive report to display from your output.

Update matching column with the selected top 1 column

I have two tables Role and Role_Imp. I need to fetch Name column's value from the 1st row of the Role table. After that I need to update Name's column value in Role_Imp table for the rows which has Names same as the selected name from the Role table.
I am using the following query, which is not working as its wrong.
UPDATE Role_Imp
SET Role_Imp.Name = 'Role Test Change'
FROM Role_Imp
INNER JOIN
Role ON Role_Imp.Name = SELECT TOP 1 Name FROM Role
How should I do this?
Seems like this should do it:
UPDATE Role_Imp
SET Name = 'Role Test Change'
WHERE Name = (SELECT TOP 1 Name FROM Role)

How to reference value from a drop down selection box ...?

I'm using Oracle APEX and I'm generating an interactive report .. Now I have a drop down selection box which has a list of values (LOVs) .. What I want to do is to use the currently selected value in the drop down box in the SQL query being used to generate the interactive report .. Like for example this is the SQL query for generating the interactive report to only show employees with rank Salesman:
select "EMP"."EMPNO" as "EMPNO",
"EMP"."ENAME" as "ENAME",
"EMP"."RANK" as "RANK",
from "EMP" "EMP"
where "EMP"."RANK" = 'SALESMAN'
The above query completely works for me ... Now I have a drop down box on the same page in APEX which is named RANKS, and has this LOV: SALESMAN, CLERK, ACCOUNTANT, DEPTHEAD
How do I change the SQL Query so that it now looks up the currently selected rank in the ranks drop down list and then only displays employees with that rank ...
If your ranks LOV is called P1_RANKS for example, then you can change the query SQL to:
select empno, ename, rank
from emp
where rank = :P1_RANKS
However, that only works once a rank has been selected. If you want to show all employees when no rank has been selected do this:
select empno, ename, rank
from emp
where (:P1_RANKS is null or rank = :P1_RANKS)
You can either make the select list submit the page to refresh the report or, preferably, create a dynamic action to refresh the report when the select list item is changed.

Resources