Update One Table with three Apply Processes
Hi.
I have One Database Target with three APPLY processes updating a same table. Each APPLY process refer to a Source Capture remote process.
But I am verifying there is no update in the table when change data on Sources Databases. This table has a PK with two columns.
Someone has idea about this problem, and how to resolve it?
Thanks very much.
JoseFormiga
Hi.
See my definitions below with one table. I have a lot of tables with similar definitons:
SOURCE: (BD1)
=======
begin
dbms_streams_adm.add_table_rules (table_name => 'TSINMETRO.HW_COBRANCAS',
streams_type => 'capture',
streams_name => 'CAPTUPSIE_CAPTURE',
queue_name => 'STRMADMIN.CAPTUPSIE_QUEUE',
include_dml => true,
include_ddl => true,
inclusion_rule => true);
end;
begin
dbms_streams_adm.add_table_propagation_rules (table_name => 'TSINMETRO.HW_COBRANCAS',
streams_name => 'DE_MG_PARA_PSCI',
source_queue_name => 'STRMADMIN.CAPTUPSIE_QUEUE',
destination_queue_name => 'STRMADMIN.APPLYMG_QUEUE@psci',
include_dml => true,
include_ddl => true,
source_database => 'ipemmg',
inclusion_rule => true);
end;
declare
source_scn number;
begin
source_scn := dbms_flashback.get_system_change_number();
dbms_apply_adm.set_table_instantiation_scn@psci (source_object_name => 'TSINMETRO.HW_COBRANCAS' ,
source_database_name => 'ipemmg',
instantiation_scn => source_scn);
end;
begin DBMS_STREAMS_ADM.ADD_COLUMN(rule_name=>'HW_COBRANCAS595',table_name=> 'TSINMETRO.HW_COBRANCAS'
,column_name=>'SRV_UNF_ID',column_value =>ANYDATA.ConvertNumber(35),value_type=>'NEW',step_number=>1,operation=>'ADD'); END;
begin DBMS_STREAMS_ADM.ADD_COLUMN(rule_name=>'HW_COBRANCAS595',table_name=> 'TSINMETRO.HW_COBRANCAS'
,column_name=>'SRV_UNF_ID',column_value =>ANYDATA.ConvertNumber(35),value_type=>'OLD',step_number=>2,operation=>'ADD'); END;
Target:
=======
begin
dbms_streams_adm.add_table_rules (table_name => 'tsinmetro.HW_COBRANCAS',
streams_type => 'apply',
streams_name => 'applymg_apply',
queue_name => 'strmadmin.applymg_queue',
include_dml => true,
include_ddl => true,
source_database => 'ipemmg',
inclusion_rule => true);
end;
I have more two Source DBs doing so.
Thanks.
JoseFormiga
Similar Messages
-
Updating one table with mult. table where clause
I'm having problems with my update statement. I want to update one table that has a mulitple table where clause. Not sure how to accomplish this. Here is what I have so far.
update lawson.apvenmast a
set vendor_status = 'I'
where ((select * from apinvoice i
where i.due_date <= TO_DATE('20011231', 'YYYYMMDD') and
i.vendor = a.vendor)
((apvenmast.ven_class = 'INS') or
(apvenmast.ven_class = 'REF')));
Am I on the right track?
thanks in advance for any help.
Lisa MearsA lot is missing.
where ((select * from apinvoice iA where clause should be like
where <something> IN (select <something> from ...)
((apvenmast.ven_class = 'INS') or
(apvenmast.ven_class = 'REF')));Where does this belong? There is no AND or OR with these two lines.
Check your table aliases too. -
Updating one table with colum of another one
Oracle 11g
Hi,
i'im trying to update two colums from SUPPORT (SUPPORT_X, SUPPORT_Y) table with two colums of POST_HTA_BT( POSTHTABT_GPS_X, POSTHTABT_GPS_Y ) table
Understand that the two tables have the colum below:
SUPPORT(SUPPORT_ID,SUPPORT_PLAQUE,POSTHTABT_ID,SUPPORT_X, SUPPORT_Y,....)
POST_HTA_BT (POSTHTABT_ID,POSTHTABT_GPS_X, POSTHTABT_GPS_Y,..)
The SUPPORT_PLAQUE has the varachar type. Except the keys, other colums are varchar type in the two tables.
The point here is to update the support_x, support_y with posthtabt_gps_x and posthtabt_gps_y.But before update we must cheik if the fifth number of support plaque is a character number between "0" to "9' and if the rest of the caracter of the support_plaque is '00000'
Please note that the support_plaque is stored in the table with the form: "0025800000"!!!
So i did the script below i'm trying to execute in sql developper.
SET SERVEROUTPUT ON
DECLARE
chiffre_liste varchar(200):= '0','1','2','3','4','5','6','7','8','9';
CURSOR CUR_GPS_SUPPORT IS
select SUPPORT.SUPPORT_X,SUPPORT.SUPPORT_Y,POSTE_HTA_BT.POSTHTABT_ID,SUPPORT.EXPL_ID,
SUPPORT.SUPPORT_PLAQUE,POSTHTABT_GPS_X,POSTHTABT_GPS_Y
from SUPPORT,
POSTE_HTA_BT
where
SUPPORT.SUPPORT_X IS NULL and
SUPPORT.SUPPORT_Y IS NULL and
SUPPORT.POSTHTABT_ID = POSTE_HTA_BT.POSTHTABT_ID and
SUPPORT.EXPL_ID = POSTE_HTA_BT.EXPL_ID
order by SUPPORT.POSTHTABT_ID;
w_POSTHTABT_ID POSTE_HTA_BT.POSTHTABT_ID%type;
w_SUPPORT_X SUPPORT.SUPPORT_X%TYPE;
w_SUPPORT_Y SUPPORT.SUPPORT_Y%TYPE;
w_EXPL_ID SUPPORT.EXPL_ID%TYPE;
w_SUPPORT_PLAQUE SUPPORT.SUPPORT_PLAQUE%TYPE;
w_POSTHTABT_GPS_X POSTE_HTA_BT.POSTHTABT_GPS_X%TYPE;
w_POSTHTABT_GPS_Y POSTE_HTA_BT.POSTHTABT_GPS_Y%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('Chargement des coordoonnées GPS -Mise à jour Coord GPS des supports de Départ');
FOR CUR IN CUR_GPS_SUPPORT LOOP
w_POSTHTABT_ID := cur.POSTHTABT_ID;
w_SUPPORT_PLAQUE := cur.SUPPORT_PLAQUE;
w_SUPPORT_X := cur.SUPPORT_X;
w_SUPPORT_Y := cur.SUPPORT_Y;
w_POSTHTABT_GPS_X := cur.POSTHTABT_GPS_X;
w_POSTHTABT_GPS_Y := cur.POSTHTABT_GPS_X;
if substr(cur.support_plaque,5,1) in chiffre_liste and substr(cur.support_plaque,6,5)='00000'
w_SUPPORT_X := CUR.POSTHTABT_GPS_X
w_SUPPORT_Y := CUR.POSTHTABT_GPS_Y
END if;
EXCEPTION WHEN NO_DATA_FOUND THEN w_SUPPORT_X := NULL and w_SUPPORT_Y := NULL;
END;
--Update de la table des supports
update SUPPORT
set SUPPORT_X = w_SUPPORT_X,
SUPPORT_Y = w_SUPPORT_Y
where SUPPORT_PLAQUE = w_SUPPORT_PLAQUE;
-- On valide imm?diatement
commit;
EXCEPTION when no_data_found then null;
-- Pas de coordonnées trouvées
END;
END;
and i got the following errors:
Rapport d'erreur :
ORA-06550: Line 2, colum 34 :
PLS-00103: Symbole "," rencontré à la place d'un des symboles suivants :
* & = - + ; < / > at in is mod remainder not rem
<exposant (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || multiset member submultiset
ORA-06550: Ligne 2, colonne 52 :
PLS-00103: Symbole ";" rencontré à la place d'un des symboles suivants :
) , * & = - + < / > at in is mod remainder not rem =>
<exposant (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || multiset member subm
ORA-06550: Line 38, colum 48 :
PLS-00103: Symbole "CHIFFRE_LISTE" rencontré à la place d'un des symboles suivants :
Symbole "(" a été substitué à "CHIFFRE_LISTE" pour continuer.
ORA-06550: Line 39, colum 12 :
PLS-00103: Symbole "W_SUPPORT_X" rencontré à la place d'un des symboles suivants :
) , * & - + / at mod remainder rem <exposant (**)> and or ||
multiset
ORA-06550: Line 40, colum 12 :
PLS-00103: Symbole "W_SUPPORT_Y" rencontré à la place d'un des symboles suivants :
. ( ) , * @ % & = - + < / > at in is mod remainder not rem
<exposant (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || mult
ORA-06550: Line 41, colum 9 :
PLS-00103: Symbole "END" rencontré à la place d'un des symboles suivants :
. ( ) , * @ % & = - + < / > at in is mod remainder not rem
<exposant (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || multiset memb
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
I verified the line number, but don't see the error in my code.
Please could you help me?
peaceHere the new script
SET SERVEROUTPUT ON
DECLARE
TYPE chiffre_liste IS TABLE OF VARCHAR2(10);
my_list chiffre_liste;
CURSOR CUR_GPS_SUPPORT IS
select SUPPORT.SUPPORT_X,SUPPORT.SUPPORT_Y,POSTE_HTA_BT.POSTHTABT_ID,SUPPORT.EXPL_ID,
SUPPORT.SUPPORT_PLAQUE,POSTHTABT_GPS_X,POSTHTABT_GPS_Y
from SUPPORT,
POSTE_HTA_BT
where
SUPPORT.SUPPORT_X IS NULL and
SUPPORT.SUPPORT_Y IS NULL and
SUPPORT.POSTHTABT_ID = POSTE_HTA_BT.POSTHTABT_ID and
SUPPORT.EXPL_ID = POSTE_HTA_BT.EXPL_ID
order by SUPPORT.POSTHTABT_ID;
w_POSTHTABT_ID POSTE_HTA_BT.POSTHTABT_ID%TYPE;
w_SUPPORT_X SUPPORT.SUPPORT_X%TYPE;
w_SUPPORT_Y SUPPORT.SUPPORT_Y%TYPE;
w_EXPL_ID SUPPORT.EXPL_ID%TYPE;
w_SUPPORT_PLAQUE SUPPORT.SUPPORT_PLAQUE%TYPE;
w_POSTHTABT_GPS_X POSTE_HTA_BT.POSTHTABT_GPS_X%TYPE;
w_POSTHTABT_GPS_Y POSTE_HTA_BT.POSTHTABT_GPS_Y%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('Chargement des coordoonnées GPS -Mise à jour Coord GPS des supports de Départ');
my_list := chiffre_liste('0','1','2','3','4','5','6','7','8','9');
FOR CUR IN CUR_GPS_SUPPORT LOOP
w_POSTHTABT_ID := cur.POSTHTABT_ID;
w_SUPPORT_PLAQUE := cur.SUPPORT_PLAQUE;
w_SUPPORT_X := cur.SUPPORT_X;
w_SUPPORT_Y := cur.SUPPORT_Y;
w_POSTHTABT_GPS_X := cur.POSTHTABT_GPS_X;
w_POSTHTABT_GPS_Y := cur.POSTHTABT_GPS_X;
if substr(cur.support_plaque,5,1) in (my_list) then
if substr(cur.support_plaque,6,5)='00000' then
w_SUPPORT_X := CUR.POSTHTABT_GPS_X;
w_SUPPORT_Y := CUR.POSTHTABT_GPS_Y;
End if;
END if;
--EXCEPTION WHEN NO_DATA_FOUND THEN w_SUPPORT_X,w_SUPPORT_Y := NULL ;
--END;
--Update de la table des supports
update SUPPORT
set SUPPORT_X = w_SUPPORT_X,
SUPPORT_Y = w_SUPPORT_Y
where SUPPORT_PLAQUE = w_SUPPORT_PLAQUE;
-- On valide imm?diatement
commit;
--EXCEPTION when no_data_found then null;
--Pas de coordonnées trouvées
--END;
END LOOP;
END;
And i got the error:
Rapport d'erreur :
ORA-06550: Ligne 40, colonne 12 :
PLS-00383: non-concordance de type détectée à 'SUBSTR' dans une clause IN ou NOT IN
ORA-06550: Ligne 40, colonne 9 :
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
I think to do a loop with your i idea, something like this:
DECLARE
TYPE liste_1 IS TABLE OF NUMBER INDEX BY VARCHAR2(10);
my_list liste_1;
Begin
my_list('0') := 1;
my_list('1') := 1;
my_list('2') := 1;
my_list('3') := 1;
my_list('4') := 1;
my_list('5') := 1;
my_list('6') := 1;
my_list('7') := 1;
my_list('8') := 1;
my_list('9') := 1;
for i in my_list loop
if substr(cur.support_plaque,5,1) in my_list(i) then
if substr(cur.support_plaque,6,5)='00000' then
w_SUPPORT_X := CUR.POSTHTABT_GPS_X;
w_SUPPORT_Y := CUR.POSTHTABT_GPS_Y;
End if;
End if;
End loop
END;
What do you think? -
I need to update a table with three conditions to check help me to solve this?
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DROP PROCEDURE [dbo].[HRM_AssignInsuranceUpdate]
GO
CREATE PROCEDURE [dbo].[HRM_AssignInsuranceUpdate]
@ID INT,
@InsuranceTypeID BIGINT,
@CompanyID BIGINT,
@EmpID BIGINT,
@InsuredObject NVARCHAR(250),
@PolicyNumber NVARCHAR(250),
@StartDate DATE,
@ExpiryDate DATE,
@Remarks NVARCHAR(MAX),
@UpdatedBy NVARCHAR(150)
AS
BEGIN
IF NOT EXISTS (SELECT * FROM dbo.HRMAssignInsurance WHERE InsuredObject = @InsuredObject
AND InsuranceTypeID = @InsuranceTypeID AND CompanyID = @CompanyID AND IsActive = 1)
BEGIN
UPDATE HRMAssignInsurance
SET InsuranceTypeID=@InsuranceTypeID,
CompanyID=@CompanyID,
EmployeeID=@EmpID,
InsuredObject=@InsuredObject,
PolicyNumber=@PolicyNumber,
StartDate=@StartDate,
ExpiryDate=@ExpiryDate,
Remarks=@Remarks,
UpdatedBy=@UpdatedBy
WHERE ID = @ID
SELECT @ID
END
ELSE
BEGIN
SELECT 0
END
ENDIf you're using SQL Server 2008 and up, use MERGE command to incorporate your conditions into one command.
Other wise change your query
to
IF EXISTS (SELECT * FROM dbo.HRMAssignInsurance WHERE InsuredObject = @InsuredObject
AND InsuranceTypeID = @InsuranceTypeID AND CompanyID = @CompanyID AND IsActive = 1)
Thanks,
Shridhar J Joshi
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
Update one table with the max value of another table
CREATE TABLE [dbo].[General](
[a_id] int NOT NULL,
[a_date] datetime NOT NULL,
[c_date] datetime NULL)
CREATE TABLE [dbo].[Specific](
[a_id] int NOT NULL,
[a_date] datetime NOT NULL,
[b_id] int NOT NULL,
[d_date] datetime NULL)
insert into General values (111,'Jan 1 2013', null)
insert into General values (112,'Jan 1 2013', 'Mar 10 2014')
insert into General values (113,'Jan 1 2013', null)
insert into General values (114,'Feb 1 2013', null)
insert into General values (115,'Feb 1 2013', 'Apr 1 2013')
insert into General values (116,'Feb 1 2013', 'Jan 1 1970')
insert into Specific values (111,'Jan 1 2013',1, 'Jan 1 2013')
insert into Specific values (111,'Jan 1 2013',2, 'Feb 1 2013')
insert into Specific values (111,'Jan 1 2013',3, 'Mar 1 2013')
insert into Specific values (112,'Jan 1 2013',1, 'Jan 1 2013')
insert into Specific values (112,'Jan 1 2013',2, 'Feb 1 2013')
insert into Specific values (113,'Jan 1 2013',1, 'Jan 1 1970')
insert into Specific values (114,'Feb 1 2013',1, null)
insert into Specific values (115,'Feb 1 2013',1, 'Jan 15 2013')
insert into Specific values (115,'Feb 1 2013',2, 'Feb 15 2013')
insert into Specific values (116,'Feb 1 2013',1, 'Jan 30 2013')
insert into Specific values (116,'Feb 1 2013',2, 'Jan 1 1970')
I want to update General.c_date only when the values are null or Jan 1 1970 from the maximum value of Specific.d_date as long as the maximum is not null or Jan 1 1970. The two tables join on a_id and a_date. In the example above
a_id = 111 and a_date = Jan 1 2013 should have c_date = Mar 1 2013 and a_id = 116 and a_date = Feb 1 2013 should have c_date = Jan 30 2013.
lgTry the below:
CREATE TABLE [dbo].[General](
[a_id] int NOT NULL,
[a_date] datetime NOT NULL,
[c_date] datetime NULL)
CREATE TABLE [dbo].[Specific](
[a_id] int NOT NULL,
[a_date] datetime NOT NULL,
[b_id] int NOT NULL,
[d_date] datetime NULL)
insert into General values (111,'Jan 1 2013', null)
insert into General values (112,'Jan 1 2013', 'Mar 10 2014')
insert into General values (113,'Jan 1 2013', null)
insert into General values (114,'Feb 1 2013', null)
insert into General values (115,'Feb 1 2013', 'Apr 1 2013')
insert into General values (116,'Feb 1 2013', 'Jan 1 1970')
insert into Specific values (111,'Jan 1 2013',1, 'Jan 1 2013')
insert into Specific values (111,'Jan 1 2013',2, 'Feb 1 2013')
insert into Specific values (111,'Jan 1 2013',3, 'Mar 1 2013')
insert into Specific values (112,'Jan 1 2013',1, 'Jan 1 2013')
insert into Specific values (112,'Jan 1 2013',2, 'Feb 1 2013')
insert into Specific values (113,'Jan 1 2013',1, 'Jan 1 1970')
insert into Specific values (114,'Feb 1 2013',1, null)
insert into Specific values (115,'Feb 1 2013',1, 'Jan 15 2013')
insert into Specific values (115,'Feb 1 2013',2, 'Feb 15 2013')
insert into Specific values (116,'Feb 1 2013',1, 'Jan 30 2013')
insert into Specific values (116,'Feb 1 2013',2, 'Jan 1 1970')
update A
Set c_date = (Select MAX(d_date) From Specific B where A.a_id = B.a_id Group by a_id
having MAX(d_date) is not null
and MAX(d_date)<>'1970-01-01 00:00:00.000')
From General A
Select * From General
Drop table general,specific
This would cause all records in General table to get updated which is not what asker want
see below statement
I want to update General.c_date only when the values are null or Jan 1 1970
from the maximum value of Specific.d_date as long as the maximum is not null or Jan 1 1970
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Comparing Two tables with 300k records and update one table
Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
Column B has same data in both the tables.
I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
I m trying to do using PLSQL Tables.
Any suggestion?
Thanks.Hi,
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results will be the contents of the changed table(s) when everything is finished.
Always say which version of Oracle you're using (for example, 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
ef2019c7-080c-4475-9cf4-2cf1b1057a41 wrote:
Could you let me know how to compare two tables having 300k records and update one table.below is the scenario.
Table Tabl_1 has columns A,B and Tabl_2 has columns B,new_column.
Column B has same data in both the tables.
I need to update Tabl_2 in new_column with Tabl_1 A column data by comparing B column in both tables.
I m trying to do using PLSQL Tables.
Any suggestion?
Thanks.
Why are you trying to use PL/SQL tables? If tabl_1 and tabl_2 are regular database tables, it will be much simpler and faster just to use them.
Depending on your requirements, you can do an UPDATE or MERGE, either in SQL or in PL/SQL. -
How to update one table based on another table ??
Hello Friends:
I am trying to run the following query in oracle but it won't run.
UPDATE BOYS
SET
BOYS.AGE = GIRLS.AGE
FROM GIRLS
WHERE
BOYS.FIRSTNAME = GIRLS.FIRSTNAME AND
BOYS.LASTNAME = GIRLS.LASTNAME;
This query runs fine in sql server but in oracle its saying can't find "SET". PLease tell me what is the correct syntax in oracle to update one table based on another table.
thanksSee if this helps.
If you wrote an SQL statement:
update boys set age = 10;
Every row in the boys table will get updated with an age of 10. But if you wrote:
update boys set age = 10
where firstname = 'Joe';
Then only the rows where the firstname is Joe would be updated with an age of 10.
Now replace the 10 in the above statements with (select g.age from girls g where g.firstname = b.firstname and g.lastname = b.lastname) and replace where firstname = 'Joe' in the second statement with where exists (select null from girls g where g.firstname = b.firstname and g.lastname = b.lastname). The same concepts apply whether 10 is an actual value or a query and whether you have a where clause with the update statement to limit rows being updated.
About the select null question regarding the outer where clause:
Since the query is checking to see if the row in the girls table exists in the boys table what the column is in this select statement doesn't matter, this column isn't being used anywhere. In this case Todd chose to use null. He could have also used a column name from the table or a lot of times you'll see the literal value 1 used here. -
Updating base table with Materialized View's data
Hi,
In order to update base table with MVs data, I am trying real time data transfer between two databases. One is Oracle 8i and other is Oracle 9i. I have created an updatable MV in 9i on a base table using database link. The base table is in 8i. Materialized View log is created in 8i on base table. MV has to be associated to some replication group, but I am not able to create replication group in 9i to which MV has to be associated. The required packages are not installed.
Replication packages are to be used to create replication group are :
/*Create Materialized View replication group*/
BEGIN
DBMS_REPCAT.CREATE_MVIEW_REPGROUP (
gname => 'TEST_MV_GRP',
master => 'TEST_DATA_LINK',
propagation_mode => 'ASYNCHRONOUS');
END;
But above block is giving error.
Can anyone suggest how to resolve this, or are there any other approaches (by not using replication packages) to update base table with MVs data ?
Thanks,
ShaileshYes, I created link between two databases and was able to update tables on 8i from 9i database using that link.
The error I am getting while creating replication group is :
ORA-06550
PLS-00201 : identifier 'SYS.DBMS_REPCAT_UTL2@'TEST_DATA_LINK' must be declared
ORA-06550
PLS-00201 : identifier 'SYS.DBMS_REPCAT_UNTRUSTED@'TEST_DATA_LINK' must be declared
ORA-06512 : at "SYS.DBMS_REPCAT_UTL", line 2394
ORA-06512 : at "SYS.DBMS_REPCAT_SNA_UTL", line 1699
ORA-06512 : at "SYS.DBMS_REPCAT_SNA", line 64
ORA-06512 : at "SYS.DBMS_REPCAT", line 1262
Is there any other approach which can be used to update base table with MVs data instead of using replication packages ?
Thanks,
Shailesh -
Best way to update a table with disinct values
Hi, i would really appreciate some advise:
I need to reguarly perform a task where i update 1 table with all the new data that has been entered from another table. I cant perform a complete insert as this will create duplicate data every time it runs so the only way i can think of is using cursors as per the script below:
CREATE OR REPLACE PROCEDURE update_new_mem IS
tmpVar NUMBER;
CURSOR c_mem IS
SELECT member_name,member_id
FROM gym.members;
crec c_mem%ROWTYPE;
BEGIN
OPEN c_mem;
LOOP
FETCH c_mem INTO crec;
EXIT WHEN c_mem%NOTFOUND;
BEGIN
UPDATE gym.lifts
SET name = crec.member_name
WHERE member_id = crec.member_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END;
IF SQL%NOTFOUND THEN
BEGIN
INSERT INTO gym.lifts
(name,member_id)
VALUES (crec.member_name,crec.member_id);
END;
END IF;
END LOOP;
CLOSE c_mem;
END update_new_mem;
This method works but is there an easier (faster) way to update another table with new data only?
Many thanks>
This method works but is there an easier (faster) way to update another table with new data only?
>
Almost anything would be better than that slow-by-slow loop processing.
You don't need a procedure you should just use MERGE for that. See the examples in the MERGE section of the SQL Language doc
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
MERGE INTO bonuses D
USING (SELECT employee_id, salary, department_id FROM employees
WHERE department_id = 80) S
ON (D.employee_id = S.employee_id)
WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
DELETE WHERE (S.salary > 8000)
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*.01)
WHERE (S.salary <= 8000); -
Updating a table with need of table joins
Hi,
I want to update a table (via PL/SQL process) but to do it I need to include joins - and my code throws an error...
How would I go about getting this to work?
UPDATE employees a, action b
SET a.met_employee = '0000'
WHERE b.date_met NOT BETWEEN QA1 AND QA2
AND b.date_met NOT BETWEEN QB1 AND QA2
AND b.date_met NOT BETWEEN QC1 AND QC2
AND b.date_met BETWEEN QD1 AND QD2
AND b.emp_id = P12_ID
AND a.emp_id = P12_ID;
Where QA1, QA2, QB1, QB2, QC1, QC2, QD1, QD2 are variable values of pre-defined dates and P12_ID is the ID variable.
The problem occurs because I need to use the two tables - how can I solve this?
Thanks,
SiThe employee table has multiple actions (action table)
We want to set certain values i.e the '0000' to certain employees that have had actions on certain dates (the defined variables)
So it needs to check all the actions within the set dates and give only employees within this criteria the value '0000'
with the following...
update emplyees
set met_emplyees = '0000'
where emp_id = P12_ID;
that will always set the employee with '0000'. However '0000' should only be set to employees that had actions on certain dates.
Cheers
Si -
Updating a table with billion rows
It was an interview question, what's the best way to update a table with 10 billion rows. Give me your suggestions. Thanks in advance.
svkThe best way to answer questions such as this is NOT with a absolute and specific answer. Instead, discuss your strategy for approaching the problem. The first step is to understand your exact requirement. It is surprising how often people
write update statements with an under-qualified where clause. NEVER update a row that does not need to be updated. For example, a statement like:
update mytable set cola = 'ABC' where id in (1, 45, 212);
Assuming id is unique for the table and the specified values exist in the table, we know 3 rows will be updated. Do all of those rows need to be updated? Think about it. If cola is already set to 'ABC' for any of those rows, we could ignore
those rows and make the update more efficient. To do that, you need to add "and cola <> 'ABC' " to the where clause. That is just one example of understanding exactly what you need to do - and doing only that which needs to be done.
Once you understand exactly what you need to do, you need to analyze the impact of the update and identify any potential issues. Updating a lot of rows can take a lot of time and consume large amounts of log and disk space. What else is using
the table? Can you afford to lock the table for the duration of the update? Are there concurrency issues, regardless of whether you update in batches or in one single statement? When using a batch approach, is there an issue if someone runs
a query against the table (i.e., the result is different from that of the same query run after all updates have been completed)? Are you changing something which is included in an index? Are you changing part of the clustered index?
Ultimately, every question you are asked is (or should be) designed to test your problem-solving skills and your skillset. IMO, it is relatively easy to improve your skillset of any particular tool, language, or environment. The other - not so much
and that is why they are more valuable IMO. -
Recordset - updating 2 tables with 1 recordset using application object update record
I have a recordset that uses a field from 2 different tables
with a select statement where clause that joins a userid. I can
display the field’s data just fine. Now I want to use the
Application object “update record” so I can modify
either of the fields. The problem is the Application object
“update record” only allows you to update one table.
How does Dreamweaver mx 2004 allow me to update 2 tables with one
recordset and 1 submit button? Currently using php.
Example of where:
Where member.userid = member_detail.userid
I tried creating the one form with the field from the first
table and that works just fine. I added the other field from the
other table into the form but ofcourse there isn’t any code
that will update the second table so it won’t work.
My application requires me to update alot of fields between 2
tables at the same time.
Does anyone know a way using Dreamweaver mx 2004 to do this?
I don’t have much php experience.jon-rookie wrote:
> DreamerJim,
>
> I am sorry but I don't think you are correct. I just
can't believe that with
> all the powers to be at Macromedia and now Adobe can't
figure out how to update
> two tables at once. There are millions of db's out there
that require this. I
> spent several hours today perusing lots of posts on the
internet. It seems I
> am not the only one out there that has asked this
question. Unfortunately
> there are no good answers yet to my surprise.
>
> I did find a Dreamweaver extension that does exactly
what I myself and many
> others want. The problem is it is no longer available
unless you purchase a
> bundle of software from Adobe.
>
> I have not looked into it in detail so I am not 100%
sure that is accurate!
>
> Still, alot of php programmers do this all the time
without much trouble. I
> just want to know if Dreamweaver mx 2004 has the
capability if a person knows
> the right steps.
>
> Hopefully a Dreamweaver expert will post something to
let us know for sure.
> Until then I am stuck.
>
Not even CS3 has this built in, you will either have to code
it yourself
or buy the extension you have found. Dreamweaver gives you
basic
features to help you develop applications, but if you want to
do
anything really clever you have to do it yourself.
One thing to consider is maybe creating an SQL view that is
can be
updated. I am pretty sure it exists, then you use the view
instead of
the table in the update behaviour. I have never done it
myself, but I am
sure it can be done.
Steve -
URGENT update a table with a text that has a single quote in it
Hello, I am trying to update a table with a text that has a single quote in it. I believe I need to use two singles quotes but I am not sure how.
For example:
UPDATE TEST
SET DESCRLONG='Aux fins d'exportations'
WHERE etc...
Should I put 2 singles quotes before the quote in the text?
UPDATE TEST
SET DESCRLONG='Aux fins d'''exportations'
WHERE etc...
Thank you very much :)The best way depends on the version of Oracle.
But, the quick and universal answer is to use two single quotes
SQL> connect test/test
Connected.
SQL> create table test (descrlong varchar2(128));
Table created.
SQL> insert into test values ('This is a string with a '' single quote');
1 row created.
SQL> select * from test;
DESCRLONG
This is a string with a ' single quote
SQL> update test set descrlong='Aux fins d''exportations'
2 where descrlong like 'T%';
1 row updated.
SQL> select * from test;
DESCRLONG
Aux fins d'exportations
SQL> -
Is it possible to update multiple tables with a dynamic form?
I have columns from two tables populating a dynamic form. I am trying to have the form update both tables on submit. I have tried both a linked transaction and a custom transaction but I am not making progress. Only the master table is being updated. Is it possible with ADDT to update two tables with a dynamic form?
I meant
SXMSMSTAT
SXMSSYERR
Thanks. -
How can I update the table with a single query for...
I have a table with columns C1 and C2.
C1 C2
A1 null
A1 null
A1 null
A1 null
A2 null
A2 null
A2 null
A3 null
A4 null
A4 null
I want to update my table with a single query so that I would have data like
C1 C2
A1 1
A1 2
A1 3
A1 4
A2 1
A2 2
A2 3
A3 1
A4 1
A4 2
The updated column C2 has the values like serial no grouped on the column C1.SQL> create table mytable
2 ( c1 varchar2(2)
3 , c2 number(2)
4 )
5 /
Tabel is aangemaakt.
SQL> insert into mytable (c1)
2 select 'A1' from dual union all
3 select 'A1' from dual union all
4 select 'A1' from dual union all
5 select 'A1' from dual union all
6 select 'A2' from dual union all
7 select 'A2' from dual union all
8 select 'A2' from dual union all
9 select 'A3' from dual union all
10 select 'A4' from dual union all
11 select 'A4' from dual
12 /
10 rijen zijn aangemaakt.
SQL> select * from mytable
2 /
C1 C2
A1
A1
A1
A1
A2
A2
A2
A3
A4
A4
10 rijen zijn geselecteerd.
SQL> merge into mytable t1
2 using (select c1
3 , row_number() over (partition by c1 order by null) rn
4 , rowid rid
5 from mytable
6 ) t2
7 on (t1.rowid = t2.rid)
8 when matched then
9 update set c2 = rn
10 when not matched then
11 insert values (null,null)
12 /
10 rijen zijn samengevoegd.
SQL> select * from mytable
2 /
C1 C2
A1 1
A1 2
A1 3
A1 4
A2 1
A2 2
A2 3
A3 1
A4 1
A4 2
10 rijen zijn geselecteerd.Regards,
Rob.
Maybe you are looking for
-
Mac platform. I have the Creative Suite. I need to reinstall the app. How can I get rid of the app and it's extensions to reinstall it?
-
Where does a PL/SQL block run? PGA or SGA?
Hi all, 11g I'm not familiar with the oracle memory structure, if I have a simple pl/sql block as below DECLARE v1 number; BEGIN v1:=100; DBMS_OUTPUT.PUT_LINE(v1); END;in my mind, even though it's a small block, when i execute it, it would also
-
HT1918 I'm having trouble updating my debit card billing information. Please help!
I just recently changed my address and now it won't update my new information.
-
Cant Display charts in browser with CrystalReportViewer
I am integrating crystal reports with Struts.I could get the reporting data in the browser with crystal report viewer.but i cant dispaly reports that contain charts in the browser.when i am trying to execute,i m getting following exception. com.cryst
-
3109c rebooting with micro-SD card inserted?
Hope someone can help me. I've a 3109c, which works fine with just it's SIM card in, but if I put in my micro-SD card as well (used to store music and some wallpaper pics on, about 500MB or so at the moment) it starts-up, but within 10 seconds or so