Oracle Apex 18 shuttle item show last selected values on right side - oracle

I have implemented Shuttle List Successfully Using Dynamic Action with Below Code
declare
tab apex_application_global.vc_arr2;
begin
tab := apex_util.string_to_table (:P14_NEW_1);
for i in 1..tab.count loop
insert into xxtest (COL1, COL2)
values (:P14_NEW, tab(i));
end loop;
commit;
end;
Problem is that each the time user open the forms it don't show the last selected values to Right Hand Side, I didn't understand this logic how can i show selected items as saved In table to Right side when page loads

You did the first part of job - stored selected values into a table.
The next step is to retrieve them back. In order to do that,
navigate to shuttle item's source property
set its type to "SQL Query (return colon separated values)
SQL query should look like this:
select listagg(col2, ':') within group (order by null)
from xxtest
where ... --> include condition, if there is any - I believe it should
set "Used" property to "Always, replacing any existing value in session state
Run the page; shuttle item should now have populated right hand side.
As of the where clause: I don't know what is the purpose of doing what you're doing, but - if you don't distinguish rows stored into the xxtest table, all users will use the same recordset and overwrite each other's data. If xxtest.col1 represents username (so that wouldn't be :P14_NEW but :APP_USER instead), you should use it in WHERE clause. Otherwise, consider doing that.

Related

How to check a checkbox in Apex 18 when its value is present in other table

I have a checkbox with list of values from table a. I need them to be checked if are present in a column of table b. Do you have any ready solution please colleagues ?
Thx
Adam
See this similar question for some background info.
When you're working with a multi-value checkbox item, you want your Source Query to select a colon-delimited list of the values that you want to be checked in your checkbox. (This is true for multi-value Application Express page items in general.) E.g.
select listagg(my_column, ':') within group (order by my_column)
from TableB
where my_column is the name of the column in TableB that your values are stored in.
If you have a lot of values in TableB (enough that the listagg() above returns more than 4000 characters), you'll need a fancier query, but for most cases it'll work fine.

how to display single record in tabular form?

I want to display single record one by one when button press in tabular form
how to do this in oracle forms?
I'd suggest you to use Forms built-in capabilities and spend time and energy on something else.
i want to display single record when press button single forward and all records when press button double forward
I presume that those buttons ("single" and "double forward") are custom-made buttons (i.e. you created them).
If so, "Double forward" is simple - put EXECUTE_QUERY into its WHEN-BUTTON-PRESSED trigger (assuming that this is a data block, based on a table).
"Single forward" isn't that simple as you can't execute query, so you have to write some code. For example, you could "prepare" result data set into another table, specifying the row number so that you could later use it:
insert into temp_table (rn, deptno, dname, loc)
select rownum, deptno, dname, loc
from dept
where ...
WHERE clause is kind of tricky because user can enter search criteria. How to know it? Use GET_BLOCK_PROPERTY. As it brings scent of dynamic SQL, you'd have to compose the INSERT statement - consider creating a stored procedure which utilizes EXECUTE IMMEDIATE (or, alternatively, see if FORMS_DDL can be used).
As many users can use the same form simultaneously, that "temp table" should be a global temporary table or - if not - you'd have to save user information as well; otherwise, you'll create a chaos.
Suppose data is now prepared. In a form, you'd have to create a parameter (or a global variable) which holds current "row number" (rn) value. "Single forward" button's trigger would then
last_record;
create_record;
select deptno, dname, loc
into :blk.deptno, :blk.dname, :blk.loc
from temp_table where rn = :parameter.rn;
-- prepare the next row
:parameter.rn := :parameter.rn + 1;
OK, now you have your data, and new problems arrive. As it is a data block, inserting values into it in that manner presumes that you inserted brand new set of information, and Forms will treat it like that. So, if you try to save it, you'll get a unique key violation (which is OK) or duplicate data (which is bad).
It means that "data block" should, actually, be a "control block", which isn't related to a table. Furthermore, it means that "Double forward" can't work the way I described, but by modifying "Single forward" button's code (don't fetch row-by-row, but all of them at once).
If it is a control block, now you have to find a way to store modified values as well as newly added records, so you'd have to create your own ON-INSERT, ON-UPDATE, etc. triggers.
Shortly, I don't think that what you want is a simple task. Did I already say that you shouldn't do it in the first place? Well, I still think so.
Hopefully, someone else will have a better, simpler suggestion.

PL/SQL: ORA 01422 fetch returns more than requested number of rows

