Home » Developer & Programmer » Forms » insert/update the values into the database tables automatically
insert/update the values into the database tables automatically [message #607568] Mon, 10 February 2014 00:04 Go to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi all,

I have 2 blocks(1database,1control block), i have 1 find button, 5 lov items in the control block canvas,i selected any one of the lov & click on the find button, first navigates to another window & the records displayed at the database block window . So my requirement is i want to isert/update from the navigable window(database block window) & stores the values in the database in the table & click on the save button(main menu in the form)

I don't want to use any buttons. How can i do this please help me.

FIND BUTTON CODE:
DECLARE
    finalstr  VARCHAR2(5000);
    dfinalstr VARCHAR2(5000);
BEGIN
    IF :CONTROL_BLOCK.org_code AND :CONTROL_BLOCK.ficsal_year IS NULL THEN
      fnd_message.Set_string('Please Select Any Item');
 
      fnd_message.show;
    ELSE
      finalstr := 'WHERE 1=1';
 
      IF :CONTROL_BLOCK.org_code IS NOT NULL THEN
        finalstr := finalstr || 'AND ORGANIZATION_CODE =' ||( :CONTROL_BLOCK.org_code );
      END IF;
 
      IF :CONTROL_BLOCK.fiscal_year IS NOT NULL THEN
        finalstr := finalstr || 'AND FISCAL_YEAR =' ||( :CONTROL_BLOCK.fiscal_year );
      END IF;
 
      IF :CONTROL_BLOCK.item_number IS NOT NULL THEN
        finalstr := finalstr || 'AND ITEM_NUMBER =' ||( :CONTROL_BLOCK.item_number );
      END IF;
 
      Go_block('DATABASE_BLOCK');
 
      dfinalstr:= Get_block_property('DATABASE_BLOCK', default_where);
 
      Set_block_property('DATABASE_BLOCK', default_where, finalstr);
 
      Execute_query();
    END IF;
END;


I want When enter data into form field and click on save button. Automatically the record is inserted into database table


Thank You

[Updated on: Mon, 10 February 2014 01:28]

Report message to a moderator

Re: insert/update the values into the database tables automatically [message #607577 is a reply to message #607568] Mon, 10 February 2014 02:20 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
As far as I can tell what you want is forms default behaviour. So why do you think that you need to do anything?
Re: insert/update the values into the database tables automatically [message #607578 is a reply to message #607577] Mon, 10 February 2014 02:24 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Thank you for reply cookiemonster,

set the properties of insert,update and delete as YES right?.If it is not worked what triggers to use for insert/update the records and click on the save menu option in the forms.where to write(block level or form level?

At Block level triggers

1)WHEN-DATABASE-RECORD
:FORECAST_DATA.last_update_date := sysdate;

Begin
	   select Fnd_Global.user_id
         into :FORECAST_DATA.last_updated_by
     from dual;
End;


2)WHEN-CREATE-RECORD
:FORECAST_DATA.creation_date := sysdate;

Begin
	   select Fnd_Global.user_id
         into :FORECAST_DATA.created_by
     from dual;
End;

:FORECAST_DATA.last_update_date := :FORECAST_DATA.creation_date;
:FORECAST_DATA.last_updated_by := :FORECAST_DATA.created_by;


The above trigger not effected to automatically insert/update when i press the save menu in the main menu right?

[Updated on: Mon, 10 February 2014 02:27]

Report message to a moderator

Re: insert/update the values into the database tables automatically [message #607580 is a reply to message #607578] Mon, 10 February 2014 02:28 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
insert, update and delete should be yes by default. If it's not working then you should be getting an error message - if so, what is it?
Re: insert/update the values into the database tables automatically [message #607581 is a reply to message #607580] Mon, 10 February 2014 02:32 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
I'd set the last_update columns in pre-update (and pre-insert if inserts count for setting them).
Re: insert/update the values into the database tables automatically [message #607582 is a reply to message #607580] Mon, 10 February 2014 02:33 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
insert, update and delete should be yes by default. If it's not working then you should be getting an error message - if so, what is it?


Yes you are right cookiemonster. I meant to say is , is this 2 triggers not effected to insert/update automatically .I have to move into the Production that's why i asked you.. Smile

Thank You
Re: insert/update the values into the database tables automatically [message #607583 is a reply to message #607582] Mon, 10 February 2014 02:36 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
mist598 wrote on Mon, 10 February 2014 08:33
is this 2 triggers not effected to insert/update automatically


Not sure what you mean by that.


Re: insert/update the values into the database tables automatically [message #607585 is a reply to message #607583] Mon, 10 February 2014 02:39 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
Not sure what you mean by that.


Ok let me check please.

Quote:
I'd set the last_update columns in pre-update (and pre-insert if inserts count for setting them).


I am not getting you point can you please explain more please?
Re: insert/update the values into the database tables automatically [message #607586 is a reply to message #607585] Mon, 10 February 2014 02:42 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Quote:
I'd set the last_update columns in pre-update (and pre-insert if inserts count for setting them).


I am not getting you point can you please explain more please?[/quote]

I'd put the code to set those items in those triggers rather than the one's you are using. That's what I normally use, but if the triggers you use work feel free to use them.
Re: insert/update the values into the database tables automatically [message #607588 is a reply to message #607586] Mon, 10 February 2014 02:47 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
ok thank you, if i get any error's , i will send you.. Smile
Re: insert/update the values into the database tables automatically [message #607599 is a reply to message #607568] Mon, 10 February 2014 03:25 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi cookiemonster, can i use pre-insert trigger?
Re: insert/update the values into the database tables automatically [message #607600 is a reply to message #607599] Mon, 10 February 2014 03:27 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
yes
Re: insert/update the values into the database tables automatically [message #607603 is a reply to message #607600] Mon, 10 February 2014 04:03 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi cookiemonster , just write the set_record_property in the pre-insert trigger right?
Re: insert/update the values into the database tables automatically [message #607605 is a reply to message #607568] Mon, 10 February 2014 04:21 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
DECLARE 
    v_rec NUMBER; 
BEGIN 
    v_rec := :system.cursor_record; 

    IF : system.cursor_record = 'NEW' 
        OR : system.cursor_record = 'QUERY' THEN 
      Message('This is a new record none of whose values are changed'); 

      Set_record_property(v_rec, 'FORECAST_DATA', status, insert_status); 

      Set_record_property(v_rec, 'FORECAST_DATA', status, new_status); 
    END IF; 
END; 


How will it works the above code , can u please explain... Smile
Re: insert/update the values into the database tables automatically [message #607606 is a reply to message #607605] Mon, 10 February 2014 04:23 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
I don't think it will work. What are you trying to accomplish?
Re: insert/update the values into the database tables automatically [message #607607 is a reply to message #607603] Mon, 10 February 2014 04:26 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
mist598 wrote on Mon, 10 February 2014 10:03
Hi cookiemonster , just write the set_record_property in the pre-insert trigger right?


Who said anything about using set_record_property in pre-insert? I certainly didn't.
Re: insert/update the values into the database tables automatically [message #607608 is a reply to message #607606] Mon, 10 February 2014 04:27 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
I don't think it will work. What are you trying to accomplish?


INSERT_STATUS Specifies that the record is to be marked as an INSERT and should be inserted into the appropriate table when the next commit action occurs.

NEW_STATUS Specifies that the record is to be treated as a NEW record, that is, a record that has not been marked for insert, update, or query. Changed but uncleared or uncommitted records cannot be assigned a status of NEW.

I searched in the Help Navigator in forms.. Smile
Re: insert/update the values into the database tables automatically [message #607609 is a reply to message #607607] Mon, 10 February 2014 04:28 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
Who said anything about using set_record_property in pre-insert? I certainly didn't.


Please help me on how to write ?
Re: insert/update the values into the database tables automatically [message #607610 is a reply to message #607608] Mon, 10 February 2014 04:30 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
I know what the statuses mean.
What I don't understand is:
1) why you're trying to set them at all.
2) Why you think setting the status to insert and then immediately changing it to new is ever a good idea.

So, again, what are you actually trying to accomplish?
Re: insert/update the values into the database tables automatically [message #607613 is a reply to message #607610] Mon, 10 February 2014 04:35 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:

1) why you're trying to set them at all.
So, again, what are you actually trying to accomplish?


To insert new record into the table used Set_record_property(v_rec, 'FORECAST_DATA', status, insert_status);

Quote:
2) Why you think setting the status to insert and then immediately changing it to new is ever a good idea.


Set_record_property(v_rec, 'FORECAST_DATA', status, new_status);

so don't use the new_status right?



Re: insert/update the values into the database tables automatically [message #607615 is a reply to message #607613] Mon, 10 February 2014 04:39 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
mist598 wrote on Mon, 10 February 2014 10:35
Quote:

1) why you're trying to set them at all.
So, again, what are you actually trying to accomplish?

To insert new record into the table used Set_record_property(v_rec, 'FORECAST_DATA', status, insert_status);

When a user types into a database item in a new record forms automatically changes the status of that record to insert.
So why are you trying to set the status at all?
Re: insert/update the values into the database tables automatically [message #607617 is a reply to message #607615] Mon, 10 February 2014 04:42 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
When a user types into a database item in a new record forms automatically changes the status of that record to insert.
So why are you trying to set the status at all?


Yes you are right.can i use insert_record built-in in the on-insert trigger, is this worked for me? to inserts the records into the tables?
Re: insert/update the values into the database tables automatically [message #607619 is a reply to message #607617] Mon, 10 February 2014 04:49 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
So why are you trying to set the status at all?


What condition to be used here?
Re: insert/update the values into the database tables automatically [message #607620 is a reply to message #607617] Mon, 10 February 2014 04:49 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
No you do not have to write insert_record in an on-insert trigger. You should never nee4d to use either that built-in or that trigger.


Do this - pick a table in your dev DB that you can mess around with the data, one with as few restrictions on what data can be entered as possible - or better yet create a new table with a few columns and no constraints.
Create a new form.
Use the datablock wizard to create a DB block based on that table.
Put all the items on the canvas.
Write no code. None. No triggers, no program units, nothing.
Run the form.
Type some data into the fields and click on save - it'll insert a row.
Execute a query.
Modify some data that's return and click on save - it'll update a row.
Delete a row and click on save - check it's deleted from the DB.

Then ask yourself why you keep insisting that you need to write code to allow users to insert/update data.
Re: insert/update the values into the database tables automatically [message #607621 is a reply to message #607620] Mon, 10 February 2014 04:59 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
Do this - pick a table in your dev DB that you can mess around with the data, one with as few restrictions on what data can be entered as possible - or better yet create a new table with a few columns and no constraints.
Create a new form.
Use the datablock wizard to create a DB block based on that table.
Put all the items on the canvas.
Write no code. None. No triggers, no program units, nothing.
Run the form.
Type some data into the fields and click on save - it'll insert a row.
Execute a query.
Modify some data that's return and click on save - it'll update a row.
Delete a row and click on save - check it's deleted from the DB.

Then ask yourself why you keep insisting that you need to write code to allow users to insert/update data.


Yes got it thank you cookiemonster.. Smile I am really very thankful to you , you are really great & good teacher.. Smile

Re: insert/update the values into the database tables automatically [message #607622 is a reply to message #607621] Mon, 10 February 2014 05:01 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi cookiemonster,
I have another issue .In forms 6i lov is have % by default but in oracle forms 11g it is not coming is there any way solve this.
LOV property --> Filter Before Display --> "NO"
But this same lov in 6i form having property as "YES" and is working why it is not working in 11g do you know the reason
Re: insert/update the values into the database tables automatically [message #607895 is a reply to message #607621] Thu, 13 February 2014 04:52 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
I updated existing column, the values are effected in the table, this fine.But ,when i update the existing column and click on the SAVE(from the main menu) menu and i am not getting any messages at the left bottom, how can i ? Please suggest
Re: insert/update the values into the database tables automatically [message #607897 is a reply to message #607895] Thu, 13 February 2014 04:58 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Did you suppress messages by setting :SYSTEM.MESSAGE_LEVEL to a high level?
Re: insert/update the values into the database tables automatically [message #607898 is a reply to message #607897] Thu, 13 February 2014 05:01 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
Did you suppress messages by setting :SYSTEM.MESSAGE_LEVEL to a high level?


No i am not used :SYSTEM.MESSAGE_LEVEL

Re: insert/update the values into the database tables automatically [message #607899 is a reply to message #607897] Thu, 13 February 2014 05:09 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Can write the below code in the pre-form?

:System.Message_Level := '20'; 
Re: insert/update the values into the database tables automatically [message #607900 is a reply to message #607899] Thu, 13 February 2014 05:24 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
I created on form & update the existing as shown below , the values effected at the tables ,but i am not getting message like
transaction complete 1 records applied and saved
/forum/fa/11689/0/
  • Attachment: image1.png
    (Size: 20.09KB, Downloaded 2476 times)
Re: insert/update the values into the database tables automatically [message #607901 is a reply to message #607897] Thu, 13 February 2014 05:31 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Please find the below attached screen i am not write any SYSTEM.MESSAGE_LEVEL in the form
/forum/fa/11690/0/
  • Attachment: image1.png
    (Size: 9.80KB, Downloaded 2380 times)
Re: insert/update the values into the database tables automatically [message #607902 is a reply to message #607901] Thu, 13 February 2014 05:36 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Use a message to check what system.message_level is set to
Re: insert/update the values into the database tables automatically [message #607903 is a reply to message #607902] Thu, 13 February 2014 05:38 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
Use a message to check what system.message_level is set to


Hi cookiemonster, where to write and how to write in which trigger Please help
Re: insert/update the values into the database tables automatically [message #608007 is a reply to message #607903] Fri, 14 February 2014 03:26 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
How to write - look up message builtin in form builder help. As always it explains exactly how it works with examples.
Where to write - key-commit would probably be a good choice in this case.
Re: insert/update the values into the database tables automatically [message #608532 is a reply to message #608007] Thu, 20 February 2014 10:52 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi,

I trying to update the existing fields and click on the SAVE(from the Main Menu), that time i want to show Alerts/Messages 'Do you want to made changes? Yes or No?" Can you please help me, how to use this ? What triggers to use , i set the properties of the Updated Items , Values are getting effected into the Table, But i want a messages please help
Re: insert/update the values into the database tables automatically [message #608533 is a reply to message #608532] Thu, 20 February 2014 11:05 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
put an alert in key-commit.
If user clicks on yes issue commit_form
Re: insert/update the values into the database tables automatically [message #608534 is a reply to message #608533] Thu, 20 February 2014 11:09 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
put an alert in key-commit.
If user clicks on yes issue commit_form


Can you please help me on this
Re: insert/update the values into the database tables automatically [message #608548 is a reply to message #608534] Thu, 20 February 2014 16:49 Go to previous message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
As always oracle form builder help explains how alerts work with examples.
Previous Topic: Multi records block
Next Topic: Calling Trigger
Goto Forum:
  


Current Time: Thu Apr 18 05:15:19 CDT 2024