How to highlight specific record using SET_BLOCK_PROPERTY - oracle

I have form in which when open form then all records shown on the block. User enter number on search option and specific record shown on the block. Now I want when search then all records remain on the block and highlight searched data.
BEGIN
SET_BLOCK_PROPERTY('block',default_where,'column= '||:block2.column);
GO_BLOCK ('block');
EXECUTE_QUERY;
END;
How to achieve this target in oracle forms 11g
Thanks

Please refer below link . This will solve your problem.
You need to create a visual attribute and need to assign at item_instance_property level.
http://www.orafaq.com/forum/t/171952/

Firstly, set Current Record Visual Attribute Group property of block to a spesific Visual Attribute which you'd like to highlight to the visited row of the block.
Then, provided the records are already queried and appears on the screen, a text field( :block2.column ) with a
WHEN-BUTTON-PRESSED trigger with the below code might be used to search among those records by entering the desired value and pressing enter :
go_block('block');
first_record;
while :block2.column != :block.column
loop
next_record;
end loop;

Related

How to solve FRM:40105- Unabel to resolve reference to item problem?

I am new in Oracle forms and reports. I am facing this error.
I have created Employees data block and displaying it to the canvas. I triggered my module as new form instance with execute_query. Then took one display text item and set it's database as no and set this name as search_box and another one is push button, I set it's name as search.
In search block button I have triggered this When button pressed and wrote this code.
begin
set_block_property('EMPLOYEES',default_where,'EMPLOYEE_ID='||':search.search_box');
go_block('EMPLOYEES');
execute_query;
set_block_property('EMPLOYEES',default_where,'');
end;
My Employee_Id is one of my block item but still i can't understand where should I fix to solve this problem.
Please help!
Should be like this - based on Forms Help which says:
Set_Block_Property('emp', ONETIME_WHERE, 'deptno <= :dept.deptno');
Also, you'd rather use onetime_where.
Therefore:
begin
set_block_property('EMPLOYEES', onetime_where, 'EMPLOYEE_ID = :search.search_box');
go_block('EMPLOYEES');
execute_query;
end;
Saying that you can't make it work ... well, I can. Here's a demo.

i have two table with foreign key and i want to press in foreign key in first table and the second table appear data

I have two blocks. First one is wizard and second is manual in Oracle Forms 11g with relational.
I execute the data into first block and I want to press in foreign key in first table and the second table appear data which is link together by the same number foreign key?
Which trigger should I use please? And which code should I put into trigger?
You can use WHEN-NEW-RECORD-INSTANCE trigger at block level of Block1 with code :
declare
v_skulist table1.skulist%type;
begin
v_skulist := :Block1.f_skulist; --> represents left uppermost field
go_block('Block2');
execute_query;
go_block('Block1'); --> go back to the upper block again, if don't want to come back, then starting from this line upto `end;`(exclusive) should be removed.
while v_skulist != :Block1.f_skulist
loop
next_record;
end loop;
end;
where
Query Data Source Name property is set to table1 for Block1
and
Query Data Source Name property is set to myuser1.table2 with
WHERE Clause set to
skulist = :Block1.skulist for Block2
assuming the second table is on the other user at least
with granted select privilege to your current user as mentioned in your comment.
This way, whatever record touched in the first block, the counterpart foreign key column is brought in the second block.
You should have used the data block wizard which creates all necessary triggers and procedures that take care about it.
If you're going to do it manually, well ... you probably shouldn't do that, there are too many procedures involved.
I suggest you remove detail block and create it from scratch, this time using the wizard. Pay attention to what it asks and - once you're done - the form will automatically do what you want it to.
Then, you can review what objects Forms created for you and - if you really REALLY want to do it manually, try to mimic its steps.

Search records on block very slow oracle forms

I have procedure in which enter Visit Number and search records on block. But this procedure search records take some time 3 to 4 minutes and block have 12672 records. How to optimize procedure to search records fast.
CODE:
DECLARE
BEGIN
IF :CTRL_BLOCK.SRCH_VISITNO IS NULL THEN
MESSAGE('Please enter Visit No...');
GO_ITEM('SRCH_VISITNO');
ELSE
BEGIN
GO_BLOCK('cpvdtl');
FIRST_RECORD;
LOOP
IF :cpvdtl.visitno = :CTRL_BLOCK.srch_visitno THEN
exit;
ELSE
NEXT_RECORD;
END IF;
EXIT WHEN :SYSTEM.LAST_RECORD='TRUE';
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
MESSAGE('No Data found...!');
END;
END IF;
:CTRL_BLOCK.srch_visitno := null;
go_item('cpvdtl.visitno');
END;
Why reinventing the wheel?
Default Forms functionality works perfectly well, as simple as:
create a block on a table
run the form
enter query mode
enter search criteria into any column (wildcards included)
execute query
If any record matches criteria, it will be displayed on the screen.
If you insist on your own search field, create it (which is what you already did). Then:
I'd suggest you to create a push button
create a WHEN-BUTTON-PRESSED trigger which will
utilize SET_BLOCK_PROPERTY built-in, using the ONETIME_WHERE (or DEFAULT_WHERE; see which fits better) property, by setting the search field's value into the block's where clause
EXECUTE_QUERY
Why button and not only the search field? Because you'd then use WHEN-VALIDATE-ITEM trigger to SET_BLOCK_PROPERTY, but you couldn't EXECUTE_QUERY in that trigger as it is a restricted procedure. Yes, you could use KEY-NEXT-ITEM trigger, but - what if user navigates out of the search field using the mouse? That trigger wouldn't fire. I'd say that button is a simpler choice.

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.

How to call a set focus on a form creation

I'm creating a small application with some 'Search' hotkeys, F1 to F4 to search into different tables of a database, so I've created a TPageControl to hold the search fields and also display the results, so I have 1 PageControl and 4 tab sheets, but I'm trying to put one if statement to set the focus on the proper search field and I'm calling it on the OnShow event of the TPageControl, but I'm getting a error message: Form:TForm cannot focus
If I didnt got it all wrong, it's because the text field cannot be found, considering I'm showing the page before the application can create the elements inside of this page, so, how can I edit this code or where can I use it to make it works, just remembering that I need to call this procedures with the hotkeys later on.
The procedure I'm using to set the focus is just a simple IF with 4 conditions in my real case:
procedure TForm.searchFocus; begin
if pgcSearches.TabIndex=0 then begin
editFieldNames.SetFocus;
end
else if pgcSearches.TabIndex=1 then begin
editFieldAdresses.SetFocus
end;
end;
A more 'explicit' help from another forum:
procedure TfrmMain.pcSearchesChange;
begin
case pcSearches.TabIndex of
0: ActiveControl:=edtSearchSongs;
1: ActiveControl:=edtSearchBibles;
2: ActiveControl:=edtSearchWarning;
end;
if Visible then
ActiveControl.SetFocus;
end;

Resources