I am developing an order transaction where a user can order a product. Once they clicked the 'add to cart' button, it will be able to save on the database in how many times they want with the same order id. Order id is like a transaction id.
My problem is that whenever I want to display the items that customer ordered, it displays an error or ORA 01422. How can I resolve this error?
Here is my code
DECLARE
order_item_id NUMBER;
BEGIN
order_item_id := :MOTOR_PRODUCTS_ORDER.M_ORDERID;
SELECT MOTOR_ID,
MOTOR_QTY_PURCHASED,
UNITPRICE
INTO :MOTOR_ORDER_ITEMS.MOTOR_ID,
:MOTOR_ORDER_ITEMS.MOTOR_QTY_PURCHASED,
:MOTOR_ORDER_ITEMS.UNITPRICE
FROM MOTOR_ORDERS
WHERE motor_order_id = order_item_id;
END;
As krokodilo says, this error is caused because your query returns multiple rows. Depending on what you want to do, you have a couple of options.
If you want multiple values then either use a loop and process them one row at a time (if you are going to be performing a dml operation use bulk collect). If you only want a single row then narrow your result set down with an extra where clause, or use MAX to ensure you only get one value back.
If there is more than one row which will be returned from a query you'll need to use a cursor. One way to do this is with a cursor FOR loop:
DECLARE
order_item_id NUMBER;
BEGIN
order_item_id := :MOTOR_PRODUCTS_ORDER.M_ORDERID;
FOR aRow IN (SELECT MOTOR_ID, MOTOR_QTY_PURCHASED, UNITPRICE
FROM MOTOR_ORDERS
WHERE motor_order_id = order_item_id)
LOOP
-- Do something here with the values in 'aRow'. For example, you
-- might print them out:
DBMS_OUTPUT.PUT_LINE('MOTOR_ID=' || aRow.MOTOR_ID ||
' MOTOR_QTY_PURCHASED=' || aRow.MOTOR_QTY_PURCHASED ||
' UNITPRICE=' || aRow.UNITPRICE);
END LOOP;
END;
Best of luck.
This looks like a Forms question; is it? If so, my suggestion is to let Forms do that job for you.
According to what you posted, there are two blocks:
MOTOR_PRODUCTS_ORDER (a master block, form type)
MOTOR_ORDER_ITEMS (a detail block, tabular type)
I guess that there is a master-detail relationship between them. If there's none, I'd suggest you to create it. Although you can make it work without such a relationship, it'll be much more difficult. If you are unsure of how to do it, start from scratch:
delete MOTOR_ORDER_ITEMS block (detail)
create it once again, this time by following the Data Block Wizard
Set MOTOR_PRODUCTS_ORDER to be its master block
Relationship is on ORDER_ID column/item
Let's presume that by this point everything is set up. Retrieving items that belong to that ORDER_ID is now very simple:
navigate to master block
enter query mode
enter value into an item that represents ORDER_ID
execute query
End of story. Forms triggers & procedures (which were created by the Wizard) will do its job and retrieve both master and detail records.
No need for additional coding; if you're skilled developer, you can create such a form in a matter of minutes. Won't be beautiful, but will be effective & reliable.
There's really no use in doing it manually, although it is possible. Your code works if there's a single item for that ORDER_ID. For two or more items, as you already know, it'll fail with TOO-MANY-ROWS error.
Basically, if you insist, you should use a loop:
you'd enter ORDER_ID into the master block
as you need to move through the detail block, i.e. use NEXT_RECORD, which is a restricted procedure, you can't use number of triggers (open Forms Online Help System and read about them) so a "Show items" button (with its WHEN-BUTTON-PRESSED trigger) might be just fine
a cursor FOR loop would be your choice
for every row it fetches, you'd populate block items and
navigate to next record (otherwise, you'd keep overwriting existing values in the 1st tabular block row)
As I said: possible, but not recommended.

Oracle APEX Selection list

I have a form on a table with some values (text fields) and a select list. The select list is declared in shared components and shows me values from another table. Also I have some process (after submit) to modify and create new table entry. Everything works fine without propagating values from select list. There are no errors from the process. It looks like the process didn't get a value for :P22_WORKER_LIST from the selection list. It should work when I push the create or save buttons but nothing happened. Every instruction in BEGIN END block runs great without this one.
Process:
BEGIN
<some instructions>
UPDATE "WORKER" SET ACCOUNT_LOGIN = :P22_LOGIN
WHERE SURNAME = :P22_WORKER_LIST;
END;
Thank you for suggestion with the session state. After submiting page it turned out that the value for my :P22_WORKER_LIST is a WORKER_ID instead a SURNAME.
BEGIN
<some instructions>
UPDATE "WORKER" SET ACCOUNT_LOGIN = :P22_LOGIN
WHERE WORKER_ID = :P22_WORKER_LIST;
END;

Apex 5.0 : Action on buttons ? Get value from textfield?

The first problem is that I have a button. I created a process called nextweek( to get data for next week from reservation table). I tried this The PL/SQL only as a trial:
begin
if :RESERVNO is null then
select RESERVNO
into :RESERVNO
from reservation;
end if;
end;
but the page keeps telling me "NO DATA FOUND". I would like to create a report with the result of my PL/SQL Query
My second problem is that I want to take values from a textfield and use it in my PL/SQL Query in another button as the "ACCEPT" in oracle.
As I understand, you need following:
Create report: click Create new page button (or create region if you already have a page), then choose region type Report. Write your source SQL query in the field Region source (choose Source type - SQL Query).
Create an item (textfield). For example, with the name P_MY_ITEM
Create a button. Here you don't need to change default properties. (Action on button click should be Submit page)
Add this item name to the source query in the region. It should look like:
select column1, column2, column3
from table1, table2, table3
where column4 = :P_MY_ITEM
and <other conditions>
After that, user can write something to the input field and press the button, page will be reloaded, and report will be changed accordingly to the item value.

Resources