PL/SQL :: Lock Row In 1 Table While Update Other Tables

Oct 15, 2012

I want to read 1 table. If the date is less than today, I want to update 4 other tables. I only want to do this update once a day.

While the 4 other tables are being updated, I want the other web users to pause for the update while this procedure runs.

Is there a better way to do this?

Here is what I have:

CREATE OR REPLACE PROCEDURE TEST_TODAY2 AS
-- to create the table
-- create table test_today(updated_date date);
-- insert into test_today(updated_date) values (sysdate-1);
-- select * from test_today;
    cursor daily_update_cur is
    select updated_date from test_today
      for update of updated_date;

[Code]...

Please use {noformat}{noformat} tags before and after your code as described in the FAQ: {message:id=9360002}.

I've corrected it this time for you.

View 6 Replies


ADVERTISEMENT

Lock Child Table By FOR Update Clause?

May 7, 2013

I am using the Oracle 10g and I have question related to "for Update" clause.We have the data warehouse db, so no foreign key constraint between parent and child.We process the data files every hour, the condition is If we find the row in parent table then we go and look into child tables and perform insertion (if no corresponding record is present) or updation (if one corresponding record is present) in the child table.

The problem is If I run the two process simultaneously for the same kind of data, and if no record is present in the child table then it create the duplicate in child table.My question is if I use FOR Update clause while selecting the data in parent table will it lock the child table for any insertion or updation?

Ex- We have employee table for employee 1

In my data files I have the row for employee 1, so when I run the select query on employee table I found 1 row.The I look the child table "Salary" as there is no record for emp_id =1 in this table I insert the record for this

Emp_id Salary
1 500

The problem is if both the process run at same time then I get duplicate rows in child table

Emp_id Salary
1 500
1 500

we do not want the duplicate row insertion. Can I lock the child table during first process run

View 4 Replies View Related

SQL & PL/SQL :: Exclusive Lock On Tables - Run Job By Scheduling

Sep 27, 2011

@ the end of the day means After date changes i need to populate the new row in Some of my tables with the previous date values with the new date.. In that time some other Transaction will Occur on those tables so we need to lock all the tables in that time..Even i tried by doing the Exclusive lock on the tables...

execute immediate 'LOCK TABLE CTR_SALES IN EXCLUSIVE MODE NOWAIT';
execute immediate 'LOCK TABLE CTR_STK_ASSIGN IN EXCLUSIVE MODE NOWAIT';

And how to run this function @ 12:00 in the midnight by scheduling.... And 1 more thing how to pick the recent (Transaction) row on that table. I tried from the rowid it's not working

View 1 Replies View Related

Performance Tuning :: Update Million Rows In One Table With Values From Another Tables?

Feb 15, 2011

I am trying to update a million rows in one table with the values from another tables.

Table being updated CI_ADJ_CHAR column CHAR_VAL_FK1
Table from which values will be used CK_ADJ columns (cx_id, ci_id)

The CI_ADJ_CHAR.CHAR_VAL_FK1 values match CK_ADJ.CX_ID and should be updated with the value CK_ADJ.CI_ID.

The CK_ADJ table has 1.3 million rows and both the columns have indexes defined. Table definitiuon mentioned below

The CI_ADJ_CHAR table has 14 million rows and will update 1 million rows and has an index on the ADJ_ID column but not on the CHAR_VAL_FK1 column.

View 1 Replies View Related

PL/SQL :: How To Update Parent And Child Tables While Updating Parent Table

Jun 13, 2012

I have a parent table EMPLOYEE which includes columns (sysid, serviceno,employeename...) sysid is Primary key, serviceno is Unique key and I have child table DEPENDENT includes columns (sysid,employee_sysid,name,dob...) here again SYSID is primary key for DEPENDENTS table, employee_sysid is Foreign key of EMPLOYEE table.

Now I want to change SYSID (using sequence) in EMPLOYEE table which need to be update in DEPENDENTS table as well

Note: I have 10000 records in EMPLOYEE table as well as I have 5 more child tables which need to update new SYSID.

View 5 Replies View Related

Server Administration :: Use Of LM ( Lock Mode) In V$lock?

Oct 4, 2012

we know we can see lock mode held in session can be analysed using LM column in v$lock.But i confused in seeing LM column it all shows in numbers from 0 to 6.

eg

0,'None(0)',
1,'Null(1)',
2,'Row Share(2)',
3,'Row Exclu(3)',
4,'Share(4)',
5,'Share Row Ex(5)',
6,'Exclusive(6)')

