How to save the data in a different column instead of replacing the data in same column - oracle

I have one field on my form (field example name "completion_date"). This data is stored to table column "completion_date". When users edits the detail, data is overwritten in the backend table field as a default way of storing the data. How can I pass on the existing data in this column to a new column (completion_date_a) when the user saves a new date in the field.

One option is to create a database trigger, e.g.
create or replace trigger trg_bu_date
before update on your_table
for each row
begin
:new.completion_date_a := :old.completion_date;
end;
/

Littlefoots' answer is correct, but you could also do this in apex with very little work. Suppose your form items are P1_COMPLETION_DATE and P1_COMPLETION_DATE_A, both mapped to their respective database column. P1_COMPLETION_DATE_A is hidden. Add a computation to P1_COMPLETION_DATE_A with point "After Header" and type "Item". Pick P1_COMPLETION_DATE as item.
Now when you save the form, the value of P1_COMPLETION_DATE_A will be set to the value of P1_COMPLETION_DATE when it was selected.

Related

Populate data from DB and save as new record oracle forms

I Have populated master detail block from Data based want to change some values in data block and save it as a new record in Both master and child tables.
To Populate used execute query
Changed values as record
Save by commit
But as i used execute query to populate existing data on commit it is trying to update already saved data in table. But i want to create new records in DB with new primary key
That won't work, as you noticed. Records you fetched are database records so - once you update their values and commit, you overwrite data.
If you want to insert new records, then
add them into new rows - you can do that manually (by typing those values), or
you can duplicate one of previous records into a new record (use Forms menu for that or a shortcut key; look for "duplicate record" option) and modify that duplicated record.
Alternatively, don't use data block but control block (the one that isn't based on a database table). Populate it, somehow (e.g. you could create a button which calls the procedure; it uses a loop and populates record-by-record). Modify values you want and create your own procedure which will insert new rows into the database table. As of the primary key, it depends on how you do it; if it is a database trigger which uses a sequence, it (the trigger) will do the job. Otherwise, you'll have to create a primary key yourself (during the insert process).

session item does not change when using lov in primary key

I am implementing a Interactive grid to perform DML operations on a table.
it has combined primary key of two columns
One primary key column is display only and refer to master table and another primary key column I want to have a LOV to select value. LOV is dynamic lov having a display and return value picked from another table.
Inserts are fine but session state item value is set for one row and all the operations are performed on that same row irrespective of which row is selected.
you can see a sample here
https://apex.oracle.com/pls/apex/f?p=128616:2:1964277347439::NO:::
master table name: sample
detail table name: sample_child
primary key in sample child : ID and Name
pop lov is implemented in NAME
LOV values are picked from table: Sample_uncle
LOV display : ID || '-' || NAME
LOV return : ID
you can try to update blabla column of sample_child table to see the issue.
I am not sure how I can give you access to look at the implementation.
I have already tried all the options I can think of
This is to do with your primary keys, the detail table does not appear to have proper ones, thats why it always tried to update the first entry, and I think this is also why every row is marked when you load the table.
Primary keys also do the annoying thing of refusing to be empty, as you can see if you insert a new row, the middle column(which is a PK) is filled with 't1001'.
Since you are dealing with simple tables(and not a whole bunch of joined tables) I always consider it best to use ROWID as PK. So set ROWID as PK for the master table, and ROWID for the detail table. And have the detail table have a Master table be your master table, and then click on the first column in the detail table and set the master column for it. And I also personaly always hide the column that is linked.
I would advise you use ROWID whenever possible as its just so much easier to work with, it does mean you might need to set up a validation to prevent someone adding duplicated values for your actual PK, but since the PK is in the underlying table, they cant enter it anyways(but if you have a validation, the error will be much prettier), whilst if the column is a PK, APEX will prevent duplicates by default.
I hope this helps

Update value in oracle form

I have a database table Land with colums:
serial, seller_name, sell_date, sell_price
I am using a datablock named land. To update the table I am using the same datablocks field. I am using a lov to take the already saved values and I am dropping those values in the datablock land.
I want to update the values based on the serial number. I am using on button pressed trigger under a button and used the commit_form. But every time new data is inserted with the same serial number. I am looking for a way to update the table for that specific serial number.
To load the right row into the data block, you have to do the following in your trigger:
enter_query(no_validate);
:serial := your_lov.whatever;
execute_query;
This will connect the datablock with the correct row, instead of overwriting another row.

Oracle Apex Tabular Form Data Lost

I have a Tabular Form in my Oracle Apex application. There is a column as UPDATED_DATE. I have set Tabular Form Attributes of this column as below.
When i'm inserting data, UPDATED_DATE column in database table is filling with a value. But when i'm updating existing record, UPDATED_DATE column is not filling with a new value. old date is remaining without changing to a newer data.
How can i solve this ?
The default will only set a value if the field is empty. On your first entry the field is empty, and therefore the updated_Date is set. On updating, the field is allready set, and therefore won't be updated.
You need to create a dynamic action (assuming you use apex 4 or above) and use that to update the date field. Your dynamic action should be triggerd on change of an table row and subsequently set the date field to the current date.
Let me now if you need help on the dynamic action.

prevent last record in access table to be deleted

I made a loginform for my access database but how to prevent anyuser to delete the last record
Ex: if there is two records in login_table or more. The user can delete all the record but not the lastone
There are many ways to do that:
1. Create constraint on your server side code to check whether there is only one record at the time of deleting the records.
2. Create a trigger on the table which prevents the user from deleting the last record.
Probably the easiest way to accomplish this in Access 2013 would be to create a "Before Delete" data macro that looks like this:
If DCount("*","Table1")<2 Then
RaiseError
Error Number 1
Error Description You cannot delete the last remaining record in this table.
End If
To create this data macro, open the table in Design View, then on the "Design" tab of the ribbon click "Create Data Macros" and choose "Before Delete". (Remember to replace "Table1" with the actual name of your table.)
The previous record is saved in the table so it can be deleted. The record being entered is not actually saved in the table until the form is closed or an action is taken to enter another record.
On an entry form I create a duplicate table with the same fields. The entry form places the data temporarily into the first table. Then I created two queries. One to update from the temporary table to the secondary table. The second query clears the first table making it ready for new data entry. The action of the query requires to command entry to save the record prior to running the two queries. I perform this by creating a macro to perform the actions in sequence. 1. save record, 2 copy the data to the second table, 3 clear the first table.
You will have better control over the data.

Resources