Disable Form Buttons for Specific Time in oracle 10g - oracle

I want to Disable five Buttons(Student,Parent,Guardian,Employee,Salary) from MENU Form for during non-business hours i-e 8am-1pm(8-13)
I code this in FormBuilder > DatabaseObjects > MyDB(i-e School) >Tables >MENU>Triggers
When i Save it it show error
ERROR:
PDE-UTG007 Trigger contains an error
PLS-00201:identifier'ENABLED'must be declared
BEGIN
IF (TO_CHAR(SYSDATE,'DY') IN ('SAT','SUN')) OR (TO_CHAR(SYSDATE,'HH24:MI') NOT BETWEEN '08:00' AND '13:00')
THEN
set_item_property('control.Student', enabled, property_false);
set_item_property('control.Parent', enabled, property_false);
set_item_property('control.Guardian', enabled, property_false);
set_item_property('control.Employee', enabled, property_false);
set_item_property('control.Salary', enabled, property_false);
RAISE_APPLICATION_ERROR(-20500, 'You can access Database only during normal business hours.');
END IF;
end;
enter image description here

This code should be created in Forms' Triggers internally, not in a Database Trigger with converting RAISE_APPLICATION_ERROR to MESSAGE('You can...'); MESSAGE(). You can embed the code within a Procedure of Forms such as
PROCEDURE Disable_Buttons IS
BEGIN
IF (TO_CHAR(SYSDATE, 'DY','NLS_DATE_LANGUAGE=ENGLISH') IN ('SAT', 'SUN')) OR
(TO_CHAR(SYSDATE, 'HH24:MI') NOT BETWEEN '08:00' AND '13:00') THEN
SET_ITEM_PROPERTY('control.Student', enabled, property_false);
SET_ITEM_PROPERTY('control.Parent', enabled, property_false);
SET_ITEM_PROPERTY('control.Guardian', enabled, property_false);
SET_ITEM_PROPERTY('control.Employee', enabled, property_false);
SET_ITEM_PROPERTY('control.Salary', enabled, property_false);
MESSAGE('You can access Database only during normal business hours.');
MESSAGE('');
END IF;
END;
and call Disable_Buttons from WHEN-NEW-FORM-INSTANCE trigger, along with WHEN-BUTTON-PRESSED triggers of those five buttons as at the top of the existing codes in order to prevent the execution of the rest of the code for already running sessions of applications during those periods.
Or as being more straightforward, you can add the Disable_Buttons into WHEN-NEW-BLOCK-INSTANCE trigger of control block instead of individually adding into the WHEN-BUTTON-PRESSED triggers of those five buttons.

Related

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.

Unlock deselected query record in oracle form 12c

This is my first time using for update nowait in Oracle Forms 12c in order to lock a record.
I have a master-detail Forms blocks, both data block are being shown in tabular layout style. The master block is allowed to update.
When double click a master record after query block, it will go to details block and fire execute_query.
I need to lock the master record manually when double click it.
In data block trigger when-double-click, I put the following:
declare
t_dummy varchar2(10);
begin
--rollback;
Select 'y'
into t_dummy
from table
where voucherno=:master.voucherno
for update nowait;
go_block('detail');
execute_query;
exception
when others then
message('Fail to lock record. Other user is locking it.');
raise form_trigger_failure;
end;
I have no idea where/how to use rollback. I need to unlock the record when
deselect the master record;
exit form;
querying record;
I try to put rollback as marked in the above but failed, it cleared the master block.
Please help

Oracle PL/SQL Trigger asking for binds

I'm trying to create my trigger but it's asking for binds EVERY time. It works the way I want it to when I click apply on the window that appears... However, it will log an error...
My trigger checks to see if a client is active or not and do NOT allow changes if it is found to be active...
CREATE Trigger Client_Activity
BEFORE Insert or Update or Delete ON Client
FOR EACH ROW
DECLARE
VAR_AC char(2);
BEGIN
IF UPDATING THEN
SELECT Activity INTO VAR_AC
FROM Client_Additionals
WHERE Activity = :Old.Activity;
IF Activity = 'AC'
THEN Raise_Application_Error(-20999, 'active')
END IF;
END;
/
ORACLE VERSION 12 USING SQLDEVELOPER
You have two syntax errors in your trigger:
The IF is missing an END IF
You need to compare the content of the variable var_ac
You are missing a ; after the Raise_Application_Error()
Putting that together, you can create the trigger without problems.
However, you need to use the "Run Script" button in SQL Developer to run a PL/SQL block like that.
SQL*Plus requires no special handling:

post-text-item can't accept commit

Can anybody suggest a good trigger that I can use in a text box. The operation that i intend to use in the text box is when the user changes the value in the text box, I call a Procedure that updates that value in the Database table with a commit. However ,so the moment the user changes the value and presses enter it should go to the next item, before which it updates the DB. It works fine in the KEY-NEXT-ITEM trigger. However, one problem is that say the user changes the value in the fld , but does not press tab or enter, but directly F10 to commit. My trigger in the text box(i.e KEY-NEXT-ITEM) does not fire. I tried a POST-TEXT-ITEM , but it does not let me use the ,COMMIT or NEXT_ITEM built ins. I want the trigger to fire the moment the user exits the item and also it should go to the next item in the form
Use WHEN-VALIDATE-ITEM trigger. This trigger is basically intended to validate value entered by user. It fires every time when forms decided, that user finished field value - when user leaves field, when user presses commit, etc.
Unfortunately you are not able to use COMMIT_FORM in this trigger. Forms recommend make direct database changes in transactional triggers only. To implement database change with commit, make your database procedure running in autonomous transaction:
CREATE OR REPLACE PROCEDURE do_somethning (some_id NUMBER, some_value VARCHAR2) AS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
UPDATE some_table SET some_column = some_value
WHERE table_id = some_id;
COMMIT;
END do_somethning;
Yout WHEN-VALIDATE-ITEM trigger can be like this
BEGIN
-- probably do some validations
...
-- call your procedure
do_something(:some_block.id, :some_block.your_field);
END;

Oracle Forms - Commit Single SQL Statement Instead of Entire Form

I'm working on an Oracle Form (10g) that has two blocks on a single canvas. The top block is called QUERY_BLOCK which the user fills out to fill PRICING_BLOCK with rows of data.
However, in QUERY_BLOCK I also have a checkbox which needs to perform an INSERT and DELETE on the database, respectively. My WHEN-CHECKBOX-CHANGED trigger looks like this:
begin
if :query_block.profile_code is not null then
if :query_block.CHECKBOX_FLAG = 'Y' then
begin
INSERT INTO profile_table VALUES ('Y', :query_block.profile_code);
end;
else
begin
DELETE FROM profile_table WHERE profile_code = :query_block.profile_code and profile_type_code = 'FR';
end;
end if;
end if;
end;
I know that I need to add some sort of commit statement in here, otherwise the record locks and nothing actually happens. However, if I do a COMMIT; then the entire form goes through validation and updates any changed rows.
How do I execute these one-line queries I have without the rest of my form updating as well?
Without commenting on the actual wisdom of this, you could create a procedure in the database that performed an autonomous transaction:
CREATE OR REPLACE FUNCTION my_fnc(p_flag IN VARCHAR2)
RETURN VARCHAR2 IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
IF p_flag = 'Y' THEN
INSERT...
ELSE
DELETE...
END IF;
COMMIT;
RETURN 'SUCCESS';
EXCPTION
WHEN OTHERS THEN
RETURN 'FAIL';
END;
Your Forms code could then look like:
begin
if :query_block.profile_code is not null then
stat := my_fnc(:query_block.CHECKBOX_FLAG);
end if;
end;
This allows your function to commit independent of the calling transaction. Beware of this, however - if your outer transaction must roll back, the autonomous transaction will still be committed. I would think there should be a transactional way to do what you need done to solve your locking problem, which would likely be the superior approach. Without knowing the specifics of your process, I can't tell. Generally speaking, autonomous transactions are used when an update must occur regardless of whether the transaction commits or rolls back, e.g., logging.

Resources