View 1 Replies View Related

SQL & PL/SQL :: How To Lock Particular Row In A Table

Jul 19, 2012

how one can lock a particular row in a table.for example i have a employee table in which 50 records. now i want to lock only 10 records of the employee table.

View 8 Replies View Related

SQL & PL/SQL :: How To Release Lock On Table

Apr 12, 2010

How to Release Lock on table ? ( without killing session )

create table x ( a number);
insert into x(a) values (1);

Lets lock table.

declare
cursor c is select * from x for update;
begin
open c ;
end;
[code]....

View 15 Replies View Related

SQL & PL/SQL :: Lock Table Manually?

Jul 15, 2010

How can one lock a table manually?

View 7 Replies View Related

SQL & PL/SQL :: Can Lock Data In Global Temporary Table

Nov 15, 2011

Can we lock data in global temporary table?

View 4 Replies View Related

SQL & PL/SQL :: Use Index To Minimize Lock On Parent Table?

Mar 27, 2013

I want to know that what oracle server do to minimize the lock on parent table, when we use Index on foreign key column ?

View 2 Replies View Related

Alter Index Shrink Space - Table Lock

Oct 18, 2012

alter index test_idx1 shrink space;

I've heard that this statement causes a table lock but cant find any information on this.if it is so, is it a write lock or also a read lock of the table?

View 5 Replies View Related

Updating Table In Session - Shared Versus Exclusive Lock

Jan 28, 2013

I have a question. If we have two scott sessions. I am updating a table EMP in session

1. It means it is exclusively locked.It cannot be used by session 2. Then can we use select command on table EMP in session

2.? This command should not work according to me. But it is working.

View 14 Replies View Related

PL/SQL :: Index-Organized Table Truncate Vs Lock / Stage / Drop / Recreate?

Apr 24, 2013

I ran into an issue in a project where a function is recreating an index-organized table by doing:Table Structure:

CREATE TABLE table_iot(
...)
ORGANIZATION INDEX
OVERFLOW ...;

Recreate Steps:

1) Populate global temporary staging table (gtt) with data
-- where gtt is staging for target index-organized table (iot)
2) Lock the target index-organized table (iot)
3) Copy old iot data to gtt
-- gtt now contains old and new data
4) Create new index-organized table (iot2) from gtt
-- iot2 now contains old and new data

[code]...

Because index-organized tables are primarily stored in a B-tree index, you can encounter fragmentation as a consequence of incremental updates. However, you can use the ALTER TABLE...MOVE statement to rebuild the index and reduce this fragmentation.The following statement rebuilds the index-organized table admin_docindex:

ALTER TABLE admin_docindex MOVE;

View 3 Replies View Related

Forms :: Insert And Update Directly Into Table From Pre Update Trigger Of Block?

May 14, 2010

I have a base table (Table A) block with multiple records displayed. I need to track audits to this underlying table in the following way:

If user updates a field in the block I want the pre-changed record's audit fields to be set and I need to create a copy of the record with the changed values. Basically any changes will result in the record being logically deleted, and a copy record created with the newly changed values.

Tried to implement in the block's pre-update trigger which will call a package to directly update Table A then Insert into Table A, then requery the block. Is there a clean and efficient way to do this?

View 4 Replies View Related

SQL & PL/SQL :: Update With Join Over Two Tables

Apr 28, 2010

I am trying to write an Update that really frustrates me because it won't work for one reason or another.The situation is that I have two tables for customer information, t1 with the names of the customer and t2 with the address.These two can be joined via a client_id.

Now I have a third table t3 with the name and address of potential customers. I want to find out if some of them are already known to me so that I can update the client_id from table t1 or t2 into t3.

I have to join firstname, lastname from t3 to firstname, lastname from t1 and street, zip, city from t3 to street, zip, city from t2 and client_id from t1 to t2. Additional there is the problem that there can be more than one result so I have to update one of the found client_ids per name/address into t3.I am no expert to PL/SQL, I just know what SQL works in Access and that is:

UPDATE (t3 INNER JOIN t1
ON (t3.firstname= t1.firstname) AND (t3.lastname = t1.lastname)) INNER JOIN t2
ON (t3.city = t2.city) AND (t3.zip = t2.zip) AND (t3.street = t2.street) AND (t1.client_id = t2.client_id)
SET t3.client_id = t1.client_id;

View 2 Replies View Related

