Selected items with check box should be printed - oracle

I have an entry with child data and here is check button with child items. If I check the items, then selected item should be printed - not all child items of this parent. How to do that?

The simplest option I can think of is to commit changes you've made (i.e. store checkbox values into the table).
Then call the report by passing the "master" row ID. Report's query would then look like this:
select some_columns
from master_table m join detail_table d on d.master_id = m.master_id
where m.master_id = :par_master_id
and d.checkbox = 1
The where condition would make sure that only checked rows are printed.
In order to "reset" it, you could use the "After Report" trigger and
update detail_table set
checkbox = 0
where master_id = :par_master_id
However, this won't work in multi-user environment as many users could work with same data and "overwrite" each other's checkboxes. Better option would be to create additional table and store [user, master_id, detail_id] rows so that everyone uses their own values.
Or, while in form, if there aren't too many child records, use a loop to concatenate IDs of checked rows and pass them to the report which would split that string into rows.

Related

Pre Populate Text Fields in Apex

I'm trying to fill out various text fields on an apex application when I select a Reference Number in a select list.
When the page loads I'd like the text fields to be filled with the information from the database related to the reference number from the select list, however, I don't know how to do so. Any suggestions or help would be most appreciated!
As far as I understood the question:
user opens a page
there's a Select List item
user picks a value
you want to populate certain items on that page, based on a value user previously selected
If that's so, you'd use a dynamic action - create it on the Select List item, pick set value type.
[EDIT: How to do that?]
Scott's schema, DEPT table. Suppose that the select list item is P15_DEPTNO, while two other items are P15_LOC and P15_DNAME.
create a dynamic action on P15_DEPTNO
event: change
item: P15_DEPTNO
create its True action:
action: set value
type: SQL statement
select loc, dname
from dept
where deptno = :P15_DEPTNO
items to submit: P15_DEPTNO
affected elements: items P15_LOC, P15_DNAME
That's all.

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

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.

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.

CheckBox in Oracle Forms

I have a Database block contains 3 columns. in that all are character columns.
I have created a multi record block in a form which contains 2 text item and one check box.
The values in the table are like below
col1 col2 col3
value1 value2 N
Value3 value4 N
Value5 value6 Y
In the form, I want to find only the records with Value 'N' in the col3.
I want to find the values using Enter - Query, Execute Query method, But here in my form, col3 is the checkbox. if ticked -Y, not ticked value will be 'N'.
I know, we cannot search 'N' values using Enter - Query, Execute Query method.
Is there Any other way we can search?
Your problem is that in enter-query standard functionality is that the checkbox contains an empty value (null) and is not unchecked. To search for an unchecked value just go in enter-query mode and click the checkbox to have the "Y" value in your case and click it again to have the "N" value. From now on you can check and uncheck the value.
If you have made a mistake and want it to be empty again use the clear item key to set it back to null.
If you want to allow querying the block based on the checkbox, you need to have the checkbox values stored somewhere, probably in a Y/N column on the table that the block is based on.
Before the block is queried, you'd just need to ensure the checkbox values are posted to the database.
If you can't save them to the table itself, an alternative would be to save them somewhere else, but it has to be something accessible to the query itself - e.g. a global temporary table.
Why not use the check box to enter the needed search criteria form col3? I can't see why that should not be possible and I even tested it quickly. Please try the following
Set properties of your checkbox for col3 as follows
Value when Checked = Y
Value when Unchecked = N
Check Box Mapping of Other Values = Not Allowed
Initial Value = N or Y whatever suites your business need
Database Item = Yes
Column Name = col3
If using this kind of settings you can in Enter Query mode select if you want the query for col3 = N by making sure that the check box is unchecked when executing the query.

inline view query

I wanted to delete some records which i added recently, from this table mytemp, please tell me what is wrong with this query,
data in selected column had been populated using cursor
DELETE FROM (SELECT ROWNUM RM, S from mytemp) where rm > 20;
error is:
ORA-01732: data manipulation operation not legal on this view
Edited for accuracy...
Here's the description of the error you are getting:
http://ora-01732.ora-code.com/
An attempt was made to use an UPDATE, INSERT, or DELETE statement on a
view that contains expressions or functions or was derived from more
than one table. If a join operation was used to create the view or the
view contains virtual columns derived from functions or expressions,
then the view may only be queried.
So it looks like an updateable view can be substituted for a table, as long as it doesn't join more than one table or use virtual columns. In your case, the problem is the virtual ROWNUM column.
It's the rownum>20 statement.
ROWNUM>x, where x values greater than a positive integer are always false.
select * from ANYTABLE where rownum>(ANY POSITIVE INTEGER)
doesn't return any record.
The first row fetched is assigned a ROWNUM of 1 and makes the condition false. The second row to be fetched is now the first row and is also assigned a ROWNUM of 1 and makes the condition false. All rows subsequently fail to satisfy the condition, so no rows are returned.
Check THIS for further info.
You can do the following:
delete from (select amount from TABLE t where t.amount=1000)
but it's the same as
delete from TABLE where amount=1000

Resources