Updating a row of table.
Hi,
I have a requirement in which, there is a table with say 5 columns and each column is an outputtext except the last 1. The last 1 has both outputtex and commandlink under it. The requirement is, when I click the command link of a particular row, it should display a symbol like * in the output text of that row and that column only. I have tried few methods but it is setting the output text of all the rows of that column to *.
Please help me in this regard.
Thanq.
First make it clear: analyze table command never changes ROWIDs. Actually, the ROWID of a row never changes untill it's deleted from its table. So make sure if you are using the correct ROWID.
Thnx
Similar Messages
-
How to update duplicate row from table
Hi,
how to update duplicate row from table?
First to find duplicate row then update duplicate row with no to that duplicate row in oracle.
can you give me suggestion on it?
Thanks in advance.
your early response is appreciated...In order to find a duplicate row, see:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1224636375004
(or search this forum, your question has been asked before)
In order to update it, just create and use an Oracle sequence, have it start and increment at a value that doesn't exist in your table.
If that doesn't get you going, post some CREATE TABLE + INSERT INTO statements, and the results you want from them, in other words: a complete testcase. -
Updating certain rows of table by external file??
Hello gentlemen,
I need your help.I have a very large table.I need to update certain rows of table every day(around 200 per day)
I would like by using an external file (.csv or .txt) to update certain column on the 200 rows i have in the external file.
Can this be done?Do i need to write down a pl/sql procedure?Please help.I am a newbie to pl/sql but it will save me much time every day if i manage to do this.
Thank you in advance for your help.I made a first attempt to create the external table from a .txt file.
I used the below:
CREATE TABLE pol_test
(STATUS VARCHAR2(30 CHAR),
ASFAL VARCHAR2(20 CHAR)
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY def_dir1
ACCESS PARAMETERS
(RECORDS DELIMITED BY STRING
FIELDS (STATUS VARCHAR2(30 CHAR),
ASFAL VARCHAR2(20 CHAR)
LOCATION ('C:\Users\t.christopoulos\Desktop\TEST.TXT')
I get the below error :
Error report:
SQL Error: ORA-06564: object DEF_DIR1 does not exist
06564. 00000 - "object %s does not exist"
*Cause: The named object could not be found. Either it does not exist
or you do not have permission to access it.
*Action: Create the object or get permission to access it.
I suppose that it goes to create the directory on the server where i dont have access.I run these commands from my desktop using SQL developer. -
Problem to update 16 rows, it updates all rows in table
I tried to update 16 rows with AL as divion name with the script as below:
Update wire_center a set a.wg_id='63'
where EXISTS (select b.div_name from wire_center a, division b, district c, ns_workgroups d
where B.DIV_NAME='AL' AND a.dis_id=c.dis_id and b.div_id=c.div_id and d.wg_id=a.wg_id );
When I run it, it updates all the rows in the table.
However when I run the select subquery, it returns 16 rows.
It seems where EXISTS is the problem. if I take exists out, it gave me ora-00936 error.
How to fix it? Please need urgent help. db is 10g.
Thanks in advance.If I understand correctly what you want, you should not include wire_center again in the second select (in your exists clause).
The second select has no relation to the table you are updating, so because the second select returns 16 rows, the exists will always be true. For every row. So every row will be updated.
Instead of
Update wire_center a set a.wg_id='63'
where EXISTS (select b.div_name from wire_center a, division b, district c, ns_workgroups d
where B.DIV_NAME='AL' AND a.dis_id=c.dis_id and b.div_id=c.div_id and d.wg_id=a.wg_id );try this:
Update wire_center a set a.wg_id='63'
where EXISTS (select b.div_name from division b, district c, ns_workgroups d
where B.DIV_NAME='AL' AND a.dis_id=c.dis_id and b.div_id=c.div_id and d.wg_id=a.wg_id );Edited by: theoa on 29-dec-2010 14:27 -
Updating a row in table exclusive lock on entire table
Hi
We have table master table and few child tables .
when we try to update a row in master table , it is locking entire table
i.e seems update process holding exclusive lock on entire table
it is not allowing any furthur update to that table
Could you please tell me what could be the problem for that
Thanks,
- AKDoes the table has primary key - foreign key relationship? Try disabling the constraint and see if it works. If it works then it is about unindexed foreign key issue.
-
Trouble updating multiple rows in table using subquery
Hi everyone, I'm having trouble updating multiple rows with a subquery. Here's the setup:
create table mytable (
col_a number primary key,
col_b number,
col_c number,
col_d number);
insert into mytable values (1 ,1,1,15);
insert into mytable values (2 ,1,2,7 );
insert into mytable values (3 ,1,3,11);
insert into mytable values (4 ,1,4,23);
insert into mytable values (5 ,1,5,14);
insert into mytable values (6 ,2,1,50);
insert into mytable values (7 ,2,2,41);
insert into mytable values (8 ,2,3,13);
insert into mytable values (9 ,2,4,12);
insert into mytable values (10,2,5,19);
insert into mytable values (11,3,1,10);
insert into mytable values (12,3,2,92);
insert into mytable values (13,3,3,81);
insert into mytable values (14,3,4,17);
insert into mytable values (15,3,5,66);
insert into mytable values (16,4,1,54);
insert into mytable values (17,4,2,41);
insert into mytable values (18,4,3,22);
insert into mytable values (19,4,4,24);
insert into mytable values (20,4,5,17);For this example, using an update statement (or merge if that's better), say I want to set the values for col_d where col_b = 3 equal to the values for col_d where col_b = 1 and col_c equal each other. Results should look like the following after the update:
col_a col_b col_c col_d
1 1 1 15
2 1 2 7
3 1 3 11
4 1 4 23
5 1 5 14
6 2 1 50
7 2 2 41
8 2 3 13
9 2 4 12
10 2 5 19
11 3 1 15
12 3 2 7
13 3 3 11
14 3 4 23
15 3 5 14
16 4 1 54
17 4 2 41
18 4 3 22
19 4 4 24
20 4 5 17I can see it right there at my fingertips using this query, where I want to set b_col_d = a_col_d, but I'm missing something, as this query returns too many rows when used in the update statement.
select * from (
select col_a as a_col_a, col_b as a_col_b, col_c as a_col_c, col_d as a_col_d
from mytable
where col_b = 1
) a, (
select col_a as b_col_a, col_b as b_col_b, col_c as b_col_c, col_d as b_col_d
from mytable
where col_b = 3
) b
where a.a_col_c = b.b_col_cupdate mytable set column_d = (select ??? where exists ???)
Can someone help me get there? I'm using 10GR2.
Thanks!
MarkHopefully this is what you are looking for:
SQL > UPDATE mytable myt1
2 SET col_d = ( SELECT myt2.col_d
3 FROM mytable myt2
4 WHERE myt2.col_b = 1
5 AND myt1.col_c = myt2.col_c
6 )
7 WHERE col_b = 3
8 AND EXISTS
9 ( SELECT NULL
10 FROM mytable myt2
11 WHERE myt2.col_c = myt1.col_c
12 )
13 ;
5 rows updated.
SQL > SELECT * FROM mytable ORDER BY col_a;
COL_A COL_B COL_C COL_D
1 1 1 15
2 1 2 7
3 1 3 11
4 1 4 23
5 1 5 14
6 2 1 50
7 2 2 41
8 2 3 13
9 2 4 12
10 2 5 19
11 3 1 15
12 3 2 7
13 3 3 11
14 3 4 23
15 3 5 14
16 4 1 54
17 4 2 41
18 4 3 22
19 4 4 24
20 4 5 17
20 rows selected.Thank you so much for providing the sample data in an easy to consume form, as well as the expected output. -
Procedure - updating 2 rows in table
Hi!
The following procedure works fine, however the update part updates only 1 row.
create or replace procedure FLIGHT (p_ptc_adult IN NUMBER,
p_origin IN favailability.origin%TYPE,
p_destination IN favailability.destination%TYPE,
p_service_class IN favailability.service_class%TYPE,
p_flightdate IN favailability.flight_date%TYPE,
p_flightdate_rt IN favailability.flight_date%TYPE ) is
Cursor c1 is
select a.carrier_code, a.flight_no, a.origin, a.dept_time, a.destination, a.arr_time, a.flight_date,
a.aircraft_type, a.booking_class, a.service_class, a.occ_first, a.occ_business, a.occ_economy, a.fare_basis, a.rt_fare, a.tax, a.surcharges, a.fare_total
from favailability a, main_related_flight b
where a.flight_leg_id = b.flight_leg_id_1
and a.origin = p_origin
and a.service_class = p_service_class
and a.flight_date = p_flightdate
union
select d.carrier_code, d.flight_no, d.origin, d.dept_time, d.destination, d.arr_time, d.flight_date,
d.aircraft_type, d.booking_class, d.service_class, d.occ_first, d.occ_business, d.occ_economy, d.fare_basis, d.rt_fare, d.tax, d.surcharges, d.fare_total
from favailability d, main_related_flight e
where d.flight_leg_id = e.flight_leg_id_2
and d.origin = p_destination
and d.service_class = p_service_class
and d.flight_date = p_flightdate_rt
order by flight_date;
f_rec c1%ROWTYPE;
v_economy_class favailability.occ_economy%TYPE;
v_economy_class_rt favailability.occ_economy%TYPE;
v_ptc_adult number;
e_no_passenger exception;
Begin
-- truncate table
-- execute immediate 'truncate table FL_ITINERARY_T';
v_ptc_adult := p_ptc_adult;
-- open cursor
Open c1;
Loop
fetch c1 into f_rec;
exit when c1%notfound;
-- check number of seats for outbound flight
if nvl(trunc(p_ptc_adult), 0) = 0
then
raise e_no_passenger;
end if;
select occ_economy into v_economy_class
from favailability
where origin = p_origin
and destination = p_destination
and service_class = p_service_class
and flight_date = p_flightdate;
if p_ptc_adult > v_economy_class then
dbms_output.put_line ('No seats available!');
elsif v_economy_class < 2 then
dbms_output.put_line ('No seats available!');
else
-- This part is updating only 1 row
-- Only the outbound flight is updated with the total number of travellers, but the return flight is not updated
-- Can't figure out where the problem is
update favailability set occ_economy = occ_economy - p_ptc_adult
where v_ptc_adult = p_ptc_adult
and origin = p_origin
and destination = p_destination
and service_class = p_service_class
and flight_date = p_flightdate;
end if;
-- insert records
insert into fl_itinerary_t (rid, carrier_t, fno_t, origin_t, dept_t, destination_t, arr_t, fdate_t, aircraft_type_t, booking_class_t, service_class_t,
economy_t, business_t, first_t, fare_basis_t, fare_t, tax_t, surcharges_t, fare_total_t)
values (new_res_seq.nextval, f_rec.carrier_code, f_rec.flight_no, f_rec.origin, f_rec.dept_time, f_rec.destination, f_rec.arr_time, f_rec.flight_date, f_rec.aircraft_type, f_rec.booking_class,
f_rec.service_class, p_ptc_adult, null, null, f_rec.fare_basis, f_rec.rt_fare, f_rec.tax, f_rec.surcharges, f_rec.fare_total);
-- show itinerary
dbms_output.put_line ('Itinerary completed!');
dbms_output.put_line (v_ptc_adult || ' seats reserved!');
Commit;
End loop;
Close c1;
exception
when e_no_passenger
then
raise_application_error(-20001, 'Please enter number of travelers!');
when no_data_found
then
raise_application_error(-20002, 'Fare not found!');
when too_many_rows
then
raise_application_error(-20003, 'More than one Fare found!');
End Flight;Thanks for any suggestions!Here is how I would have laid out your code:
CREATE OR REPLACE PACKAGE flight_pkg
AS
e_no_available_fares EXCEPTION;
e_no_passenger EXCEPTION;
PROCEDURE flight (p_ptc_adult IN NUMBER,
p_ptc_adult_rt IN NUMBER,
p_origin IN favailability.origin%TYPE,
p_destination IN favailability.destination%TYPE,
p_service_class IN favailability.service_class%TYPE,
p_flightdate IN favailability.flight_date%TYPE,
p_flightdate_rt IN favailability.flight_date%TYPE );
END flight_pkg;
CREATE OR REPLACE PACKAGE BODY flight_pkg
AS
PROCEDURE fare_availability (p_num_adults IN NUMBER,
p_flight_origin IN favailability.origin%TYPE,
p_flight_dest IN favailability.destination%TYPE,
p_service_class IN favailability.service_class%TYPE,
p_flight_date IN favailability.flight_date%TYPE)
IS
v_economy_class favailability.occ_economy%TYPE;
BEGIN
SELECT occ_economy
INTO v_economy_class
FROM favailability
WHERE v_ptc_adult = p_num_adults
AND origin = p_flight_origin
AND destination = p_flight_dest
AND service_class = p_service_class
AND flight_date = p_flight_date;
IF p_num_adults > v_economy_class
OR v_economy_class < 2 THEN
RAISE e_no_available_fares;
ELSE
UPDATE favailability
SET occ_economy = occ_economy - p_num_adults
WHERE v_ptc_adult = p_num_adults
AND origin = p_flight_origin
AND destination = p_flight_dest
AND service_class = p_service_class
AND flight_date = p_flight_date;
END IF;
EXCEPTION
WHEN e_no_available_fares THEN
RAISE_APPLICATION_ERROR (-20021, 'There are no fares available for flight'||
' from '||p_flight_orig||' to '||p_flight_dest||
' on '||TO_CHAR(p_flight_date, 'dd-Mon-yyyy'));
WHEN no_data_found THEN
RAISE_APPLICATION_ERROR (-20022, 'Fare not found for flight from '||p_flight_orig||
' to '||p_flight_dest||' on '||
TO_CHAR(p_flight_date, 'dd-Mon-yyyy'));
WHEN too_many_rows THEN
RAISE_APPLICATION_ERROR (-20023, 'More than one fare found for flight from '||
p_flight_orig||' to '||p_flight_dest||' on '||
TO_CHAR(p_flight_date, 'dd-Mon-yyyy'));
END fare_availablility;
PROCEDURE flight (p_ptc_adult IN NUMBER,
p_ptc_adult_rt IN NUMBER,
p_origin IN favailability.origin%TYPE,
p_destination IN favailability.destination%TYPE,
p_service_class IN favailability.service_class%TYPE,
p_flightdate IN favailability.flight_date%TYPE,
p_flightdate_rt IN favailability.flight_date%TYPE ) is
v_ptc_adult NUMBER;
v_ptc_adult_rt NUMBER;
BEGIN
-- CONSIDER USING A GTT!
EXECUTE IMMEDIATE 'TRUNCATE TABLE fl_itinerary_t';
v_ptc_adult := p_ptc_adult;
v_ptc_adult_rt := p_ptc_adult;
-- validate the number of adults travelling
IF NVL(TRUNC(p_ptc_adult), 0) = 0
OR NVL(TRUNC(p_ptc_adult_rt), 0) = 0
THEN
RAISE e_no_passenger;
END IF;
-- Check outbound availability
fare_availablility (p_ptc_adult,
p_origin,
p_destination,
p_service_class,
p_flightdate);
-- Check inbound availability
fare_availablility (p_ptc_adult_rt,
p_destination,
p_origin,
p_service_class,
p_flightdate_rt);
INSERT INTO fl_itinerary_t (rid,
carrier_t,
fno_t,
origin_t,
dept_t,
destination_t,
arr_t,
fdate_t,
aircraft_type_t,
booking_class_t,
service_class_t,
economy_t,
business_t,
first_t,
fare_basis_t,
fare_t,
tax_t,
surcharges_t,
fare_total_t)
SELECT new_res_seq.nextval,
a.carrier_code,
a.flight_no,
a.origin,
a.dept_time,
a.destination,
a.arr_time,
a.flight_date,
a.aircraft_type,
a.booking_class,
a.service_class,
p_ptc_adult,
null,
null,
a.fare_basis,
a.rt_fare,
a.tax,
a.surcharges,
a.fare_total
FROM favailability a,
main_related_flight b
WHERE (a.flight_leg_id = b.flight_leg_id_1
AND a.origin = p_origin
AND a.service_class = p_service_class
AND a.flight_date = p_flightdate)
OR (a.flight_leg_id = b.flight_leg_id_2
AND a.origin = p_destination
AND a.service_class = p_service_class
AND a.flight_date = p_flightdate_rt);
COMMIT;
EXCEPTION
WHEN e_no_passenger THEN
RAISE_APPLICATION_ERROR(-20001, 'Please enter a valid number of travelers!');
END flight;
END flight_pkg;
/Note the following:
1. I've turned the code into a package, rather than a standalone procedure - this allows you to group related procedures/functions together, and also control whether they're private or public functions/procedures.
2. I've moved the exception definitions to the package spec; this allows the rest of the world to access these exceptions - handy for if you're checking for specific error conditions from outside the package (eg. the proc which calls flight_pkg.flight).
3. I've merged the two SELECT statements together, rather than UNION them; this should improve performance as now only one tablescan is required, rather than two as previously. Is the statement correct, though? It would appear that the destination is unconstrained in both sets of conditions, therefore you are selecting all flights leaving from the origin or the destination, rather than just those going between the two on the given dates. This doesn't appear to match what you're doing in the first half of the flight procedure!
4. I've combined some of the conditions for your IF statements - not strictly necessary, but I think it makes the code more readable and therefore maintainable.
5. I've modularised the code by taking out the checking the outbound/inbound availability, and putting the code into its own procedure. There is only one set of code now to do the checking, rather than two as before - but the new procedure is called twice with the appropriate parameters. This is good coding practice - you now have only one bit of code to maintain, rather than two identical bits! It's also a lot more readable.
6. I've converted your cursor into an INSERT INTO ... SELECT ... statement - it's better to have one SQL statement than loop row-by-row (aka slow-by-slow).
7. I've removed most of your comments, as they were a bit pointless... "Truncate table" when you're following it with a command that says "Truncate table"? Most of the code should be self-documenting - especially if you choose decent names for your variables, procedures, functions, etc. Don't use comments to describe what the code is doing, describe why it's doing it. You should go through the code and make sure your identifiers have meaningful names.
Hopefully you can see that what I've done has a) made things easier to read and maintain and b) more performant. -
Update multiple rows in table using ODataModel.
I have tied ODataModel with table using "TwoWay" binding. I need to allow user to edit the rows of the table at the bottom of which I have 'Save' button. Currently though the table is editable I am unable to edit the entries in multiple rows of the table.
Please find my code below:
var oTable = new sap.ui.table.Table("dprTable",{
visibleRowCount: 4,
visible: true,
navigationMode: sap.ui.table.NavigationMode.Paginator
var oColumn = new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "DBR/DPR"}),
template: new sap.m.Link({
"target": "_blank",
press:[controller.onClickDemoNo,controller]
}).bindProperty("text","DemoId"),
width: "auto",
tooltip: "DBR/DPR"
oTable.addColumn(oColumn);
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Description"}),
template: new sap.ui.commons.TextView().bindProperty("text", "DemoDesc"),
width: "auto",
tooltip: "Description"
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Required Date"}),
template: new sap.ui.commons.DatePicker("",{
value:{
path:"ReqDate",
type: new sap.ui.model.type.Date({pattern: "dd-MM-yyyy"})
change: function(){
console.log('the date is changed and it\'s value is'+value);
width: "auto",
tooltip: "Required Date"
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Requestor"}),
template: new sap.ui.commons.TextView().bindProperty("text", "RequestorName"),
width: "auto",
tooltip: "Requestor"
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Requestor/Project Lead"}),
template: new sap.ui.commons.TextView().bindProperty("text", "LeadName"),
width: "auto",
tooltip: "Requestor/Project Lead"
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Solution"}),
template: new sap.ui.commons.TextView().bindProperty("text", "SolutionText"),
width: "auto",
tooltip: "Solution"
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Start Date"}),
template: new sap.ui.commons.DatePicker("",{
value:{
path:"StartDate",
type: new sap.ui.model.type.Date({pattern: "dd-MM-yyyy"})
width: "auto",
tooltip: "Start Date"
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "End Date"}),
template: new sap.ui.commons.DatePicker("",{
value:{
path:"StartDate",
type: new sap.ui.model.type.Date({pattern: "dd-MM-yyyy"})
width: "auto",
tooltip: "End Date"
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Estimated Duration"}),
template: new sap.ui.commons.TextView().bindProperty("text", "EstDuration"),
width: "auto",
tooltip: "Estimated Duration"
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Hours"}),
template: new sap.m.Input("",{}).bindProperty("value", "ActDuration"),
width: "auto",
tooltip: "Hours"
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Status"}),
template: new sap.ui.commons.ComboBox({items: [
new sap.ui.core.ListItem({text: "New",key:"1"}),
new sap.ui.core.ListItem({text: "In Process",key:"2"}),
new sap.ui.core.ListItem({text: "Completed",key:"3"})
]}).bindProperty("value","StatusText"),
width: "auto",
tooltip: "Status"
oTable.setBusyIndicatorDelay(1);
//oData service call
var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZSECENTRAL_SRV",true);
oModel.setDefaultBindingMode("TwoWay");
oModel.attachRequestSent(function (oEvent) {
console.log('request sent');
oTable.setBusy(true);
oModel.attachRequestCompleted(function () {
console.log('request completed');
oTable.setBusy(false);
});os
oModel.attachRequestFailed(function () {
oTable.setBusy(false);
oTable.setModel(oModel);
oTable.bindRows("/DEOPENDBRSet");
Is there something pending in the settings? And to update the multiple records in the table do I have to make use of some batch operations? Any help would be appreciated.
Thanks,
Supriya KaleHi Supriya,
your code is missing call of oModel.submitChanges() when Save button is called.
You can find the example here SAPUI5 SDK - Demo Kit
Regards,
Peter -
How can I update multiple rows in table using a single form button and checkboxes
I have a project where the visitors can select multiple productos and once the click on the PURCHAS button it updates the selected records.
You have not mentioned the programming language that you are using, but here's a link that could help you if you are using ASP.
http://csharpdotnetfreak.blogspot.com/2009/05/edit-multiple-records-gridview-checkbox.html
Also, have a look at this discussion thread
http://forums.asp.net/t/1470882.aspx -
Hi Experts,
I wants to enable tracking for one of the table in my database.Tracking details must contains Time,new values ,old values and more importantly who/when made the changes.
Other than Triggers do we have any other way to track those changes.
Suggestions are highly appreciated.
Thanks,
NandhuHi NandhuJana,
Please check my response above. I already gave the basic logic there. If you need the "who" then this is manually work, as CDC isn't designed for auditing but for data change tracking. Next step is to write the code for you, and for this
we need the DDL+DML and the CDC information (all element that it created for you),
but on the same time i recommended above
NOT to use CDC if you need the "who" information. The "when" is built-in in CDC and you can check the URL that I posted above for this.
I write again my recommendation here as I wrote above from what I assume is best for your case to lower:
1. create your own DML triggers on the tables (probably best solution in your case, if I understand it correctly)
2. Use Extended event or profiler (I don't like this solution for this case if this is permanent tracking)
3. Using OUTPUT in each query (need to change all query and not fit for most cases, but i some cases it is the best solution)
*** If you can post for us the table DDL for the table that you want to track, then we could help you with the
trigger. but first make sure that you understand the idea and you know what are
triggers :-)
Ronen Ariely
[Personal Site] [Blog] [Facebook] -
How to Update Particular row in a table from OAF page
Hi Can anyone please help me on the following requirement:
In my oaf page i am displaying table values(supplier site details from base tables) with update and delete icons . When i click on update button a new page opens in which we used to update the values and click on apply button which again comes back to the original page.
So when i click on apply button on update page i have to first search for the site in the site table whether it exists or not, if not exists i have to create a new row and save the data, if site exists in the table i have to update the row of a table for that particular site. I have written code for this but unable to achive the requirement, it is not updating the existing row of the table. And i am doing all this on the Temp tables.
So now when i save, previous transaction is also updating along with the current transaction. That means when i m trying to save 2nd transaction values , 1st transactions values are getting updated with the 2nd transaction values(2 rows are getting updated)
Can anyone help me with the code used for updating the current row of the table. Please correct me if i m doing anyting wrong in code.
following is the current code i m using and which is failing :
Controller Code
if(pcontactaction.equals("createECdetailsEvent")) {
String currentSiteName=pageContext.getParameter("SiteName");
System.out.println("Selected Site Name is : " + currentSiteName);
Serializable x[]={reqNum,suppId,currentSiteName,pnotifMethod,pfaxNum};
System.out.println("Invoking AM Method.........");
am.invokeMethod("initCreateECDetails",x);
System.out.println("initCreateECDetails Method Executed. ");
//am.invokeMethod("save");
localOAApplicationModule.getTransaction().commit();
pageContext.setForwardURL(
"OA.jsp?page=/oracle/apps/floaf/flpos/supregister/webui/ECDetailsPG"
, null //not needed as we are retaining menu context
,OAWebBeanConstants.KEEP_MENU_CONTEXT
, null //not needed as we are retaining menu context
,null // no parameters are needed
,true //retain AM
,OAWebBeanConstants.ADD_BREAD_CRUMB_NO
,OAWebBeanConstants.IGNORE_MESSAGES);
AM Code
public void initUpdateECDetails(String request_number,String supplier_id,String site_name,String site_id,String notification_method,String fax_number)
OADBTransaction localOADBTransaction = getOADBTransaction();
String siteToUpdate;
siteToUpdate=site_name;
String siteidToUpdate;
siteidToUpdate=site_id;
System.out.println("Site Name to Update or Create is : " + siteToUpdate);
System.out.println("Site Id to Update or Create is : " + siteidToUpdate);
System.out.println("Inside Update EC Details MEthod.");
OAViewObject suppSiteDetVO = getFLPOSSuppSiteDetailsVO1();
FLPOSSuppSiteDetailsVORowImpl sro=null;
String existingWhereClause = suppSiteDetVO.getWhereClause();
suppSiteDetVO.setWhereClause(null);
suppSiteDetVO.setWhereClauseParams(null);
suppSiteDetVO.setWhereClause("SUPPLIER_ID = :1 AND REQUEST_NUMBER = :2 AND SITE_ID = :3 ");
suppSiteDetVO.setWhereClauseParam(0, supplier_id);
suppSiteDetVO.setWhereClauseParam(1, request_number);
suppSiteDetVO.setWhereClauseParam(2, site_id);
suppSiteDetVO.executeQuery();
suppSiteDetVO.setWhereClauseParams(null);
suppSiteDetVO.setWhereClause(existingWhereClause);
int rowcount = suppSiteDetVO.getRowCount();
System.out.println("Fetched Rows : " + rowcount);
if (rowcount == 0) {
Row row = suppSiteDetVO.createRow();
System.out.println("Row is : " +row);
suppSiteDetVO.insertRow(row);
String siteId = getOADBTransaction().getSequenceValue("FLPOS_SITE_ID_SEQ").toString();
System.out.println("New Site ID : " + siteId);
row.setNewRowState(Row.STATUS_INITIALIZED);
row.setAttribute("RequestNumber", request_number);
row.setAttribute("SupplierId", supplier_id);
row.setAttribute("SiteName", site_name);
row.setAttribute("SiteId", siteId);
row.setAttribute("FaxNo",fax_number);
row.setAttribute("NotificationMethod",notification_method);
System.out.println("New Row Created for Supplier Site.");
System.out.println("Data Saved to table.");
else{
System.out.println("Inside Else Block ");
try {
System.out.println("Inside Try Block ");
Row[] row = suppSiteDetVO.getAllRowsInRange();
for (int i = 0; i < rowcount; i++) {
sro = (FLPOSSuppSiteDetailsVORowImpl)row;
String psiteName=sro.getSiteName();
Number psiteid=sro.getSiteId();
System.out.println(" p Site Name is : " +psiteName);
System.out.println(" p site id is " +psiteid);
if(psiteid.equals(siteidToUpdate) ) {
sro.setAttribute("FaxNo",fax_number);
sro.setAttribute("NotificationMethod",notification_method);
//getOADBTransaction().commit();
break;
catch (Exception e) {
System.out.println("Exception in update : " + e);
}Please answer following:
1. Are you using EO based VOs or ReadOnly VO?
2. What is your VO Query for the search and update?
3. Why have you based your logic on site_name; you should have used site_id?
4.Are you getting correct site name in handling createECdetailsEvent event in CO?
5. In case of update are you getting correct values on the Update Site Details?
6. On coming back from Update page to Supplier Site Search page, do you see old values of the site or the new values in the results table?
Please share the screenshot if possible.
-Prince
[email protected]
http://princekapoor82.blogspot.com -
Need help in SQL Query: Update a row in a table & insert the same row into another table
I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
Thanks in Advance.Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
SQL> var v_id number
update tableA
set colB='ABC'
where colC='XYZ'
returning id into :v_id;
insert into table A_History (ID, colA, colB, ColC)
select id, ColA, ColB, ColC
from tableA
where id = :v_id; -
Trigger in mutation - Update another rows in the same table with a trigger
Hi ,
I try to do a before update trigger on a table , but the trigger is in mutation. I understand why it do that but my question is :
How can I update other rows in the same table when a UPDATE is made on my table??????
Here is my trigger :
CREATE OR REPLACE TRIGGER GDE_COMPS_BRU_5 BEFORE
UPDATE OF DEPARTEMENT--, DISCIPLINE, DEG_DEMANDE, CE_ETAB
ON GDEM.COMPOSITION_SUBV
FOR EACH ROW
Organisme : FQRNT-FQRSC
Date de création : 14-07-2011
Date de modification :
Modifié par :
Auteur : Johanne Plamondon
Description : Ce déclencheur s'executera lors de la modification
du responsable dans la table COMPOSITION_SUBV
DECLARE
V_OSUSER V$SESSION.OSUSER%TYPE;
V_PROGRAM V$SESSION.PROGRAM%TYPE;
V_TERMINAL V$SESSION.TERMINAL%TYPE;
V_MACHINE V$SESSION.MACHINE%TYPE;
V_MODULE V$SESSION.MODULE%TYPE;
V_LOGON_TIME V$SESSION.LOGON_TIME%TYPE;
V_AUDIT_ID NUMBER;
vSEQ NUMBER;
i NUMBER;
vID DEMANDE.ID%TYPE;
BEGIN
begin
SELECT OSUSER, PROGRAM, TERMINAL,MACHINE,MODULE, LOGON_TIME
INTO V_OSUSER,V_PROGRAM,V_TERMINAL,V_MACHINE,
V_MODULE,V_LOGON_TIME
FROM V$SESSION
WHERE TYPE = 'USER'
AND USERNAME = USER
AND LAST_CALL_ET IN (0,1)
AND ROWNUM < 2;
exception when others then null; end;
IF NVL(:NEW.SC_PART,' ') = 'CHC' THEN
SELECT COUNT(*)
INTO i
FROM DEMANDE
WHERE DEM_REF = :NEW.DEM_ID
AND PER_NIP = :NEW.PER_NIP;
IF i = 1 THEN
SELECT ID
INTO vID
FROM DEMANDE
WHERE DEM_REF = :NEW.DEM_ID
AND PER_NIP = :NEW.PER_NIP;
UPDATE COMPOSITION_SUBV
SET --CE_ETAB = :NEW.CE_ETAB,
--DISCIPLINE = :NEW.DISCIPLINE,
DEPARTEMENT = :NEW.DEPARTEMENT,
--DEG_DEMANDE = :NEW.DEG_DEMANDE,
DATE_MODIF = SYSDATE,
USER_MODIF = V_OSUSER
WHERE DEM_ID = vID
AND PER_NIP = :NEW.PER_NIP
AND ANNEE = :NEW.ANNEE;
END IF;
END IF;
/*EXCEPTION
WHEN OTHERS THEN
NULL;*/
END;A standard disclaimer, the mutating trigger error is telling you that you really, really, really don't want to be doing this. It generally indicates a major data model problem when you find yourself in a situation where the data in one row of a table depends on the data in another row of that same table. In the vast majority of cases, you're far better off fixing the data model than in working around the problem.
If you are absolutely sure that you cannot fix the data model and must work around the problem, you'll need
- A package with a collection (or global temporary table) to store the keys that are modified
- A before statement trigger that initializes the collection
- A row-level trigger that adds the keys that were updated to the collection
- An after statement trigger that iterates over the data in the collection and updates whatever rows need to be updated.
If you're on 11g, this can be simplified somewhat by using a compound trigger with separate before statement, row-level, and after statement sections.
Obviously, though, this is a substantial increase in complexity over the single trigger you have here. That's one of the reasons that it's generally a bad idea to work around mutating table exceptions.
Justin -
Update multiple rows in a dynamic table Dreamweaver CS5.5
hello there
i want to update multiple rows which comes from a dynamic table in Dreamweaver CS5 (a loop in php) here is my Mysql table :
sql code
CREATE TABLE `register`.`s_lessons` (
`lid` int( 5 ) NOT NULL ,
`sid` int( 9 ) NOT NULL ,
`term` int( 5 ) NOT NULL ,
`tid` int( 5 ) NOT NULL ,
`point` double NOT NULL DEFAULT '0',
PRIMARY KEY ( `lid` , `sid` , `term` ) ,
KEY `tid` ( `tid` ) ,
KEY `point` ( `point` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_persian_ci;
and this is my page source code:
php file
<?php require_once('../Connections/register.php'); ?>
<?php
session_start();
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$colname1_rs1 = "-1";
if (isset($_GET['term'])) {
$colname1_rs1 = $_GET['term'];
$colname_rs1 = "-1";
if (isset($_GET['lid'])) {
$colname_rs1 = $_GET['lid'];
$colname2_rs1 = "-1";
if (isset($_SESSION['tid'])) {
$colname2_rs1 = $_SESSION['tid'];
mysql_select_db($database_register, $register);
$query_rs1 = sprintf("SELECT s_lessons.sid, s_lessons.lid, s_lessons.term, s_lessons.tid, s_lessons.point FROM s_lessons WHERE s_lessons.lid = %s AND s_lessons.term = %s AND s_lessons.tid = %s", GetSQLValueString($colname_rs1, "int"),GetSQLValueString($colname1_rs1, "int"),GetSQLValueString($colname2_rs1, "int"));
$rs1 = mysql_query($query_rs1, $register) or die(mysql_error());
$row_rs1 = mysql_fetch_assoc($rs1);
$totalRows_rs1 = mysql_num_rows($rs1);
$count=mysql_num_rows($rs1);
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
for ($j = 0, $len = count($_POST['lid']); $j < $len; $j++) {
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE s_lessons SET point=%s WHERE tid=%s, lid=%s, sid=%s, term=%s",
GetSQLValueString($_POST['point'] [$j], "double"),
GetSQLValueString($_SESSION['tid'], "int"),
GetSQLValueString($_POST['lid'] [$j], "int"),
GetSQLValueString($_POST['sid'] [$j], "int"),
GetSQLValueString($_POST['term'] [$j], "int"));
mysql_select_db($database_register, $register);
$Result1 = mysql_query($updateSQL, $register) or die(mysql_error());
$updateGoTo = "student_lists.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $updateGoTo));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>r</title>
<link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="styles/in_styles.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
<div id="header-wrapper">
</div>
<!-- end #header -->
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm">
<div id="content">
<div class="post">
<div style="clear: both;">
<form name="form1" id="form1" method="post" action="<?php echo $editFormAction; ?>">
<table border="1" align="center">
<tr>
<th>Student ID</th>
<th>Lesson ID</th>
<th>Semester</th>
<th>Point</th>
</tr>
<?php do { ?>
<tr>
<td class="data"><label for="sid[]"></label>
<input name="sid[]" type="text" id="sid[]" value="<?php echo $row_rs1['sid']; ?>" size="9" readonly="readonly" /></td>
<td class="data"><label for="lid[]"></label>
<input name="lid[]" type="text" id="lid[]" value="<?php echo $row_rs1['lid']; ?>" size="5" readonly="readonly" /></td>
<td class="data"><label for="term[]"></label>
<input name="term[]" type="text" id="term[]" value="<?php echo $row_rs1['term']; ?>" size="4" readonly="readonly" /></td>
<td><label for="point[]"></label>
<input name="point[]" type="text" id="point[]" value="<?php echo $row_rs1['point']; ?>" size="4" />
</tr>
<?php } while ($row_rs1 = mysql_fetch_assoc($rs1)); ?>
</table>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit" />
<input type="hidden" name="MM_update" value="form1" />
</p>
</form>
</div>
</div>
<div style="clear: both;">
</div>
</div>
<!-- end #content -->
<!-- end #sidebar -->
<div style="clear: both;"> </div>
</div>
</div>
</div>
<!-- end #page -->
</div>
<!-- end #footer -->
</body>
</html>
<?php
mysql_free_result($rs1);
?>
All i want is that when users click on SUBMIT button values of point column in s_lessons(database table) be updated by new entries from user.
i did my best and result with that code is :
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' lid=888, sid=860935422, term=902' at line 1
I would appreciate any idea.
with prior thanksGo to the Row Properties, and in the Visibility tab, you have "Show or hide based on an expression". You can use this to write an expression that resolves to true if the row should be hidden, false otherwise.
Additionally, in the Matrix properties you should take a look at the filters section, perhaps you can achieve what you wish to achieve through there by removing the unnecessary rows instead of just hiding them.
It's only so much I can help you with the limited information. If you require further help, please provide us with more information such as what data are you displaying, what's the criteria to hiding rows, etc...
Regards
Andrew Borg Cardona -
Update all rows in a table which has 8-10 million rows take for ever
Hi All,
Greetings!
I have to update 8million rows on a table. Basically have to reset the batch_id with the current batch number. it contains 8-10 million rows and i have tried with bulk update and then also it takes long time. below is the table structure
sales_stg (it has composite key of product,upc and market)
=======
product_id
upc
market_id
batch_id
process_status
I have to update batch_id,process_status to current batch_id (a number) and process_status as zero. I have to update all the rows with these values for batch_id = 0.
I tried bulk update an it takes more than 2hrs to do. (I limit the update to 1000).
Any help in this regard.
Naveen.The fastest way will probably be to not use a select loop but a direct update like in William's example. The main downside is if you do too many rows you risk filling up your rollback/undo; to keep things as simple as possible I wouldn't do batching except for this. Also, we did some insert timings a few years ago on 9iR1 and found that the performance curve on frequent commits started to level off after 4K rows (fewer commits were still better) so you could see how performance improves by performing fewer commits if that's an issue.
The other thing you could consider if you have the license is using the parallel query option.
Maybe you are looking for
-
Runtime error when executing smartform in se38
hi, i designed a smartform but when iam executing that using se38 am gettin runtime error.can anybody plz help me. *& Report ZDEMOPRG REPORT ZDEMOPRG. DATA FNAME(30) TYPE C. TABLES: LFA1. DATA: BEGIN OF ITAB OCCURS 0. INCLUDE STRUCTURE LFA1
-
Migration strategy for oracle reports 6 to 10g or 1g
Hello All, I would like to know what is the migration path for migrating reports from 6 (*note not 6i*) to 10g or 11g. Thanks Sulakshana
-
What is the best tool to use if I want to quickly create and learn SQL?
I have downloaded and installed: http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html instantclient-sqlplus-win32-10.2.0.3-20061115.zip (722,059 bytes) instantclient-basic-win32-10.2.0.3-20061115.zip (34,469,920 bytes)
-
Can InCopy CS5 save to a CS4 file type
I'm managing an e-learning project that requires a group of writers to use InCopy. Everyone including our client is using IC CS4 but one of my writers who has been unable to find anything other than the latest version. If she uses the CS5 version i
-
fb button in gallery not working, says connecting but returns me back to the pic even if i use the soft button and then share and then facebook not working, twitter working though. I already installed the gallery and camera update and no use !! Solve