SQL & PL/SQL :: Bulk Update - Two Tables

Dec 5, 2011

I am trying to write an update using two tables, one table contains the list of updates to be applied, and the second contains the old data. I have a working solution but I was wondering if there might be some other better way to accomplish this task.

CREATE TABLE foo
(
foo_id NUMBER,
foo_val NUMBER
);
CREATE TABLE foo_change
(
foo_id NUMBER,
foo_val NUMBER
[code]...

The update works, but I thought there may be a better way I just don't know about.

View 2 Replies View Related

SQL & PL/SQL :: Create Trigger To Update Table B After Update On Table A

Jul 21, 2011

I have table test1(id,name) and table test2(id,,name)

Now when I update name column of a row on test1 I want the same value to be updated for the same id in test2.

So I wrote this trigger but its not working

create trigger test_trigger after update on test1 for each row
begin
update test2 set name=new.name where test2.id=id
end
/

View 9 Replies View Related

SQL & PL/SQL :: Create Trigger That Will Update Table When There Is Insert / Update

May 29, 2012

i want to create a trigger that will update a table when there is an insert or update.i can't across this error that i don't even know what it means "table %s.%s is mutating, trigger/function may not see it".

*Cause: A trigger (or a user defined plsql function that is referenced in this statement) attempted to look at (or modify) a table that was in the middle of being modified by the statement which fired it.

*Action: Rewrite the trigger (or function) so it does not read that table.

CREATE OR REPLACE TRIGGER set_date_end
BEFORE INSERT OR UPDATE OF issued ON shares_amount
FOR EACH ROW
DECLARE
BEGIN
INSERT INTO shares_amount(date_end) VALUES(SYSDATE);
END set_date_end;
/

View 3 Replies View Related

SQL & PL/SQL :: Update Statement By Joining 2 Tables

Mar 24, 2012

I have a table called test_renames that has two columns(new_name and old_name) and one row with the following values

NEW_NAME OLD_NAME
DRUG10 DRUG1

I have another table called SH0 that has 10,000 rows and the column of interest is called ITEM1. ITEM 1 contains the following distinct drug names:

DRUG1,DRUG2,DRUG3,DRUG4,DRUG5

Each DRUG has multiple rows associated with it.

I need to only update rows for DRUG1 and set the name from DRUG1 to DRUG10 for all rows where ITEM1 is DRUG1.

However I need to write this update statement by joining with the values in the test_renames table that contains the NEW_NAME and the OLD_NAME.

DRUG1 has 2,000 rows associated with it. The following SQL statement gives me 2,000 rows

(SELECT NVL(CHG.NEW_NAME, SH.ITEM1)
FROM test_renames CHG,sh0 sh
WHERE UPPER(SH.ITEM1) = UPPER(CHG.OLD_NAME)
AND UPPER(SH.ITEM1) IN (SELECT UPPER(OLD_NAME) from test_renames))

However when I run the following update statement, it appears that the SQL query updates all the 10,000 rows in the table instead of just touching the 2,000 rows for DRUG1. It does change all the rows for DRUG1 to DRUG10, but all the other ITEM1 values become null. What I need from the update statement is only chnage the rows for DRUG1 to DRUG10 and leave the other rows that I associated with DRUG2, DRUG3 etc. Here is my update statement.

UPDATE SH0 SH
SET ITEM1 = (SELECT NVL(CHG.NEW_NAME, SH.ITEM1)
FROM test_renames CHG
WHERE UPPER(SH.ITEM1) = UPPER(CHG.OLD_NAME)
AND UPPER(SH.ITEM1) IN (SELECT UPPER(OLD_NAME) from test_renames))

This update statement touches all 10,000 rows. I am looking to update only the relevant 2,000 rows for DRUG1.

View 2 Replies View Related

SQL & PL/SQL :: Update Statement Using Multiple Tables

Aug 26, 2010

I am issuing an update statement in which I am using multiple tables it is giving me an error " set keyword missing"

update E_CONT_DETAIL_NUMB_VALUE ecdnv, y_obj_category yoc, t_contact tc
set ecdnv.ContTPRecCount = 1000
where tc.default_category_id = (select primary_key from y_ojb_category where tree_position = 'CONT')
and ecdnv.detail_field_id=tc.default_category_id;

update E_CONT_DETAIL_NUMB_VALUE ecdnv, y_obj_category yoc, t_contact tc
*
ERROR at line 1:
ORA-00971: missing SET keyword

View 4 Replies View Related

SQL & PL/SQL :: How To Update Two Tables In Single Set Or Query

Nov 22, 2011

How to update two tables in single set or single query ?

View 8 Replies View Related

SQL & PL/SQL :: After Update Trigger (with Multiple Tables)

Nov 21, 2012

I have to write a "after update trigger". Here, i have to update the stock table by other inventory tables (by complex query).
I have written trigger below. how to make it correct?

create or replace trigger trg_stk_upd_pur
after update on O_STOCK_EFFECTS
REFERENCING NEW AS new OLD AS old
FOR EACH ROW

[Code]....

View 5 Replies View Related

SQL & PL/SQL :: Loop Over Recordsets In Update Tables

Jan 21, 2011

I can't seem to get away from writing php scripts to handle the update. I want to learn to use procedures more. What I have is a table like this:

courses(
id number(16) pk,
Division_title varchar2(100),
department_title varchar2(100)

I also have a temp table where I upload updated data into from time to time it looks like this

load_updates_courses(
id number(16) pk,
div_desc varchar2(100),
dep_desc varchar2(100)
)

Currently when I need to update the courses table, I write a php script to do the update. But what I really would like to do is write a procedure I could call to handle this.

I figured I need to loop over the recordsets in the update tables then do a update but I can't figure out how to get started with the plsql.

View 5 Replies View Related

PL/SQL :: Update SAME Column Name In Two Tables From ONE Query

Oct 15, 2012

is it possible to update a same column name in two tables.

I have two tables in same schema

(1)table name
pem.igp_parent
column name
igp_no.
igp_type

(2)table name
pem.igp_child
column name
igp_no.
igp_type

i want to update igp_no column in one query, how it would be possible.

View 2 Replies View Related

PL/SQL :: Update A Single Column Data In 10 Tables?

Oct 2, 2012

We have to update a single column data in about 10 tables which has child/parent table relations, pk/fk constraints.. The column that we are updating is a part of primary key in half of the tables and part of foreign key in the other half tables.. I'm thinking of disabling all the foreign key constraints in the tables then update the column data then enable the foreign key constraints in these tables.

View 7 Replies View Related

PL/SQL :: Merge / Update With Multiple Tables And Columns

Sep 6, 2013

I am trying to update multiple columns from one table based on the results of another table So I have 3 tables as follows 

HISTORYSUMM_SNAPADM_CHOICE 
My SQL code is loosely SELECT SUM(H.HIS1),
SS.SNAP1,
AC.ADM1FROMHISTORY H,
SUMM_SNAP SS,ADM_CHOICE ACWHERE H.HIS2=SS.SNAP2AND SS.SNAP3=AC.ADM2GROUP BY SS.SNAP1,
AC.ADM1

 This works, and I am able to SUM the column as I need with the right numbers.  I altered the SUMM_SNAP table and now I want this summarized column to be in the table I tried using UPDATE, but there is no FROM clause to let me do the table join/group by 

UPDATE SUMM_SNAPSET SUMM_SNAP.SNAP3=SUM(H.HIS1)FROMHISTORY H,
SUMM_SNAP SS,ADM_CHOICE AC
WHERE H.HIS2=SS.SNAP2AND SS.SNAP3=AC.ADM2
GROUP BY SS.SNAP1, AC.ADM1 

The above is obviously wrong - but just trying to show whatI was thinking What would be the best method to get the numbers from the SUM into a table?

View 5 Replies View Related

Audit Delete And Update On All Tables Of Database?

Jun 14, 2013

Was going through this and found that

“AUDIT DELETE ANY TABLE BY <username> BY ACCESS” or “AUDIT UPDATE ANY TABLE<username> BY ACCESS”

enable audit for delete and updates for  given username/schema.  I want to enable auditing on delete and update on my entire database. 

Why? And have we tested it in our any of existing setup?  I am thinking of “Trigger after delete” but again this logic gets struck at individual tables. It do not work simply once and all for complete database/all users/all schemas

View 15 Replies View Related

SQL & PL/SQL :: How To Update Multiple Table With Single UPDATE

Jul 19, 2011

I have a column "empno" in EMP table and "deptno" in DEPT table . I want to update both the columns with single UPDATE statement. With out a creation of stored procedure or view(updating it through view).

View 4 Replies View Related

Get All Tables That A User Can Select / Insert / Update Or Delete

Dec 17, 2010

How to get all the name of tables that a user can select, insert, update or delete?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved