compare number two, in two tables varchar column
HelloI have two tables with varchar column number.
SQL> desc ckm1
Name Null? Type
----------------------------------------- -------- ----------------------------
N_COMP_ID NOT NULL NUMBER(10)
C_COMP_NAME NOT NULL VARCHAR2(120)
C_HOSTNAME VARCHAR2(20)
N_FRWK_COMP_FLAG NOT NULL NUMBER(1)
C_COMP_ENV VARCHAR2(1024)
SQL> desc ckm2
Name Null? Type
----------------------------------------- -------- ----------------------------
N_COMP_ID NOT NULL NUMBER(10)
C_COMP_NAME NOT NULL VARCHAR2(120)
C_HOSTNAME VARCHAR2(20)
N_FRWK_COMP_FLAG NOT NULL NUMBER(1)
C_COMP_ENV VARCHAR2(1024)
Is any function similar to 'dbms_lob.compare '...Thus, two field of two columns of text in another table can be compared?
Any example?
Any advice on this?
No comment
Something like that?
Select t1.n_comp_id, decode(t1.n_comp_name,t2.n_comp_name,'EQUAL','DIFFERENT') EQ_DIFF
from chm1 t1, chm2 t2
where t1.n_comp_id=t2.n_comp_id;
Max
[My Italian blog Oracle | http://oracleitalia.wordpress.com/2010/01/02/query-gerarchiche/]
Tags: Database
Similar Questions
-
By comparing the two tables for the integrity of the data
Hi all
I need to compare two tables for the integrity of the data through the SQL query.If you need to compare all the columns of t1 to t2:
(SELECT * FROM t1 MINUS SELECT * FROM t2) UNION ALL (SELECT * FROM t2 MINUS SELECT * FROM t1);
Kind regards
Ankit Rouault
http://theoraclelog.blogspot.in -
by comparing the two tables with
With the help of 10 gr 2
Assuming that we have two tables with the following structure:
create table1 (integer id, amount1 number, status varchar2 (200));
create table2 (integer id, number, status varchar2 amount2 (200));
Table1 contains a single line:
ID = 4711, amount1 = 3, status = "not ok".
Table2 contains one or more lines with table2.id = table1.my_field referenced:
ID = 4711, amount2 = 2, status = "not ok".
ID = 4711, amount2 = 2, status = "not ok".
ID = 4711, amount2 = 1, status = "not ok".
ID = 4711, amount2 = 4, status = "not ok".
The amount1 in Table1 is a cumulative sum of Table2 lines what status should be set to "ok". Table1.my_field is particularly well indexed.
How to make all the lines (for example via the rowid) from Table2 that sum on amount2 is the amount1 in the line after line in Table1 (for switching their table2.status to 'ok')?
I hope my question is clear enough...Try this
SQL> select * from table2; ID AMOUNT2 STATUS ---------- ---------- ------ 4711 2 Ok 4711 2 not ok 4711 1 Ok 4711 4 not ok SQL> roll Rollback complete. SQL> select * from table1; ID AMOUNT1 STATUS ---------- ---------- ------ 4711 3 not ok SQL> select * from table2; ID AMOUNT2 STATUS ---------- ---------- ------ 4711 2 not ok 4711 2 not ok 4711 1 not ok 4711 4 not ok SQL> SQL> SQL> update 2 table2 a 3 set 4 a.status = 'Ok' 5 where 6 rowid in 7 (select t2.rowid 8 from 9 (select 10 table2.*, 11 sum(amount2) over (partition by id order by rn) rn_total 12 from 13 (select table2.*, row_number() over (partition by id order by amount2) rn from table2 ) table2) t2, 14 table1 15 where 16 table1.id = t2.id and 17 t2.rn_total <= table1.amount1) 18 / 2 rows updated. SQL> select * from table2; ID AMOUNT2 STATUS ---------- ---------- ------ 4711 2 Ok 4711 2 not ok 4711 1 Ok 4711 4 not ok SQL>
-
Hello experts...
I'm new to this forum and Oracle coding complex.
I have a task in which I want to compare two tables with the same structure, same columns. My Oracle database is 11g Release 2. I want this column-by-column comparison and save the result in a separate table. (say result_table)
The structure of the table would be as follows:
SQL > desc emp;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NOT NULL NUMBER 4
ENAME VARCHAR2 (10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER (2)
SQL > emp_comp desc;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NOT NULL NUMBER 4
ENAME VARCHAR2 (10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER (2)
Both of the tables EMPNO is the primary key.
I want to compare these two tables based on the EMPNO (EMPNO even is both tables).
The result log table would be as follows:
SQL > create table result_table
2 (check_sr_no, number (5),)
table_name 3 varchar2 (30),
ROW_ID 4 varchar2 (20).
column_name 5 varchar2 (20).
6 column_data varchar2 (1000).
compared_by 7 varchar2 (10));
Table created.
SQL > alter table result_table
2 Add the constraint result_table_pk
3 primary key (check_sr_no);
Modified table.
The name of the table and the name of the column will not be hardcoded (based parameter by user)
I tried to use the dbms_comparison package, but do not find comparison of column to column.
I also used by using the query operator LESS. It's showing the difference in rank.
I also went to https://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:2151582681236
Your help will be very appreciated.
Thank you
DK
Tom Kyte has answered this question MANY times over the years. Here are links for its solution
https://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:4934799800346640847
-
By comparing the two huge table columns
Hello
I want to compare two tables each of RECON_APPEND_01 table contains 375 million and RECON_VS_24082011 450 million records.
RECON_APPEND_01 is a normal table and RECON_VS_24082011 is range partitoned table.
The two table has a primary key on the column Serial_number. (Oracle 11g R2)
Requirment is to obtain the records in the RECON_APPEND_01 table that are not present in RECON_VS_24082011.
I came across a few suggestions for using operator less. Here is the query and its plan to explain
Explain the Plan:CREATE TABLE RECON_APPEND_01 PARALLEL 3 NOLOGGING AS ( SELECT SERIAL_NUMBER FROM RECON_APPEND_01 minus select SERIAL_NUMBER from RECON_VS_24082011 )
Another alternate query:-------------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| TQ |IN-OUT| PQ Distrib | -------------------------------------------------------------------------------------------------------------------------- | 0 | CREATE TABLE STATEMENT | | 378M| 6451M| | 1398K (43)| | | | | 1 | PX COORDINATOR | | | | | | | | | | 2 | PX SEND QC (RANDOM) | :TQ10002 | | | | | Q1,02 | P->S | QC (RAND) | | 3 | LOAD AS SELECT | RECON_APPEND_03 | | | | | Q1,02 | PCWP | | | 4 | MINUS | | | | | | Q1,02 | PCWP | | | 5 | SORT UNIQUE | | 378M| 4336M| 7255M| 775K (4)| Q1,02 | PCWP | | | 6 | PX RECEIVE | | 378M| 4336M| | 114K (3)| Q1,02 | PCWP | | | 7 | PX SEND HASH | :TQ10000 | 378M| 4336M| | 114K (3)| Q1,00 | P->P | HASH | | 8 | PX BLOCK ITERATOR | | 378M| 4336M| | 114K (3)| Q1,00 | PCWC | | | 9 | TABLE ACCESS FULL | RECON_APPEND_01 | 378M| 4336M| | 114K (3)| Q1,00 | PCWP | | | 10 | SORT UNIQUE | | 184M| 2115M| 3539M| 538K (3)| Q1,02 | PCWP | | | 11 | PX RECEIVE | | 184M| 2115M| | 216K (1)| Q1,02 | PCWP | | | 12 | PX SEND HASH | :TQ10001 | 184M| 2115M| | 216K (1)| Q1,01 | P->P | HASH | | 13 | PX BLOCK ITERATOR | | 184M| 2115M| | 216K (1)| Q1,01 | PCWC | | | 14 | INDEX FAST FULL SCAN| SYS_C002617302 | 184M| 2115M| | 216K (1)| Q1,01 | PCWP | | --------------------------------------------------------------------------------------------------------------------------
Explain the Plan:CREATE TABLE recon_append_02 PARALLEL 3 NOLOGGING AS SELECT * FROM RECON_APPEND_01 a WHERE NOT EXISTS (SELECT 'X' FROM RECON_VS_24082011 b WHERE b.SERIAL_NUMBER = a.SERIAL_NUMBER)
Based on the plan I've run the second query, but it's taking a lot of time around 4 hours and still running.------------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| TQ |IN-OUT| PQ Distrib | ------------------------------------------------------------------------------------------------------------ | 0 | CREATE TABLE STATEMENT | | 378M| 26G| 450K (10)| | | | | 1 | PX COORDINATOR | | | | | | | | | 2 | PX SEND QC (RANDOM) | :TQ10000 | 378M| 26G| 153K (28)| Q1,00 | P->S | QC (RAND) | | 3 | LOAD AS SELECT | RECON_APPEND_02 | | | | Q1,00 | PCWP | | | 4 | NESTED LOOPS ANTI | | 378M| 26G| 153K (28)| Q1,00 | PCWP | | | 5 | PX BLOCK ITERATOR | | | | | Q1,00 | PCWC | | | 6 | TABLE ACCESS FULL| RECON_APPEND_01 | 378M| 22G| 116K (5)| Q1,00 | PCWP | | | 7 | INDEX UNIQUE SCAN | SYS_C002617302 | 1 | 12 | 0 (0)| Q1,00 | PCWP | | ------------------------------------------------------------------------------------------------------------
Please suggest.
With respect,
Adeline FaureLook carefully at the request of Tubby. Your problem in your test is with b.val = null. You can't compare anything on a null using normal operators.
SQL> select * from target_tab; VAL ---------- 1 2 3 4 5 6 7 8 9 10 SQL> select * from source_tab; VAL ---------- 6 7 8 9 10 SQL> select a.* 2 from target_tab a, source_tab b 3 where a.val = b.val(+) and 4 b.val is null; VAL ---------- 5 1 4 2 3
John
-
How to join two tables if you transpose the rows, columns and rows in one of the table
Hi guys,.
can someone help me please in the write request
I have two tables
Agents and Agent phones but in the agent phones table for the id of an agent it displays 4 rows because one of the column there types of different phones (office, mobile, home, fax)
So instead of display 4 rows, I used max(case...) to convert rows to columns
now how to reach it with another table
Requirement:
Database: 11.2.0.2.0
create the table AGENT_PHONE
(
agent_id NUMBER (20) not null,
agent_type_code VARCHAR2 (10) not null,
agent_type_prefix VARCHAR2 (10) not null,
Phone_Number VARCHAR2 (16) not null,
phone_type_code VARCHAR2 (10) not null
)
CREATE TABLEAGENTS
(
agent_id NUMBER (20) not null,
agent_type_code VARCHAR2 (10) not null,
agent_type_prefix VARCHAR2 (10) not null,
NAME VARCHAR2 (40) NOT NULL
)
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '4805551436', 'CELL');
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '1111111111', 'PHONE');
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '2223334444',' OFF');
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '5556667788', 'FAX');
INSERT INTO VALUES AGENTS
(29709, ARE ', 'OFFICE', 'FLY');
INSERT INTO VALUES AGENTS
(1234, ARE ', 'OFFICE', 'MIKE');
SELECT * FROM AGENT_PHONES
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX PHONE_NUMBER PHONE_TYPE_CODE ---------------------------------------------------------------------------------------------
29709 RE OFFICE 4805551436 CELL 29709 RE OFFICE 1111111111 PHONE 29709 RE OFFICE 2223334444 OFF 29709 RE OFFICE 5556667788 FAX
SELECT * AGENTS
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME
29709 RE OFFICE ROB 1234 RE OFFICE MIKE
This is so the data we have in both table
Now, I transposed rows to columns in the table of agent phones so I used the following query
SELECT AP. AGENT_ID,. AGENT_TYPE_CODE,. AGENT_TYPE_PREFIX.
MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'CELL' THEN AP. PHONE_NUMBER END) AS CELL.
MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'OFF' THEN AP PHONE_NUMBER END) AS TURNED OFF.
MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'FAX' THEN AP. PHONE_NUMBER END) LIKE FAX,.
MAX (CASE WHEN PHONE_TYPE_CODE = 'PHONE'. THEN AP PHONE_NUMBER END) AS PHONE
AGENT_PHONE AP
WHERE AP. AGENT_ID = 29709
GROUP OF AP. AGENT_ID, AP. AGENT_TYPE_CODE, AP. AGENT_TYPE_PREFIX.
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL OFF FAX PHONE 1 29709 RE OFFICE 4805551436 2223334444 5556667788 1111111111 My question is how this to join the agents table so that my output should be like this...
I want to display all the results in the table of the Agent, even if they are not in the table of agent phones. As you can see there are other agent id 1234 is also populated
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788 1234 RE OFFICE MIKE Currently, I run this query and I get the output as below
SELECT *.
AGENTS HAS
LEFT OUTER JOIN AGENT_PHONE AP
ON A.AGENT_ID = AP. AGENT_ID
AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.
AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX PHONE_NUMBER PHONE_TYPE_CODE 1 29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 CELL 2 29709 RE OFFICE ROB 29709 RE OFFICE 1111111111 PHONE 3 29709 RE OFFICE ROB 29709 RE OFFICE 2223334444 OFF 4 29709 RE OFFICE ROB 29709 RE OFFICE 5556667788 FAX 5 1234 RE OFFICE MIKE I want id 29709 agent in a line with 1234 agent also id to display
You can rotate your phone number of agent in columns
Select *.
of AGENT_PHONE
pivot)
min (PHONE_NUMBER)
for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')
)
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788 Then you can join to view inline or CTE
with AGENT_PHONE_PIVOT like)
Select *.
of AGENT_PHONE
pivot)
min (PHONE_NUMBER)
for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')
)
)
SELECT *.
AGENTS HAS
LEFT OUTER JOIN AGENT_PHONE_PIVOT AP
ON A.AGENT_ID = AP. AGENT_ID
AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.
AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX 29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788 1234 RE OFFICE MIKE - - - - - - - Is that what you're looking for?
-
Compare two tables, APEX
Hello
I am trying to compare two tables, but I want to display values that are the differnet from one to the other,
both tables have the same columns and have the same PK.
Thank you.Hello
You probably need a report based on a query like this:
SELECT d1.deptno, d1.dname, d2.dname, d1.loc, d2.loc FROM dept1 d1 INNER JOIN dept2 d2 ON d1.deptno = d2.deptno AND ( d1.dname <> d2.dname OR d1.loc <> d2.loc )
You can also consider using FULL JOIN where you have different values of primary key in both tables and you want to include in the report.
-
Comparing the sum of the two tables and correct by difference of amount in its second t
Hello guys,.
I have a very difficult task that I can't get my head around.
The sample data looks like this:
Master table
Request - booking - debit - credit - MasterAmout
1------------1----------------D---------------------------------15.3
1------------2----------------D---------------------------------480.6
1------------3------------------------------C-------------------496.8
------------------------------------------- 0.9
The slave table
Demande---reservation---debit---credit---slaveamout---slavecorrection
1------------1------------D------------------------------------15.3---------------14.5
1------------2------------D------------------------------------480.6-------------480.6
1------------3-----------------------------C-------------------496---------------496
-------------------------------------------0.1--------------------------------------0.9
The reservation have a total amount of 0.1, but must be corrected to 0.9 because the main table has 0.9.
Reservation 1 requires a correction so the slave table also has a total of 0.9 (business rule is, only corrections on the first booking). So we have
to change the amount of 15.3 to 14.5. I plan my SQL like this:
1 reservations sum of two tables for each claim. Compare the two for each individual claim.
2. If Captain sum the amount shows a difference between master / slave
2.1 select top 1 table reservation slave for the specific claim and increase/decrease by the difference of these two amounts.
Who is?Hello
Use MERGE to actually do the UPDATE.
The ROW_NUMBER analytic function to identify the first booking in slave (unless you can count on which the reservation = 1).MERGE INTO slave dst USING ( WITH master_summary AS ( SELECT claim , SUM ( master_ampount * CASE WHEN debit = 'D' THEN -1 WHEN credit = 'C' THEN 1 END ) AS balance FROM master GROUP BY claim ) SELECT s.claim , s.booking , SUM ( s.slave_amount * CASE WHEN s.debit = 'D' THEN -1 WHEN s.credit = 'C' THEN 1 END ) OVER (PARTITION BY claim) - m.balance AS diff , ROW_NUMBER () OVER ( PARTITION BY claim ORDER BY booking ) AS r_num FROM master_summary m JOIN slave s ON m.claim = s.claim ) src ON ( src.claim = dst.claim AND src.r_num = 1 ) WHEN MATCHED THEN UPDATE SET dst.debit = CASE WHEN src.diff < 0 THEN 'D' ELSE NULL END , dst.credit = CASE WHEN src.diff < 0 THEN NULL ELSE 'C' END , dst.slaveamount = ABS (src.diff) ;
If you would care to CREATE TABLE and INSERT statements for the sample data (showing the two tables, as they exist before the DML) then I could test this.
The design of history seems very uncomfortable. Instead of the debit and credit columns, it would be much simpler to have positive and negative amounts. Is it really worth now both not corrected and corrected the amounts in the table on the slave, especially if you keep only versions corrected debit and credit columns?
-
SQL join on the two tables where the column as another column
Hi all
tried to get the results of a join between two tables where only one column is like another.
Table1 (nameA) examples: black2, green1
Table2 (Name) example: black2.location.uk.com, green1.location.uk.com
so, for example, I want to match all those in table1 with black2 column in table2 that begins with black2 and so of suite, if you see what im trying to get to!
My sql up to now:
but it errors:select * from schema.table1 a join schema.table2 b on a.nameA like concat('%', b.nameB, '%');
ORA-00909: invalid number of arguments
00909 00000 - "invalid number of arguments.
Any help or advice would be greatly appreciated, thank you!Or any of them should do...
select * from schema.table1 a join schema.table2 b on a.nameA like '%'||b.nameB||'%';
or
select * from schema.table1 a join schema.table2 b on instr(b.nameB,a.nameA) > 0
-
Find unmatched columns from two tables
Hello guys,.
I am trying to compare two tables based on a key of the indexed columns.
Here is an example of what I'm trying to achieve:
Table A: A_ID A_Name A_Income A_housecount
Jess 11 9 2
Rauny 4 6 22
Table b: B_ID B_Income B_housecount
11-5-2
22 6 4
In the example above data columns A_ID and B_Id are same in both tables. I'm trying to compare A_Income with B_Income & & A_housecount with B_housecount. The results of this series of samples would be:
11-9-2
11-5-2
as income in the same id is different.
As I have large amount of data in the two tables can you please give me some ideas on how I can get my results? Let me know if the explanation is not clear for you.
Thanks in advanceselect hshold_id,hsold_income,hshold_size, 'abc.' || case count(src1) when 0 then 'demo' else 'hshold' end the_source from (select hshold_id,hsold_income,hshold_size, 1 src1, to_number(null) src2 from abc.hshold union all select hshold_id,hsold_income,hshold_size, to_number(null) src1, 2 src2 from abc.demo ) group by hshold_id,hsold_income,hshold_size having count(src1) != count(src2)
Concerning
Etbin
Edited by: Etbin on 11.2.2011 18:00
correction of alignment -
Hello
can you please help me.
How can I compare two table. following my code...
var my_array:Array = Array (5,10,15,20,25,30)
var new_array:Array = Array (7,8,9,10,11,12,13)
for (var i: Number = 0; i < my_array.length; i ++) {}
{if(my_array[i]==new_array[i])}
trace (my_array [i])
}
}Thanks in advance,
JaxNa
Then, you're almost on correct... See the same code that I modified a little,
var my_array:Array = Array (5, 10, 15, 20, 25, 30);
var new_array:Array = Array (7, 10, 9, 10, 10, 30, 13);for (var i: Number = 0; i
If (my_array [i] is {new_array [i]})
trace ("' my Array'" + i + "("+my_array[i]+")"new_array' "+ i +"("+new_array[i]+") = Matching");
} else {}
trace ("' my Array'" + i + "("+my_array[i]+") 'new_array'" + i + "("+new_array[i]+") = is only not to");
}
}If this is not so, explain exactly what you want
-
Implement conditional read-only column in the set of two Tables
Hello
I would like to implement a mechanism of "read-only conditional" on a column in a table with two tables in total to be involved in this situation.
I have a demo/proof of concept of the present and things work as expected in the tests I've done; However, I would like any input as to if there is a better way, etc.
This is a far-fetched but demo that illustrates the main ingredients however. Oracle 10.2.0.4 version 64 bit on Windows Server 2008 Release 2 64-bit.
-Table DDL and small sample data
-The rules relating to the conditional objective of read-onlycreate table band( band_id number primary key, band_name varchar2(20), status varchar2(20) ); create table band_member( band_id references band, member_name varchar2(20) ); insert into band values(3, 'The Rutles', 'prefab4'); insert into band values(4, 'The Beatles', 'established'); commit; insert into band_member values(3, 'Ron Nasty'); insert into band_member values(3, 'Dirk McQuickly'); insert into band_member values(3, 'Stig O''Hara'); insert into band_member values(3, 'Barrington Womble'); commit; insert into band_member values(4, 'John Lennon'); insert into band_member values(4, 'Paul McCartney'); insert into band_member values(4, 'George Harrison'); insert into band_member values(4, 'Ringo Starr'); commit;
1 is not allowed to update band.band_name when band.status = 'prefab4'
2 is not allowed to insert/update / deletion of lines of band_member when the parent a band.status row = 'prefab4'
-The triggers used to implement the goal (current solution)
-Quick example of test for each conditioncreate or replace trigger t1 before update of band_name on band for each row when (old.status = 'prefab4' or new.status = 'prefab4') begin raise_application_error(-20010, 'can not update band_name when status=''prefab4'''); end; / create or replace trigger t2 before insert or update or delete on band_member for each row declare l_status band.status%type; l_band_id band_member.band_id%type; cursor l_cursor (p_band_id number) is select status from band where band_id = p_band_id for update; begin if updating or inserting then l_band_id := :new.band_id; else l_band_id := :old.band_id; end if; open l_cursor(l_band_id); fetch l_cursor into l_status; close l_cursor; if l_status = 'prefab4' then raise_application_error(-20011, 'can not update child when parent status=''prefab4'''); end if; end; /
As I said, while my simple tests seem to show the correct results, there I was wondering if there could be a better way to implement such functionality.update band set band_name = 'THE RUTLES' where band_id = 3; update band * ERROR at line 1: ORA-20010: can not update band_name when status='prefab4' ORA-06512: at "DEMO.T1", line 2 ORA-04088: error during execution of trigger 'DEMO.T1' update band_member set member_name = 'RON NASTY' where member_name = 'Ron Nasty'; update band_member * ERROR at line 1: ORA-20011: can not update child when parent status='prefab4' ORA-06512: at "DEMO.T2", line 18 ORA-04088: error during execution of trigger 'DEMO.T2'
I tried to provide the information needed, but if I managed to omit something, please let me know.
See you soon,.
ChalfontHi, Chalfont,
user13146957 wrote:
...
I'm went to the road to slider to add the clause "for update" to force the serialization on the line - i.e. the idea was to avoid the case where another session might want to update the State a moment after my extraction but before the rest of the finished code. Who is?No, not really. The trigger on tape prevents anyone else from ever change their status from 'prefab4' to something else (or vice versa).
Even apart from this, you put some efforts to prevent something which will be allowed a fraction of a second later (or maybe the other way around). What is significant in that split second?I didn't think about other ideas rather than the approach of the trigger, but came up empty, somehow, to this day. I am open to resort to others and make some schema changes is not off the table either.
FGA (Fine grain access), or his brothers and sisters more older VPD (virtual private database) can also do what you want, but instead of trigger an error, they ignore the illegal action. This can be an advantage or a disadvantage, depending on your needs.
Another approach is for the owner of the table, not to grant INSERT, UPDATE or DELETE privileges to anyone: all DML must be made via a procedure (or procedures) belonging to the owner of the table, which grants EXECUTE privileges instead of other privileges.
-
compare two tables and update the differences
Hi all
Sorry for the newbie question, but I am a beginner in the present.
I have two tables, both have same structure-
CODE - code NUMBER (6,0) store is the primary key does not change and is unique
ADDRESS1
ADDRESS2
ADDRESS3 - all VARCHAR2 (100)
One of the tables is named MASTER, the other being updated. MASTER contains hundreds of lines, while the table of UPDATES may have anywhere from zero to 10 or more.
I want to compare the table of UPDATES against the MASTER of the table and if there is a difference, ask the differences in the table in UPDATES to the MASTER of table - so if the address of an Exchange store, then the change is reflected in the MASTER table by crushing with the data contained in the UPDATES table.
I thought that maybe using sliders and compare each field but there must be a more efficient way.
I hope that I have explained quite clearly... any help would be greatly appreciated.
Thank you
BillEducation MERGE, assuming that your version supports supported the MERGER.
SY.
-
Several lines to a format of columns from two tables
Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
The difficulty to return several lines simple lines/columns in two tables.
Table 1:
ID BOOK_NBR
1 1001
1 2001
2 1010
3 1020
Table 2:
AUTHOR BOOK_NBR
1001 JOHN_1
2001 JOHN_2
MARY 1010
1020 JUNE
Desired output:
ID BOOK_NBR AUTHOR BOOK_NBR AUTHOR
1 1001 JOHN_1 2001 JOHN_2
2 MARY 1010
3-1020 JUNE
There are an unknown number of BOOK_NBR to one ID.
Any guidance would be appreciated.
-
Hello
I need to compare two tables (T1, T2) and update existing records only in T2, but not in T1. So basically, the lines updated in T2:
Select * from T2 where T2.id not in (select id from T1).
What would be a good way to achieve this in ODI?
I created an ODI interface with a join T2.id not in T1.ID, but it did not work "coz:" ORA-01427: einreihig subquery returns several lines "."
Appreciate any input/access map.
Thank you.Hi Michele...
At first glance, there are at least 2 ways to do it:
(1) put the steps in "(select id from T1)" (you can use an ODI API to get the schema dynamically) as an object filter to T2 (interface), use the incremental update IKM SQL and put "Insert" option on 'No'. " This will do a few updates.
OR
(2) in an interface set the T1 and T2 and left join (based on T2) load a temp table where all fields accept the value zero. Next to the columns to update (of course the T2), create an ID column (I named him as T1_Temp_ID) and map the Id of the T1 to it.
Now just create new interface where the temperature is source and put a filter like "T1_Temp_ID is not null.The first option is less complex and can bring better performance.
The second option gives a better follow-up of the use of the table and the columns, but can be less performatique.This help you?
Maybe you are looking for
-
Wireless on Satellite L300D issue
My Toshiba laptop Satellite L300D does not display available Wi - Fi networks, even if the Wi - Fi light is 'ON'.Ask you please guide me / help me solve this problem. Thank you / Florence
-
HP Notebook: Enter the password administrator or power on password
I have a laptop hp 8.1 windows model is and other information are not visible. By mistake, I created a password in the bios. Everytime I turn it on it ask an administrator password or power on password. I know the password but I how to go into bios a
-
Microsoft Wireless 400 not correctly typing certain keys
When I type I get ", do not know what the problem is...". Thought it was keyboard so purchased new Microsoft wireless 400 and do the same thing! Must be something with the computer!
-
MY SECURITY CENTER HAS TURNED OFF, I WENT INTO THE CONTROL PANEL TO TURN BACK BUT I COULDN'T SO I WENT PROGRAMS TO LOOK TO HIGH SECURITY CENTER AND IT WASN'T WHAT I DO AND HOW TO GET BACK MY SECURITY CENTER
-
Hello I downloaded a theme on the internet but I got to unpack it before I send to my mobile phone, that I tried to do with vista help & support on my phone but it didn't work! What should I do? Its a file JAD but on the website where I downloaded th