Merge - update table@dblink
Hi all,
my need is to perform merge:
1) update table2@dblink only when some column(s) is/are different than in local table1
2) insert rows into table2@dblink when not present.
(2) works fine.
(1) works strange. It was tested successfully at test server where both table1 and table2 are local. It just doesn't work at production server where table2 is remote (using dblink), it doesn't report any error, but values just are not updated.
Query code:
merge into remote.table2@dblink rr
using
select
ID ,
NAME
from local.table1
) hh
on ( hh.id = rr.id )
when matched
then update set
rr.NAME = hh.NAME
where
rr.NAME <> hh.NAME
when not matched then insert (
rr.ID ,
rr.NAME
values (
hh.ID ,
hh.NAME
);Oracle version:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
(the same on local and remote servers).
The content of table:
ID
NAME
1
Germany
2
Spain
3
Italy
4
Portugal
4 rows selected.Please, help me.
Looks like Bug:
Bug 9816678 - Merge on a remote table using local table gives wrong results. [ID 9816678.8]
Fixed in 11.2.0.3 ...
Similar Messages
-
Update table using merge or Update statement
Hi All,
We have oracle 10G R2 On windows...
We have tables BROK_DEALER_MAP and DTRMIS_REPORT.
create table BROK_DEALER_MAP
SL_NO NUMBER,
BROK_DLR_CODE VARCHAR2(30),
EMP_TAG VARCHAR2(30),
REMARKS VARCHAR2(60),
CONS_CODE VARCHAR2(30),
BROK_DLR_NAME VARCHAR2(50),
BROKER_TYPE VARCHAR2(30),
BROK_DLR_0 VARCHAR2(30),
CATG_DESC VARCHAR2(60),
Category VARCHAR2(30));
desc DTRMIS_REPORT
SL_NO
POSTED_DATE
ZONE
AMC_REGION
CITY
BROK_DLR_CODE
BROK_DLR_NAME
SUB_BROKER
B_TYPE
FOLIO_NO
INVESTOR_NAME
TAX_NO
INV_TAG
SCHEME_CODE
SCHEME_NAME
SCH_CLASS
TRXN_MODE
CHN_TAG
FP_COUNT
FP_AMOUNT
AP_COUNT
AP_AMOUNT
PUR_COUNT
PUR_AMOUNT
SIP_COUNT
SIP_AMOUNT
SI_COUNT
SI_AMOUNT
RED_COUNT
RED_AMOUNT
SO_COUNT
SO_AMOUNT
DR_COUNT
DR_AMOUNT
STP_COUNT
STP_AMOUNT
NET_SALES
DISTRIBUTOR_TYPE
SCHEME_TYPE
FOCUS_PRODUCT
RM_CODE
RM_NAMEtable BROK_DEALER_MAP doesn't have any duplicate records.
table DTRMIS_REPORT have more than 2 lacks duplicate records.
Now i want to update table DTRMIS_REPORT (DISTRIBUTOR_TYPY COLUMN) With the values of BROK_DEALER_MAP (CATEGORY COLUMN).
For that i have written merge statement like below
merge into dtrmis_report a
using brok_dealer_map b
on (a.brok_dlr_code=b.cons_code)
when matched then
update set a.Distributor_type=b.category
where a.brok_dlr_code=b.cons_code;IT's giving error saying ORA-30926: unable to get a stable set of rows in the source tables.
How to update the table.
Please help.Chanchal Wankhade wrote:
IT's giving error saying ORA-30926: unable to get a stable set of rows in the source tables.That means there are duplicate records in your source table.
Please post the output of the below
select cons_code
from brok_dealer_map
group by cons_code
having count(*) > 1;In case of duplicate CONS_CODE, you need to decide with which the target table should get updated
And are you seriously giving a where condition in merge like you posted..?
Edited by: jeneesh on Dec 19, 2012 9:56 AM -
Compare table A and table B and update table B ,,,,table B has 300k rows
Hi,
I m trying to write a code, I have tables A and table B.
I need to compare table A and table B , and update table B with one column.
using joins b/w A&B tables, I selected one record from table A in cursor.
After Begin I m trying to open cursor and in FOR LOOP
Im trying to update table B WHERE CURRENT OF Cursor.
this is erroring out.
could you let me know on this.
there is another way like selecting required columns from both table.but i was told to do as above.
Thanks> this is erroring out.
You haven't posted nearly enough for anyone to help you. You didn't even tell us what error you are getting.
So about the only thing we can do is post a generic MERGE statement which you'll have to modify for your use.
merge into tableB b
using (select some_key, some_column from tableA where etc.) u
on (u.some_key = b.some_key)
when matched then update
set b.some_column = u.some_column; -
How to merge two tables in powerpivot excel 2013?
Hi
I have a few tables imported from two different systems/databases/tables and I need to merge them into one table in Power Pivot.
All of the import tables have some common fields such as Name, Value. e.g. Staff Expenses, Staff Sales table
The output table at lest with 3 columns (Name, Value, and Data Source). The Data Source column indicates which table the row value comes from.
How can I merge the tables using DAX?
Regards
Joe Lee
update: Just add a few sample data and chart I was required to develop
Name
Expense
Joe
1000
James
2000
Name
Sales
Joe
3000
James
10000
The chart I need to develop
I was thinking using DAX to merge the table as follow for the chart
Name
DataSource
Value
Joe
Expense
1000
James
Expense
2000
Joe
Sales
3000
James
Sales
10000
jlHi Joe,
DAX doesn't currently have a UNION function so you'll need to use a workaround such as
this to achieve the result but it won't be suitable for all scenarios. I would generally recommend using the Append capability
in Power Query for this type of task as it would be a much better fit. However, I should highlight that using Power Query would limit your refresh options to a manual refresh from within the workbook or scheduled refreshes using Power BI
for Office 365. If this is not a deal breaker then Power Query is the way to go.
Regards,
Michael Amadi
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to vote it as helpful :)
Website: http://www.nimblelearn.com, Twitter:
@nimblelearn -
Corellated update AND merge(update only)
Hi ,
I have few corellated updates in my code , which i though ,i can replace with 10g new Merge update only stmt.
But to my surprise , the sql using merge is showing more cost and using full table scan.
Please find below the sql stmts. below(example). Am using Oracle 10.2.0.1
create table t1 as select * from all_objects where rownum<10000;
create table t2 as select * from t1 where rownum<10000-200;
create unique index t1_objId_ind on t1(object_id);
create unique index t2_objId_ind on t2(object_id);
--Corellated updated query
update t1 set t1.object_name= (select upper(t2.object_name) from t2 where t1.object_id=t2.object_id)
where T1.OBJECT_ID IN (SELECT t2.object_id from t2);Explan for above update stmt.
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | 9139 | 383K| 37 (9)| 00:00:01 |
| 1 | UPDATE | T1 | | | | |
| 2 | NESTED LOOPS | | 9139 | 383K| 37 (9)| 00:00:01 |
| 3 | TABLE ACCESS FULL | T1 | 9138 | 267K| 35 (3)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | T2_OBJID_IND | 1 | 13 | 0 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID| T2 | 1 | 30 | 2 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
|* 6 | INDEX UNIQUE SCAN | T2_OBJID_IND | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
4 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
6 - access("T2"."OBJECT_ID"=:B1)I wanted to eliminate the corellated update , So i wrote using MERGE as below
MERGE INTO T2
USING T1
ON (t1.object_id=t2.object_id)
WHEN MATCHED THEN update
SET T2.OBJECT_NAME=UPPER(T1.OBJECT_NAME);Explan for above MERGE stmt.
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | MERGE STATEMENT | | 9139 | 303K| | 201 (2)| 00:00:03 |
| 1 | MERGE | T2 | | | | | |
| 2 | VIEW | | | | | | |
|* 3 | HASH JOIN | | 9139 | 2391K| 1256K| 201 (2)| 00:00:03 |
| 4 | TABLE ACCESS FULL| T1 | 9138 | 1142K| | 35 (3)| 00:00:01 |
| 5 | TABLE ACCESS FULL| T2 | 9671 | 1322K| | 34 (3)| 00:00:01 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
3 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")Cost is 201 , but for the corellated update the cost is 37.
Any idea , how should i re-write the MERGE stmt.?
Edited by: kumar on Jun 16, 2011 4:41 PMFirst "cost" is just a number and you should not compare or tune to get the best "cost" in an execution plan.
What counts ist elapsed time => IO, CPU...
In 11g the "cost" for the merge is better (and also the CPU time is far off to be close to the truth!)
9799 rows updated
78ms elapsed
Plan hash value: 580992724
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | UPDATE STATEMENT | | 9641 | 404K| 28964 (34)| 00:05:48 |
| 1 | UPDATE | T1 | | | | |
| 2 | NESTED LOOPS | | 9641 | 404K| 41 (3)| 00:00:01 |
| 3 | TABLE ACCESS FULL | T1 | 10866 | 318K| 40 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | T2_OBJID_IND | 1 | 13 | 0 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID| T2 | 1 | 30 | 2 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | T2_OBJID_IND | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
4 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
6 - access("T2"."OBJECT_ID"=:B1)
Note
- dynamic sampling used for this statement (level=2)
commited
16ms elapsed
9799 rows merged
125ms elapsed
Plan hash value: 2009158753
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | MERGE STATEMENT | | 9641 | 320K| | 251 (1)| 00:00:04 |
| 1 | MERGE | T2 | | | | | |
| 2 | VIEW | | | | | | |
|* 3 | HASH JOIN | | 9641 | 3088K| 1720K| 251 (1)| 00:00:04 |
| 4 | TABLE ACCESS FULL| T2 | 9640 | 1600K| | 39 (0)| 00:00:01 |
| 5 | TABLE ACCESS FULL| T1 | 10866 | 1676K| | 40 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - access("T1"."OBJECT_ID"="T2"."OBJECT_ID")
Note
- dynamic sampling used for this statement (level=2)In your example, the elapsed time (thanks for the it!) is 78ms for the update and 125ms for the MERGE. (ORACLE 11g on and old PC) .
So "should you rewrite" the MERGE? No idea how. I assume you want to change from UPDATE to MERGE and see if it's worth?
Here it's not. But, your example just uses 2MB of data. And the difference from my point view is not MERGE or UPDATE it's NL against HASH join with that tiny amount of data.
So generally I use MERGE because of speed and because I have more control over the query. For updating 2MB of data, it's not worth it. For updating GBytes the stuff I worked on it was faster (and better to control). -
Merge, Update, or Insert?
Hey all,
I am new to using Oracle and SQL database codes in general. I am wondering what kind of statement to use for the problem I am about to explain. I will probably have coding questions down the road, which I will post in the correct part of the forum, but I thought that posting this general question would be appropriate in this forum.
My problem:
I have a TMP table which contains specific columns that were taken from the source. (Source had 85 columns, this TMP table has around 20). So, now I need to insert the data from the TMP table to different table. For example, the temp table is called TMP_SUPP_MASTER. The table we are moving this information into is TBL_SUPP_MASTER. In the TMP table there are columns like ADR_ST_LN_1, ADR_ST_LN_2, ADR_ST_LN_3, ADR_ST_LN_4...but in the TBL there is just ADDR_ST. Therefore, I need to combine those 4 columns into 1.
That was one part of the problem, another part involves inserting a single value into every row under the ORG_ID column name. The ORG_ID is not part of TMP, but is in TBL.
The last part of the problem is we have a lot of SUPP_CD (supplier codes), which are the primary keys. Well the code is built to include a facility ID followed by a "root" supplier code. Each facility ID and "root" supplier code is unique, so we are keeping those codes, but also making a column that has just the "root" supplier code. There are multiple "root" supplier codes that match up, so we are creating a parent/child relationship with those codes and having a column that marks them as 'P' or 'C'. P = parent, C = child. So I need to also insert that.
On top of all that, we will have new information coming in that needs to be updated to the table (so I'm assuming it's a merge).
Can anyone point me in the right direction to figure out this problem? I would really appreciate it. I don't need any codes, but just a simple opinion.
Thank you all!991769 wrote:
Can anyone point me in the right direction to figure out this problem? I would really appreciate it. I don't need any codes, but just a simple opinion.Well, coffee is good for figuring out problems... ;-)
Performance is determined by the size of a workload and how fast it can be moved. The biggest chunk of most database workloads is I/O. I/O workloads are also slow to move.
So the basic principal for performance is to do the least amount of I/O as possible.
If you have an UPDATE using table TMP for getting the new values to update table PROD1, and you have an INSERT using table TMP for getting new data into table PROD2, this means 2 I/O workloads on TMP.
If both workloads read the entire TMP table, they are pretty much identical and results in a double workload for the same data. In this case a MERGE hitting TMP once, and then feeding updates to PROD1 and inserts to PROD2, will be a far smaller and far more effective workload.
So when tackling a problem with SQL, try and keep the I/O to only that what is necessary to achieve the goal - and guard against hitting the same rows of data with multiple passes. -
We have a stored procedure that merges/updates a subset of data from one table into another for a particular identier. For example, the data from table 1 with a PNOTE value of 991 is being merged with data from table 2 with a PNOTE value of 650. How do I verify the data from table 1 was merged with the data from table 2? I can't do a count because some records are inserted and others updated. I need to grab the data from the first subset and make sure it ended up in the second subset. Any help would be greatly appreciated.
I was able to find the solution. You have to query table 1 based on PNOTE value and then very that record set doesn't exist in table 2 using the primary keys.
This takes the subset from table 1 and verifies it doesn't exist in the updated subset in table 2.
select t1.* from table1 t1 where pnote = 650 and not exists
(select t2.* from table2 t2 where pnote = 991 and
t1.pk1 = t2.pk1 and
t1.pk2 = t2.pk2)
If the records were merged correctly the record set should be empty. -
"Error in updating Table J_1iexchdr"
Hi ,
When I am creating the excise invoice, It's terminated the program and gives the following error
"Error in updating Table J_1iexchdr"
What can be the reason?
Regards
PremHi prem
Look if these threads can help
RG23C Update Problem
Problem in SAP Script
billing document not creating
return delivery
************Reward points if usefull************** -
Error in updating table J_1PART2
Hi,
I am getting an error while saving the excise invoice as 'error in updating table J_1PART2'.
What would have gone wrong?????? please help!!!
Thanks ,
RamyaDiscussion moved from SAP ERP Sales and Distribution (SAP SD) to Internationalization and Unicode
Please use Internationalization and Unicode for you CIN related queries -
Error in updating table J_1IEXCHDR,J_1IEXCDTL in tcode J1IJ
Hi,
while cancelling excise invoice in Tcode J1IJ ,
we are getting 'error in updating table J_1IEXCHDR,J_1IEXCDTL'.
what is missing or tell the procedure to resolve the issue.
Regards,Discussion moved from SAP ERP Sales and Distribution (SAP SD) to Internationalization and Unicode
Please use Internationalization and Unicode for you CIN related queries -
Bapi : BAPI_ALM_ORDER_MAINTAIN not updating table AFVU-USR08
Hi,
I have a requirement to update table AFVU-USR08.I am actualy dealing with tcode IW32/IW33 where in we need to update operation-->enhancement tab.I am using BAPI : BAPI_ALM_ORDER_MAINTAIN to do this.I am testing the BAPI directly( Not called in any program ),I can see a message like so and so order saved under notification,But there is no entry in table AFVU-USR08.
If any one have come across this prob. and got the sol. Pl. share it with me.
Your solution will be more helpful.
Thanks,
Bharani.Hi Ferry,
1. I have also tried ur given code before BAPI_TRANSACTION_COMMIT.
l_fname = 'SOBKZ'.
l_fvalue = 'U'.
CALL FUNCTION 'CO_BH_MOD_SINGLE_FIELDS'
EXPORTING
aufnr_imp = wa_meth-objectkey(12)
field1 = l_fname
value1 = l_fvalue.
but this program is giving dump for only this particular Value saying that This is PROTECTED field.
Can anyone help me out on How to Update Special Stock Indicator on Components Tab of Maintenance Order (IW32).
If anyone has faced such type of problem & solved it then please let me also.
2. Which BADI to use for Updating Special Stock Indicator when we press enter on Components tab in Transaction IW32 ?..
Thanks in advance,
Hope to get the solution soon from all SAP gurus.
and help will be appriciated .
Gaurav. -
How to CREATE VIEW to merge two tables each of which has CLOB-typed column
I failed in creating a view to merge two tables that have CLOB-type column each.
The details are:
Database: Oracle 9i (9.2.0)
Two tables "test" and "test_bak", each of which has the following structure:
ID Number(10, 0)
DUMMY VARCHAR2(20)
DUMMYCLOB CLOB
The following operation fails:
create view dummyview (id, dummy, dummyclob) as
select id, dummy, dummyclob from test
union
select id, dummy, dummyclob from test_bak;
I was announced:
select test.id, test.dummy, test.dummyclob
ERROR in line 2:
ORA-00932: inconsistent data type: required - , but CLOB presented.
But if creating views from only ONE table with CLOB-type columns, or from two tables WITHOUT CLOB-typed columns, the creation will succeed. The following 1) and 2) will succeed, both:
1) one table, with CLOB-typed column
create view dummyview (id, dummy, dummyclob) as
select id, dummy, dummyclob from test;
2) two tables, without CLOB-typed columns
create view dummyview (id, dummy) as
select id, dummy from test
union
select id, dummy from test_bak;
I want to merge the two tables all, with complete columns, how to write the CREATE VIEW SQL statement?
many thanks in advanceDong Wenyu,
No.
But you could do this:
SELECT source.*, nvl (tab1.clob_column, tab2.clob_column)
FROM your_table1 tab1, your_table2 tab2, (
SELECT primary_key, ...
FROM your_table1
UNION
SELECT primary_key, ...
FROM your_table2
) source
WHERE source.primary_key = tab1.id (+)
AND source.primary_key = tab2.id (+)
In other words, do the set operation (UNION (ALL)/INTERSECT/MINUS) on just the PK columns before pulling in the LOB columns.
d. -
Creating a better update table statement
Hello,
I have the following update table statement that I would like to make more effecient. This thing is taking forever. A little background. The source table/views are not indexed and the larger of the two only has 150k records. Any ideas on making more effecient would be appreciate.
Thanks.
Ryan
Script:
DECLARE
V_EID_CIV_ID SBI_EID_W_VALID_ANUM_V.SUBJECT_KEY%TYPE;
V_EID_DOE DATE;
V_EID_POE SBI_EID_W_VALID_ANUM_V.POINT_OF_ENTRY%TYPE;
V_EID_APPR_DATE DATE;
V_CASE_CIV_ID SBI_DACS_CASE_RECORDS.CASE_EID_CIV_ID%TYPE;
V_CASE_DOE DATE;
V_CASE_POE SBI_DACS_CASE_RECORDS.CASE_CODE_ENTRY_PLACE%TYPE;
V_CASE_APPR_DATE DATE;
V_CASE_DEPART_DATE DATE;
V_SBI_UPDATE_STEP SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP%TYPE;
V_SBI_CIV_ID SBI_DACS_CASE_RECORDS.SBI_CIV_ID%TYPE;
CURSOR VALID_CIV_ID_FROM_EID IS
SELECT EID.SUBJECT_KEY,
TO_DATE(EID.PROCESS_ENTRY_DATE),
EID.POINT_OF_ENTRY,
TO_DATE(EID.APPREHENSION_DATE),
DACS.CASE_EID_CIV_ID,
TO_DATE(DACS.CASE_DATE_OF_ENTRY,'YYYYMMDD'),
DACS.CASE_CODE_ENTRY_PLACE,
TO_DATE(DACS.CASE_DATE_APPR,'YYYYMMDD'),
TO_DATE(DACS.CASE_DATE_DEPARTED,'YYYYMMDD'),
DACS.SBI_UPDATE_STEP,
DACS.SBI_CIV_ID
FROM SBI_EID_W_VALID_ANUM_V EID,
SBI_DACS_CASE_RECORDS DACS
WHERE DACS.CASE_NBR_A = EID.ALIEN_FILE_NUMBER;
BEGIN
OPEN VALID_CIV_ID_FROM_EID;
SAVEPOINT A;
LOOP
FETCH VALID_CIV_ID_FROM_EID INTO V_EID_CIV_ID, V_EID_DOE, V_EID_POE,V_EID_APPR_DATE,V_CASE_CIV_ID, V_CASE_DOE,V_CASE_POE,V_CASE_APPR_DATE,V_CASE_DEPART_DATE,V_SBI_UPDATE_STEP,V_SBI_CIV_ID;
DBMS_OUTPUT.PUT_LINE('BEFORE');
EXIT WHEN VALID_CIV_ID_FROM_EID%FOUND;
DBMS_OUTPUT.PUT_LINE('AFTER');
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_CASE_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 1
WHERE V_CASE_CIV_ID IS NOT NULL
AND V_CASE_CIV_ID <> 0;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 2
WHERE V_SBI_CIV_ID IS NULL AND V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE = V_CASE_POE
AND V_EID_APPR_DATE = V_CASE_APPR_DATE
AND V_EID_APPR_DATE = V_CASE_DEPART_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 3
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE = V_CASE_POE
AND V_EID_APPR_DATE = V_CASE_APPR_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 4
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE = V_CASE_POE
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) > -4
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) < 4 ;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 5
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE <> V_CASE_POE
AND V_EID_APPR_DATE = V_CASE_APPR_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 6
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_POE = V_CASE_POE
AND V_EID_APPR_DATE = V_CASE_APPR_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 7
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_APPR_DATE = V_CASE_APPR_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 8
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) > -4
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) < 4;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 9
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE = V_CASE_POE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 10
WHERE V_SBI_UPDATE_STEP = 0
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) > -4
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) < 4;
END LOOP;
CLOSE VALID_CIV_ID_FROM_EID;
COMMIT;
END;
-----Thats it. Thanks for your help.
RyanPlease use [ code] or [ pre] tags to format code before posing:
DECLARE
V_EID_CIV_ID SBI_EID_W_VALID_ANUM_V.SUBJECT_KEY%TYPE;
V_EID_DOE DATE;
V_EID_POE SBI_EID_W_VALID_ANUM_V.POINT_OF_ENTRY%TYPE;
V_EID_APPR_DATE DATE;
V_CASE_CIV_ID SBI_DACS_CASE_RECORDS.CASE_EID_CIV_ID%TYPE;
V_CASE_DOE DATE;
V_CASE_POE SBI_DACS_CASE_RECORDS.CASE_CODE_ENTRY_PLACE%TYPE;
V_CASE_APPR_DATE DATE;
V_CASE_DEPART_DATE DATE;
V_SBI_UPDATE_STEP SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP%TYPE;
V_SBI_CIV_ID SBI_DACS_CASE_RECORDS.SBI_CIV_ID%TYPE;
CURSOR VALID_CIV_ID_FROM_EID IS
SELECT EID.SUBJECT_KEY,
TO_DATE(EID.PROCESS_ENTRY_DATE),
EID.POINT_OF_ENTRY,
TO_DATE(EID.APPREHENSION_DATE),
DACS.CASE_EID_CIV_ID,
TO_DATE(DACS.CASE_DATE_OF_ENTRY,'YYYYMMDD'),
DACS.CASE_CODE_ENTRY_PLACE,
TO_DATE(DACS.CASE_DATE_APPR,'YYYYMMDD'),
TO_DATE(DACS.CASE_DATE_DEPARTED,'YYYYMMDD'),
DACS.SBI_UPDATE_STEP,
DACS.SBI_CIV_ID
FROM SBI_EID_W_VALID_ANUM_V EID,
SBI_DACS_CASE_RECORDS DACS
WHERE DACS.CASE_NBR_A = EID.ALIEN_FILE_NUMBER;
BEGIN
OPEN VALID_CIV_ID_FROM_EID;
SAVEPOINT A;
LOOP
FETCH VALID_CIV_ID_FROM_EID INTO V_EID_CIV_ID, V_EID_DOE,
V_EID_POE,V_EID_APPR_DATE,V_CASE_CIV_ID, V_CASE_DOE,
V_CASE_POE,V_CASE_APPR_DATE,V_CASE_DEPART_DATE,V_SBI_UPDATE_STEP,V_SBI_CIV_ID;
DBMS_OUTPUT.PUT_LINE('BEFORE');
EXIT WHEN VALID_CIV_ID_FROM_EID%FOUND;
DBMS_OUTPUT.PUT_LINE('AFTER');
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_CASE_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 1
WHERE V_CASE_CIV_ID IS NOT NULL
AND V_CASE_CIV_ID <> 0;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 2
WHERE V_SBI_CIV_ID IS NULL AND V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE = V_CASE_POE
AND V_EID_APPR_DATE = V_CASE_APPR_DATE
AND V_EID_APPR_DATE = V_CASE_DEPART_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 3
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE = V_CASE_POE
AND V_EID_APPR_DATE = V_CASE_APPR_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 4
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE = V_CASE_POE
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) > -4
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) < 4 ;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 5
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE <> V_CASE_POE
AND V_EID_APPR_DATE = V_CASE_APPR_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 6
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_POE = V_CASE_POE
AND V_EID_APPR_DATE = V_CASE_APPR_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 7
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_APPR_DATE = V_CASE_APPR_DATE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 8
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) > -4
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) < 4;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 9
WHERE V_SBI_UPDATE_STEP = 0
AND V_EID_DOE = V_CASE_DOE
AND V_EID_POE = V_CASE_POE;
UPDATE SBI_DACS_CASE_RECORDS
SET SBI_DACS_CASE_RECORDS.SBI_CIV_ID = V_EID_CIV_ID,
SBI_DACS_CASE_RECORDS.SBI_UPDATE_STEP = 10
WHERE V_SBI_UPDATE_STEP = 0
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) > -4
AND (V_EID_APPR_DATE - V_CASE_APPR_DATE) < 4;
END LOOP;
CLOSE VALID_CIV_ID_FROM_EID;
COMMIT;
END;Peter D. -
Guys,
I need to update table A columns col3, col4, col5 and col6 by table b columns col3, col4, col5 and col6 however table b col5 and col6 values need to come from table c col1.
Means table b col5 and col6 have values in it however i need to replace them with value from table c col1 and need to update table a col5 and col6 accordingly.
table a and table b has col1 and col2 in common.
i am trying something like this.
Update a
a.col3 = b.col3,
a.col4 = b.col4,
a.col5 = (select col1 from table_c c where c.col2=b.col5),
a.col6 = (select col1 from table_c c where c.col2=b.col6)
from table_A a inner join table_b
on a.col1=b.col1 and a.col2=b.col2
can someone help me reframe above update query?
thanks in advance for your help.Try the below:(If you have multiple values, then you may need to use TOP 1 as commented code in the below script)
create Table tableA(Col1 int,Col2 int,Col3 int,Col4 int,Col5 int,Col6 int)
Insert into tableA values(1,2,3,4,5,6)
create Table tableB(Col1 int,Col2 int,Col3 int,Col4 int,Col5 int,Col6 int)
Insert into tableB values(1,2,30,40,50,60)
create Table tableC(Col1 int,Col2 int,Col3 int,Col4 int,Col5 int,Col6 int)
Insert into tableC values(100,50,30,40,2,2)
--Insert into tableC values(200,50,30,40,2,2)
Insert into tableC values(100,60,30,40,2,2)
Select * From tablea
Update a Set
a.col3 = b.col3,
a.col4 = b.col4,
a.col5 = (select col1 from tablec c where c.col2=b.col5 ),
a.col6 = (select col1 from tablec c where c.col2=b.col6 )
from tableA a inner join tableb b
on a.col1=b.col1 and a.col2=b.col2
--Update a Set
--a.col3 = b.col3,
--a.col4 = b.col4,
--a.col5 = (select Top 1 col1 from tablec c where c.col2=b.col5 Order by c.Col1 asc),
--a.col6 = (select Top 1 col1 from tablec c where c.col2=b.col6 Order by c.Col1 asc)
--from tableA a inner join tableb b
--on a.col1=b.col1 and a.col2=b.col2
Select * From tablea
Drop table tablea,Tableb,TableC -
Help with UPDATE table and database RELATIONSHIPS
HI there, I have been trying to create an update table for
weeks now and keep getting error messages.
The database has a table named:
"books" in the table cells are "idbook" and "book".
"suppliers" in the table cells are "idsupplier" and
"supplierName".
"category" in the table cells are "idcategory" and
categoryName"
They all have a relationships with this table:
"results" in the cells are "idbook", "idsupplier" and
"idcategory".
This "results" table brings all of the above tables together.
When I try to do an update, i am doing one to the results
table. Is this correct?
The updates have problems because when drawing the text to
the update table to view it comes in text form.
When trying to update, it wont becuase all of the cells in
the results table are numeric. This is because of the
relationships.
Can anyone suggest where i may be going wrong.
Ask anything you need to.
TAMM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Session("MM_UserName") <> "") Then
Recordset1__MMColParam = Session("MM_UserName")
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_connSeek_STRING
Recordset1.Source = "SELECT * FROM Query1 WHERE UserName = '"
+ Replace(Recordset1__MMColParam, "'", "''") + "'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim rsUpdate
Dim rsUpdate_numRows
Set rsUpdate = Server.CreateObject("ADODB.Recordset")
rsUpdate.ActiveConnection = MM_connSeek_STRING
rsUpdate.Source = "SELECT * FROM tblSpecies"
rsUpdate.CursorType = 0
rsUpdate.CursorLocation = 2
rsUpdate.LockType = 1
rsUpdate.Open()
rsUpdate_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<html>
<head>
<link href="css%20files/paragraph.css" rel="stylesheet"
type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new
Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0;
i<a.length; i++)
if (a
.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0"
marginwidth="0" marginheight="0"
onLoad="MM_preloadImages('images/Publicationb.gif','images/Factsheetsb.gif')">
<table width="100%" height="100%" border="1"
cellpadding="0" cellspacing="0" bordercolor="#5D5D5D">
<tr>
<td colspan="2">
<div align="right"></div>
<div align="left"></div>
</td>
</tr>
<tr>
<td colspan="2"><table width="100%" height="100%"
border="0" cellpadding="0" cellspacing="0"
bordercolor="#5D5D5D">
<tr>
<td valign="top"><form
ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
<table width="90%" border="0" align="center"
cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><div
align="center"></div> <table border="1" align="center"
cellpadding="2" cellspacing="0" bordercolor="#FFFFFF">
<tr bgcolor="ECECD7">
<td colspan="2"><div align="center">
<p><strong><font size="3">Update Key Word
& Category</font></strong></p>
</div>
</td>
</tr>
<tr>
<td><div align="center">
<p><font size="1">Enter Up to 10 Species /
Product
Name</font></p>
</div>
</td>
<td><div align="center">
<p><font size="1">Select a
Category</font></p>
</div>
</td>
</tr>
<tr>
<td colspan="2" bordercolor="#D0D09D">
<%
While ((Repeat1__numRows <> 0) AND (NOT
Recordset1.EOF))
%>
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr><td width="50%"><div align="center">
<input name="f1" type="text" id="f13"
value="<%=(Recordset1.Fields.Item("TimberSpecies").Value)%>"
size="33">
</div></td>
<td width="45%"><div
align="center"></div></td></tr></table>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend %>
<div align="center"> </div> <div
align="center">
</div></td></tr><tr>td
colspan="2"> </td></tr><tr><td
colspan="2"><div align="right"><p><font
size="1">To Finalise Your Changes Please Press the Update
Button
<input name="update2" type="submit" id="update"
value="Update">
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%=
rsUpdate.Fields.Item("TimberSpecies").Value %>">
Maybe you are looking for
-
can anyone help with this issue
-
Safari will not display my Web page properly
http://www.ornl.gov/sci/fed/stelnews If you mouseover each issue link, you are supposed to see a summary of the issue in the right pane. It works in Mozilla, Opera, and IE. Safari just shows the first mouseover image. This is a Bug. I'm not sure how
-
Does SharePoint foundation supports Reporting services
Does user will be able to create Adhoc reporting services in SharePoint foundation 2010, our requirement is the SMDL created bit BIDS(Business Intelligence Development Studio) would be uploaded into the business intelligence site and user uses these
-
Deploy Icon Using .Jar files?
Hi ! i have created the .jar file using following command.. D:\myapp\icon> jar -cvf myappicon.jar *.gif then 'Copy' this myappicon.jar file to the D:\frs\forms90\java directory then i open formsweb.cfg and edit this as following.. [myApp] ⦠archive
-
11,000 referenced photos = 13 GB Aperture library! Help!
I'm coming from Lightroom 2 where I have 11,000 images in my library and the size of the preview file is about 5 gigs. I decided to import all the images as referenced files to Aperture 3 to test it out. However, the size of the Aperture library file