The MINUS operator in SQL
Hi
i use this minus operator to find the non matching row of the second query.
after looking at the reasult of this query , i searched the one result in the second query alone i could see the data.
it's worng The MINUS query returns all rows in the first query that are not returned in the second query.
in my case it's returning the rows which returned by the second query.
(select distinct lower(trim(to_char(sso))),lower(trim(to_char(region))),to_date(expiration_date,'DD-MM-YY') from ca_ourc_view
where rownum <1001
minus
(select distinct lower(trim(to_char(sso))),lower(trim(to_char(region))),to_date(expiration_date,'DD-MM-YY') from ourc_members_v1@gesprd
where rownum <1001
)thanks
Raj
in my case it's returning the rows which returned by the second query.can't happen like this
for example
SQL> select * from scott.emp where empno=7369
2 minus
3 select * from scott.emp where empno=7499;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
Similar Messages
-
I am very new to oracle and am working with the minus operator to run a query. I could use some help!
Here is the query I am working on:
select suppliername, partname
from quote
where partname = 'hammer'
minus
select suppliername, partname
from quote
where partname = 'hammer';
HOW DO I GET THE QUERY TO DISPLAY ONLY THE ROWS OF SUPPLIERNAMES THAT SUPPLY ONLY HAMMERS?
I WOULD GREATLY APPRECIATE SOME CLARIFICATION.HOW DO I GET THE QUERY TO DISPLAY ONLY THE ROWS OF SUPPLIERNAMES THAT SUPPLY ONLY HAMMERS?It may, for some data related reason, give you the result you were expecting, but this query does not answer that question because you have included partname in the MINUS.
E.g.
WITH quote AS
(SELECT 'BOB' suppliername, 'HAMMER' partname FROM DUAL UNION ALL
SELECT 'BOB' suppliername, 'SPANNER' partname FROM DUAL UNION ALL
SELECT 'TIM' suppliername, 'HAMMER' partname FROM DUAL UNION ALL
SELECT 'JACK' suppliername, 'HAMMER' partname FROM DUAL)
SELECT suppliername, partname
FROM quote
MINUS
SELECT suppliername, partname
FROM quote
WHERE partname != 'HAMMER';
SUPPLIERNAME PARTNAME
BOB HAMMER
JACK HAMMER
TIM HAMMER Clearly this is wrong because Bob supplies spanners (aka wrench).
However:
WITH quote AS
(SELECT 'BOB' suppliername, 'HAMMER' partname FROM DUAL UNION ALL
SELECT 'BOB' suppliername, 'SPANNER' partname FROM DUAL UNION ALL
SELECT 'TIM' suppliername, 'HAMMER' partname FROM DUAL UNION ALL
SELECT 'JACK' suppliername, 'HAMMER' partname FROM DUAL)
SELECT suppliername
FROM quote
MINUS
SELECT suppliername
FROM quote
WHERE partname != 'HAMMER';
SUPPLIERNAME
JACK
TIM Amongst the many alternatives - NOT EXISTS:
WITH quote AS
(SELECT 'BOB' suppliername, 'HAMMER' partname FROM DUAL UNION ALL
SELECT 'BOB' suppliername, 'SPANNER' partname FROM DUAL UNION ALL
SELECT 'TIM' suppliername, 'HAMMER' partname FROM DUAL UNION ALL
SELECT 'JACK' suppliername, 'HAMMER' partname FROM DUAL)
SELECT *
FROM quote q1
WHERE NOT EXISTS (SELECT 1
FROM quote q2
WHERE q2.suppliername = q1.suppliername
AND partname != 'HAMMER');
SUPPLIERNAME PARTNAME
JACK HAMMER
TIM HAMMER -
Problem with the minus operator - Urgent
Hi,
I am executing one source minus target query which is taking a lot of time to run (more than a day) in TEST and PROD environment.
But when i run the same query DEV it is workin fine giving results in few seconds.
Individual query is also takin less time as there are only some 10k records in target table and in source depending upon the date condition(max 500 rows).
I checked the indexes of DEV, test AND PROD. All are same.
Can any one help me in this.
ASAP.
Thanks in advance,
Harshadev - explain plan
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=ALL_ROWS 1 4507
SORT AGGREGATE 1
VIEW 4 4507
MINUS
SORT UNIQUE 4 2 K 256
HASH JOIN OUTER 4 2 K 255
NESTED LOOPS 1 444 223
HASH JOIN 37 10 K 28
FILTER 61 4 K 23
REMOTE SERIAL
REMOTE 1 105 2 SERIAL
REMOTE t1(source) 1 72 1 SERIAL
REMOTE t2(source) 10 K 1 M 32 SERIAL
SORT UNIQUE 6 K 406 K 4251
HASH JOIN 6 K 406 K 4183
TABLE ACCESS FULL t1(target) 11 K 439 K 87
TABLE ACCESS FULL t2 target) 372 K 8 M 4076
test explain plan -
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=ALL_ROWS 1 4958
SORT AGGREGATE 1
VIEW 235 4958
MINUS
SORT UNIQUE 235 124 K 703
CONCATENATION
HASH JOIN OUTER 219 115 K 271
NESTED LOOPS 2 870 211
NESTED LOOPS 2 826 209
HASH JOIN 47 12 K 66
FILTER 74 5 K 60
REMOTE SERIAL
REMOTE 1 105 2 SERIAL
REMOTE t1(source) 1 75 1 SERIAL
REMOTE t3(source) 1 22 1 SERIAL
REMOTE t2(source) 11 K 1 M 59 SERIAL
HASH JOIN OUTER 16 8 K 431
NESTED LOOPS 1 435 371
NESTED LOOPS 1 360 370
NESTED LOOPS 115 37 K 255
HASH JOIN 47 12 K 66
REMOTE t4(source) 74 5 K 60 SERIAL
NESTED LOOPS 106 20 K 5
REMOTE t5(source) 1 105 2 SERIAL
REMOTE t6(source) 106 9 K 3 SERIAL
REMOTE t7(source) 128 4 SERIAL
REMOTE t3(source) 1 22 1 SERIAL
REMOTE t1(source) 1 75 1 SERIAL
REMOTE t2(source) 11 K 1 M 59 SERIAL
SORT UNIQUE 7 K 439 K 4256
HASH JOIN 7 K 439 K 4183
TABLE ACCESS FULL t1(target) 12 K 474 K 88
TABLE ACCESS FULL t2(target) 373 K 8 M 4076 -
Minus operator versus 'not exists' for faster SQL query
Hi everybody,
Does anyone know if rewriting a query to use the MINUS operator instead of using NOT EXISTS in the query is faster, giving all else is the same?
Thanks very much!
Bill Loggins
801-971-6837
[email protected]It really depends on a bunch of factors.
A MINUS will do a full table scan on both tables unless there is some criteria in the where clause of both queries that allows an index range scan. A MINUS also requires that both queries have the same number of columns, and that each column has the same data type as the corresponding column in the other query (or one convertible to the same type). A MINUS will return all rows from the first query where there is not an exact match column for column with the second query. A MINUS also requires an implicit sort of both queries
NOT EXISTS will read the sub-query once for each row in the outer query. If the correlation field (you are running a correlated sub-query?) is an indexed field, then only an index scan is done.
The choice of which construct to use depends on the type of data you want to return, and also the relative sizes of the two tables/queries. If the outer table is small relative to the inner one, and the inner table is indexed (preferrable a unique index but not required) on the correlation field, then NOT EXISTS will probably be faster since the index lookup will be pretty fast, and only executed a relatively few times. If both tables a roughly the same size, then MINUS might be faster, particularly if you can live with only seeing fields that you are comparing on.
For example, if you have two tables
EMPLOYEE
EMPID NUMBER
NAME VARCHAR2(45)
JOB VARCHAR2(45)
HIRE_DATE DATE
and
RETIREE
EMPID NUMBER
NAME VARCHAR2(45)
RET_DATE DATEIf you wanted to see if you had retirees that were not in the employee table, then you could use either MINUS or NOT EXISTS (or even NOT IN, but you didn't ask). However you could possibly get different results.
SELECT empid,name
FROM retirees
MINUS
SELECT empid,name
FROM employeeswould show retirees not in the emp table, but it would also show a retiree who had changed their name while retired. A safer version of the above using MINUS would be
SELECT empid,name
FROM retirees
WHERE empid IN (SELECT empid
FROM retirees
MINUS
SELECT empid
FROM employees)A full scan of retirees, a full scan of employees (Assuming indexes on both, then maybe an index fast full scan) and two sorts for the minus, at best an index probe then table access by rowid on retirees, possibly a full scan of retirees for the outer query.
Assuming that employees is indexd on empid then
SELECT empid,name
FROM retirees
WHERE NOT EXISTS (SELECT 1
FROM employees
WHERE retirees.empid = employees.empid)requires a full scan of retirees and an index access into employees index for each row.
As with most things SQL, the only real way to tell is to benchmark.
HTH
John -
Hello,
Am trying to upgrade a SCOM SP1 environment to SCOM R2( 3 MGT servers, 1 GW and 2 Web console boxes )
The prerequisites are failing and it is stating the following ;
Operational Database SQL Version Check - The installed Version of SQL Server is not supported for the operational database
Data Warehouse SQL Version Check - The installed Version of SQL Server is not supported for the data warehouse
The SQL servers are running SQL 2012 SP1 64 Enterprise, which is compatible.
All other pre-upgrade tasks have been done.
Help appreciated!I'm having the exact same issue, I believe. I think that Tubble has problem with SCOM 2012. Not 2007.
I've checked the compatibility list for both SCOM 2012 SP1 and R2. All newer Windows Server and SQL versions are supported. We're running the SQL 2012 SP1 x64 Standard edition on a Windows Server 2012 Standard.
I even tried to move the database from SQL 2012 to an older SQL 2008 R2, but that's not supported either. Only upgrading. Not downgrading.
So, I started checking the opsMgrSetupWizard.log file for clues. And the error message was there as well. But the reason why it says not supported is that it can't get the info about the OS version, so I guess it assumes the OS version is to low. The RPC
service can not be reached.
[10:29:11]: Error: :GetRemoteOSVersion(): Threw Exception.Type: System.Runtime.InteropServices.COMException, Exception Error Code: 0x800706BA, Exception.Message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
[10:29:11]: Error: :StackTrace: at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Management.ManagementScope.InitializeGuts(Object o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at Microsoft.EnterpriseManagement.OperationsManager.Setup.Common.SetupValidationHelpers.GetRemoteOSVersion(String remoteComputer)
[10:29:11]: Debug: :IsSQLOnAValidComputer: remote OS version string was null or empty.
[10:29:11]: Error: :Error:IsValidSQLVersionCheck: SqlServer OS version is too low.
[10:29:11]: Debug: :**************************************************
[10:29:11]: Error: :<![CDATA[CheckPrerequisites: Logic Type:and IsValidOMDBSQLVersionCheck: 2]]>
[10:29:11]: Error: :
[10:29:11]: Error: :CheckPrerequisites: OMDBSqlVersionCheckTitle: Failed
[10:29:11]: Error: :
[10:29:11]: Debug: :**************************************************
[10:29:33]: Error: :GetRemoteOSVersion(): Threw Exception.Type: System.Runtime.InteropServices.COMException, Exception Error Code: 0x800706BA, Exception.Message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
[10:29:33]: Error: :StackTrace: at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Management.ManagementScope.InitializeGuts(Object o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at Microsoft.EnterpriseManagement.OperationsManager.Setup.Common.SetupValidationHelpers.GetRemoteOSVersion(String remoteComputer)
[10:29:33]: Debug: :IsSQLOnAValidComputer: remote OS version string was null or empty.
[10:29:33]: Error: :Error:IsValidSQLVersionCheck: SqlServer OS version is too low.
[10:29:33]: Debug: :**************************************************
So, in our case this was just a FW that was blocking some high ports between management server and SQL. I believe TCP port 135 also needs to be open.
Let's hope this fixes your issue as well, Tubble.
Have a great day! -
Use of double Minus operator....
Hi ,
I have a situation where i need to use the minus operator in such a way that:
<sql_statement_A>
Minus
<sql_statement_B>
Minus
<sql_statement_C>
The resulting row set will return rows from sql_statement_A minus rows from sql_statement_B or sql_statement_A minus rows from sql_statement_C... Is the above sql pattern is correct....or , do i need to write two views
<sql_statement_A>
Minus
<sql_statement_B>
and
<sql_statement_A>
Minus
<sql_statement_C>
and one third making Union of the two above...????
many thanks,
SimonIf in doubt, use parentheses to make them run the way you want.
So..
(<sql_statement_A>
minus
<sql_statement_B>)
minus
<sql_statement_C>
Just like OR conditions in the where clause, grouping with parentheses will greatly help those who come later to maintain it. And this looks simpler and more efficient than using two minus operations and combining the result. -
Minus operator abnormal behavior question
Oracle 10gR2/Oracle 11g on Windows 2003 R2 32-bit
There is a very weird query with minus, it is basically:
select id from table1 where xxxx --> query 1
minus
select id from table1 where xxxx --> query 2the queries are against the same table, only difference is the where clause. There are 3rd party implemented type and index being used in the where clause in both queries.
query 1 returns 100 records (i.e. all the records in table1), query 2 returns 0 record.
but with the minus operator, it returns 1 record.
If I modify query 2, remove the 3rd party type/index, use another filter that will return 0 record too, then the minus query returns 100 records correctly.
If I modify the whole query to use not in/not exist instead of minus, then query returns 100 records correctly.
Question: is it possible the 3rd party type/index can cause the minus operator to behave this way?
Edited by: modeler on Nov 18, 2009 3:15 PM
Edited by: modeler on Nov 18, 2009 3:16 PMIs there any way you can put together a representative test case that we can test here?
-
Hi All,
I have created a report utilizing the minus operation as follows:
Person_Wid (Filtered by a set of criteria selected by users via prompts)
minus
Person_wid (Filtered by another set of criteria selected by users via prompts)
I get the correct person_wids.
However I need to calculate count of the person_wid obtained in the result. Can someone tell me how I can achieve this.
ThanksHi David,
Thanks for ur suggestion. However the query I am trying to execute is
Person_Wid (Filtered by a set of criteria selected by users via prompts) ----->A
minus
Person_wid (Filtered by another set of criteria selected by users via prompts)--------->B
So when I implement what you suggested I get the count of only 'A'. It does not give me the row count of (A-B). Is there something I need to tweak?
Thanks,
Nikita -
SQL Azure - Intermittent The wait operation timed out
I have a website engine which runs a few hundred "white label" sites. It's hosted on Azure with a SQL Azure Business database. Generally everything is fine - it all works and runs at a good speed.
However, throughout the day I get maybe 40 or 50 of the error:
System.ComponentModel.Win32Exception: The wait operation timed out
Please don't refer me to the connectivity blog at http://blogs.msdn.com/b/sqlazure/archive/2010/03/22/9982979.aspx as this seems to refer to problems where you just can't connect. My problem is that it's fine most of the time, but I still get these
intermittently.
This is sometimes on the main database, but we're also using a database for sessions and this gets the errors too. Both databases are on the same server.
I also get errors like:
An existing connection was forcibly closed by the remote host
and:
System.Data.SqlClient.SqlException: The service has encountered an error processing your request. Please try again. Error code 40143. A severe error occurred on the current command. The results, if any, should be discarded.
and, when evil bots are hammering the site:
System.Data.SqlClient.SqlException: Resource ID : 1. The request limit for the database is 180 and has been reached. See 'http://go.microsoft.com/fwlink/?LinkId=267637' for assistance.
Each website can potentially have a Google footprint of around 10,000 pages. The result it that bots are hitting the sites regularly, indexing lots of pages for hundreds of sites. I also have some worker roles doing data work. The database is clearly busy!
I am hoping to add 2 or 3 times the number of sites that I currently have to the "engine".
I am looking at efficiency where possible, but the sites are clearly under a fair load from bots and visitors.
My question is, will one of the upgrades from Business to S2, P1, P2 or P3 resolve these problems? The financial cost of these database instances stagger greatly so I wouldn't want to update and find I'm left with the same problems but am paying many times
more each month.
Thank you in advance.Hello,
For Web/Business edition database, the maximum limit of concurrent requests is 180. Beyond this limit, you will receive error.
The Max woker threads for Standard(S2) is 100, you should upgrade your database to Permium tier.
The concurrent requests limit of premium database varies depending on the reservation size of a premium database. For example, for P1, the max worker threads is 200.
Reference:Azure SQL Database Resource Governance
Azure SQL Database Service Tiers and Performance Levels
Regards,
Fanny Liu
If you have any feedback on our support, please click here.
Fanny Liu
TechNet Community Support -
I have a web app that is backed by a an Azure SQL Database. The problem is that I had multiple issues when connecting to the database mainly when trying to establish a connection, or timeouts. This is the log I just encountered when trying to use the web
app.
[Win32Exception (0x80004005): The wait operation timed out]
[SqlException (0x80131904): Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=21970; handshake=1; ]
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +671
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1012
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6712291
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +152
System.Data.SqlClient.SqlConnection.Open() +229
System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +102Hi Affar2k,
According to your description, we need to verify if there is no network issue and the Sqlclient version is older than .NET 4.5. You can try to connect to the Windows Azure SQL database via SSMS and check if it can run well. When you
connect to the SQL Azure database via ADO.NET, you need to verify that the server name and passwords are right in the connection string.
For more information, you can review the following article about how to connect to Windows Azure SQL Database using ADO.NET.
http://msdn.microsoft.com/en-us/library/windowsazure/ee336243.aspx
Thanks,
Sofiya Li
Sofiya Li
TechNet Community Support -
Using the Unpivot Operator when in Oracle8i PL/SQL Generation Mode
Hi,
when you are validating a mapping with contains an unpivot operator and the PL/SQL Generation Mode is set to Oracle8i (because you're using an Oracle8i 8.1.7. target database) the following error is raised:
VLD-3127: Cannot generate code for UNPIVOT because the unpivot operator is only supported starting with the Oracle9i version of the database.","The unpivot operator is only supported starting with the Oracle9i version of the database. To resolve this, set the PL/SQL Generation Mode to Oracle9i in the configuration of the Oracle module that contains this mapping.
When you set the PL/SQL Generation Mode to Oracle9i and after successfully validating the mapping generate the code you can see that within the generated code case-statements are used for the unpivot translation.
like:
MIN(CASE WHEN "AGG_YEAR_MONTH" = 200301 THEN "NO_CALLS" ELSE NULL END) "JAN2003_CALLS"
And as Oracle8i doesn't support the case-statement, the raised validation error is understandable. But the generated code can be easily modified using decode-classes instead of the case-statements.
results in:
MIN(DECODE("AGG_YEAR_MONTH",''200301'',"NO_CALLS",NULL)) "JAN2003_CALLS"
And the generated code works fine in the Oracle8i 8.1.7 target database.
But now my question:
Does someone know if it is possible to create a custom unpivot operator in OWB9.2.0 which will generate the code using the decode-class instead of using the case-statements. And if so, how I can create such custom operator.
Many Thx in advantage!
RemcoHi,
The reason why OWB does not generate decode statements is that the generated code needs to support both set-based and row-based operation modes. Decodes are valid in SQL (set based), but not in PL/SQL (row based)
Oracle 8i (8.1.7) does in fact support CASE, but only in SQL statements, not PL/SQL
Have you considered creating a view to perform the unpivot operation using decode? It should also be possible solve your problem using a function
Regards,
Roald -
How do I incorporate the 'WHEN' operator in a SQL*Loader mapping?
Environment:
OWB 10g
Repository: 9.2.0.4
Target: 9.2.0.4
O/S: AIX 5.2
I have the need to incorporate the WHEN clause in a flat file mapping to eliminate some unneeded rows in the flat file.
I can't seem to find the configuration option or property setting or whatever it takes to get that done.
I thought it would be part of the FILTR operator but I kept getting an 'Invalid expression' error message.
In this case I want to ignore any rows that have a 'M', 'D' or 'S' in the first column.
Many thanks for all your help.
GaryJean-Pierre
Thanks very much for your quick response.
One last point and we should drop this in favor of other more urgent issues we both ahve to deal with.
The data is coming from a comma delimited (CSV) file using a comma ',' and optional quotes (") as field separators.
The first column of 'good' data is read as an INTEGER EXTERNAL because of course it is a number. However, the 'bad' rows I want to eliminate have character text in them where I would normally find numbers and they all start with 'D','M' or 'S'.
I don't have an actual column in the data file or resulting table definition that represents that first character that I'm trying to test on. Hence my use of (1) to reporesent the 1st character of data on the line regardless of whether its numeric or character.
As I stated, the syntax works fine in SQL*Loader when I typed the WHEN clause in manually.
I guess if there was a way to define a pseudo column that could be defined using the POSITION notation and everything else using the variable length delimited notation I could test on that psuedo column. I don't want the pseudo column to appear in my resulting table so that seems to be an issue. Enough.
Since I've worked around it using external tables for this issue I'm not going to spend any more time on it today.
As usual, many thanks for your help.
Have a great day! I'll be back soon with another issue :-)>
Gary -
Hi everyone,
I am trying to find a way to do minus operations on table. I know this is possible in SQL, but I have yet to find out how to do it in ABAP. Can anyone help?
What I need to do is the following.
Let table A = (A,B,C,D,E) and table B = (B,C,E), then A minus B would return (A,D). Is there a function in ABAP for this?
Thank you very much in advance.
Philip R. Jarnhushello,
u can use subqueries:
http://help.sap.com/saphelp_NW04/helpdata/en/dc/dc7614099b11d295320000e8353423/content.htm
it is easy, but wrong way to solve your problem. This select will make a lot of calls to your DB.
better way:
1) two selects from table 1 and table 2 into two different internal tables.
define two internal tables in your code. One table should have standard tables type and another hashed tables type with unique.
2) subtract the result:
loop at it_1 into ls_1.
lv_tabix = sy-tabix.
read table lt_1 transporting no fields with table key column_name = ls_1-column_name.
check sy-subrc eq 0.
delete it_1 index lv_tabix.
endloop.
this solution will speed up your application. -
MINUS operator fetches invalid record count
Hi,
One of the application team complained that oracle MINUS operator fetches an invalid record count after data load.
Here are the details of the data load:
They are using source as PROD and target as UAT.
They are replicating the data on UAT environment in schema A from fetching the data in PROD from the same schema.
After load when we query the count of records in UAT it shows more records in target, that is in UAT, than PROD.
When they use MINUS operator to fetch the extra records in UAT, it shows no rows selected.
SQL> select 'A' count(1) from A.UAT union all select 'A' count(1) from A.PROD@BISLSPD1;
A COUNT(1)
A.UAT 19105022
A.PROD 19104995
SQL> select distinct count(*) from (select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1);
COUNT(*)
0
SQL> select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1
no rows selected
Please note that both are partitioned tables and they are using Informatica Data Replication 9.5 tool to populate the data from source to target.
Not sure if this could be a bug or an issue.
PROD DB Version: 10.2.0.5
UAT DB Version: 10.2.0.5
Both are in Linux 2.6
Please throw some light on this.974065 wrote:
SQL> select 'A' count(1) from A.UAT union all select 'A' count(1) from A.PROD@BISLSPD1;
A COUNT(1)
A.UAT 19105022
A.PROD 19104995
SQL> select distinct count(*) from (select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1);
COUNT(*)
0
SQL> select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1
no rows selected
Given that you've go "distinct" in your query, you're eliminating duplicates from each table (and MINUS implicitly means distinct anyway). Check for duplicates (of dw_discount_key, dw_discount_modifier_key) in both tables.
If the combination is actually unique, I would check that you actually had the raw results the right way round - MINUS is not symmetrical, and for a complete picture you need to look at (select from uat minus select from prod) union all (select from prod minus select from uat)
Regards
Jonathan Lewis -
Instead of Minus operation any other ?
Hi,
Master Table : book_master
Master_Pk_No Book_Name Version_no I_User Initial_id
10 Book1 0 XXX 10
20 Book1 1 XXX 10
30 Book1 2 XXX 10
# Initial id will be same as Master_Pk_No first number
# I have to take the latest version ( 2 ) and compare with the older version if any records
are availble in older version i have to fetch that and append that with the
Child Table : source
C_PK_NO SEQ_SOURCE UNIT_SEQ O_User
10 1 1 XXX
10 2 1 abc
10 3 2 abc
10 4 1 ggg
10 5 2 ggg
10 6 3 abc
10 7 4 abc
20 1 1 XXX
20 2 1 abc
20 3 2 abc
20 4 1 ggg
20 5 2 ggg
20 6 1 zzz
30 1 1 XXX
30 2 1 abc
30 3 2 abc
30 4 1 ggg
30 5 2 ggg
30 6 2 XXX
SELECT seq_source, o_user, unit_seq
FROM SOURCE
WHERE c_pk_no IN ( SELECT master_pk_no FROM AER
WHERE book_name = 'Book1'
AND version_no = 0 )
MINUS
SELECT seq_source, o_user, unit_seq
FROM SOURCE
WHERE c_pk_no IN ( SELECT master_pk_no FROM AER
WHERE book_name = 'Book1'
AND version_no = 2) ;
If i execute this query i will get the below result .
C_PK_NO SEQ_SOURCE UNIT_SEQ O_User
10 6 3 abc
10 7 4 abc
SELECT seq_source, o_user, unit_seq
FROM SOURCE
WHERE c_pk_no IN ( SELECT master_pk_no FROM AER
WHERE book_name = 'Book1'
AND version_no = 1 )
MINUS
SELECT seq_source, o_user, unit_seq
FROM SOURCE
WHERE c_pk_no IN ( SELECT master_pk_no FROM AER
WHERE book_name = 'Book1'
AND version_no = 2) ;
C_PK_NO SEQ_SOURCE UNIT_SEQ O_User
20 6 1 zzz
is it possible to achieve this without minus operation ?
Regards,
KBG.And here is the test:
SQL> WITH BOOK_MASTER AS(
2 SELECT 10 master_pk_no,'Book1' book_name,0 version_no,'XXX' i_user,10 Initial_id from dual union all
3 SELECT 20,'Book1',1,'XXX',10 from dual union all
4 SELECT 30,'Book1',2,'XXX',10 from dual
5 ),
6 SOURCE AS (
7 SELECT 10 c_pk_no,1 seq_source,1 unit_seq,'XXX' o_user from dual union all
8 SELECT 10,2,1,'abc' from dual union all
9 SELECT 10,3,2,'abc' from dual union all
10 SELECT 10,4,1,'ggg' from dual union all
11 SELECT 10,5,2,'ggg' from dual union all
12 SELECT 10,6,3,'abc' from dual union all
13 SELECT 10,7,4,'abc' from dual union all
14 SELECT 20,1,1,'XXX' from dual union all
15 SELECT 20,2,1,'abc' from dual union all
16 SELECT 20,3,2,'abc' from dual union all
17 SELECT 20,4,1,'ggg' from dual union all
18 SELECT 20,5,2,'ggg' from dual union all
19 SELECT 20,6,1,'zzz' from dual union all
20 SELECT 30,1,1,'XXX' from dual union all
21 SELECT 30,2,1,'abc' from dual union all
22 SELECT 30,3,2,'abc' from dual union all
23 SELECT 30,4,1,'ggg' from dual union all
24 SELECT 30,5,2,'ggg' from dual union all
25 SELECT 30,6,2,'XXX' from dual
26 )
27 SELECT s.seq_source,
28 s.o_user,
29 s.unit_seq
30 FROM SOURCE s,
31 BOOK_MASTER a
32 WHERE s.c_pk_no = a.master_pk_no
33 AND a.book_name = 'Book1'
34 AND a.version_no IN (0,2)
35 GROUP BY s.seq_source,
36 s.o_user,
37 s.unit_seq
38 HAVING MAX(a.version_no) = 0
39 /
SEQ_SOURCE O_U UNIT_SEQ
6 abc 3
7 abc 4
SQL> WITH BOOK_MASTER AS(
2 SELECT 10 master_pk_no,'Book1' book_name,0 version_no,'XXX' i_user,10 Initial_id from dual union all
3 SELECT 20,'Book1',1,'XXX',10 from dual union all
4 SELECT 30,'Book1',2,'XXX',10 from dual
5 ),
6 SOURCE AS (
7 SELECT 10 c_pk_no,1 seq_source,1 unit_seq,'XXX' o_user from dual union all
8 SELECT 10,2,1,'abc' from dual union all
9 SELECT 10,3,2,'abc' from dual union all
10 SELECT 10,4,1,'ggg' from dual union all
11 SELECT 10,5,2,'ggg' from dual union all
12 SELECT 10,6,3,'abc' from dual union all
13 SELECT 10,7,4,'abc' from dual union all
14 SELECT 20,1,1,'XXX' from dual union all
15 SELECT 20,2,1,'abc' from dual union all
16 SELECT 20,3,2,'abc' from dual union all
17 SELECT 20,4,1,'ggg' from dual union all
18 SELECT 20,5,2,'ggg' from dual union all
19 SELECT 20,6,1,'zzz' from dual union all
20 SELECT 30,1,1,'XXX' from dual union all
21 SELECT 30,2,1,'abc' from dual union all
22 SELECT 30,3,2,'abc' from dual union all
23 SELECT 30,4,1,'ggg' from dual union all
24 SELECT 30,5,2,'ggg' from dual union all
25 SELECT 30,6,2,'XXX' from dual
26 )
27 SELECT s.seq_source,
28 s.o_user,
29 s.unit_seq
30 FROM SOURCE s,
31 BOOK_MASTER a
32 WHERE s.c_pk_no = a.master_pk_no
33 AND a.book_name = 'Book1'
34 AND a.version_no IN (1,2)
35 GROUP BY s.seq_source,
36 s.o_user,
37 s.unit_seq
38 HAVING MAX(a.version_no) = 1
39 /
SEQ_SOURCE O_U UNIT_SEQ
6 zzz 1
SQL> SY.
Maybe you are looking for
-
Customer balance report - S_ALR_87012172
Hi sap gurus, I searched forum but I couldn't get enough knowledge. how does S_ALR_87012172 calculate customer's balance value? based on posting date, clearing date, document date or other date? I'm checking with fbl5n but balances are different.as I
-
Error sqlldr with plink in remote command
Hi all, My OS is Windows, I tried to launch a sqlldr remote command with plink (putty) : Command dos: "plink host -l oracle -pw oracle sqlldr -userid schema/pwd -control /tmp/test.ctl" I had this error : "ksh: sqlldr: not found" Setting of server : $
-
Farcical interactions between reader & acrobat for wet signatures
Apologies for the flamebait style subject, but im incredibly frustrated with adobe's products. I have a PDF which requires a signature, it is a secure PDF, but permissions allow for signatures (in this case opting for 'wet' from an image). If I open
-
Airport Express working, PC connects to network but cannot use internet
I set up my Airport Express wireless network, and all is functioning. My IMac recognizes and uses the network. My PC laptop recognizes the network (excellent signal) and "connects" or indicates that it is connected, but I cannot access the internet.
-
How to total all inputs after looping?
Hello, new user here. I've just started doing loops, but am have a little problem that I hope you can help me with. I want to loop a program to input the commission figures for ten people, then calculate and output the total commission overall, as we