Where Not
These both not returning same number, am i missing anything, I would like change the first query to write in other format, because i have lot of and conditions like this. I have given only one as example.
-- Original query ; working
SELECT COUNT(*) FROM P
INNER JOIN R WITH ( NOLOCK )
ON R.Id = P.Id
where P.Pk NOT IN (
SELECT p.Pk
WHERE R.Name = 'S'
AND p.Type = 'O' )
and R.Date = '7/16/2014'
-- Test query ; not returning same rows as above
SELECT COUNT(*) FROM P
INNER JOIN R WITH ( NOLOCK ) ON R.Id = P.Id
where NOT (R.Name = 'S' AND p.Type = 'O')
and R.Date = '7/16/2014'
Those two statements will not return the same result if either R.Name or P.Type is NULL and R.Date = '7/16/2014'
To see why that is true, consider the case where R.Name is NULL and P.Type = 'O'.
The first query's inner select is Select p.Pk WHERE R.Name = 'S' AND p.Type = 'O'. That will return zero rows because R.Name is NULL. So the NOT IN will be TRUE and since the R.Date condition is TRUE so the entire where is true and that row is
counted.
In the second case, you check if R.Name = 'S'. Since R.Name is NULL, the result of that logical comparison is UNKNOWN (that is, neither true nor false). You then AND that with p.Type = 'O' which is TRUE. So you get UNKNOWN AND TRUE - the
result of that is UNKNOWN. You then do a NOT of that UNKNOWN values which is still UNKNOWN. You then and that with R.Date = '7/16/2014', so the final result of your where condition is UNKNOWN. So this row is not counted.
So the first and second queries can return different results.
I gather from your question that you want a query using the form of the second query that will return the same result as the first query. To do that you have to handle the NULL's. One way would be to do
SELECT COUNT(*) FROM P
INNER JOIN R ON R.Id = P.Id
where Not (IsNull(R.Name, 'S') <> 'S' And IsNull(p.Type, 'O') <> 'O')
and R.Date = '7/16/2014'
Tom
Similar Messages
-
Using WHERE NOT EXISTS for a Fact Table Load
I'm trying to set up a fact table load using T SQL, and I need to use WHERE NOT EXISTS. All of the fields from the fact table are listed in the WHERE NOT EXISTS clause. What I expect is that if the value of any one of the fields is different, that the whole
record be treated as a new record, and inserted into the table. However, in my testing, when I 'force' a field value, new records are not inserted.
The following is my query:
declare
@Created_By nchar(50)
,@Created_Date datetime --do we need utc check?
,@Updated_By nchar(50)
,@Updated_Date datetime
select @Created_By = system_user
,@Created_Date = getdate()
,@Updated_By = system_user
,@Updated_Date = getdate()
insert fact.Appointment
Slot_ID
, Slot_DateTime
, Slot_StartDateTime
, Slot_EndDateTime
, Slot_Duration_min
, Slot_CreateDateTime
, Slot_CreateDate_DateKey
, Healthcare_System_ID
, Healthcare_Service_ID
, Healthcare_Supervising_Service_ID
, Healthcare_Site_ID
, Booked_Appt_ID
, Appt_Notification_Submission_DateKey
, Appt_Notification_Completion_DateKey
, Appt_Notification_Duration
, Appt_Notification_ID
, Patient_ID
, Physician_ID
, Referral_ID
, Specialty
, LanguageRequested
, Created_Date
, Created_By
, Updated_Date
, Updated_By
select distinct
Slot.Slot_ID
, Slot.Slot_Start_DateTime as Slot_DateTime --???
, Slot.Slot_Start_DateTime
, Slot.Slot_End_DateTime
, datediff(mi,slot.Slot_Start_DateTime,slot.Slot_End_Datetime) as Slot_Duration_Min
, Slot.Created_Date as Slot_CreateDateTime
, SlotCreateDate.Date_key as Slot_CreateDate_DateKey
, HSite.Healthcare_System_ID
, HSite.Healthcare_Service_ID
, HSite.Healthcare_Service_ID as Healthcare_Supervising_Service_ID
, HSite.Healthcare_Site_ID
, Ref.Booked_Appt_ID
, ApptSubmissionTime.Date_key as Appt_Notification_Submission_DateKey
, ApptCompletionTime.Date_key as Appt_Notification_Completion_DateKey
, datediff(mi,appt.SubmissionTime,appt.CompletionTime) as Appt_Notification_Duration
, Appt.Appt_Notification_ID
, pat.Patient_ID
, 0 as Physician_ID
, ref.Referral_ID
, Hsrv.Specialty
, appt.[Language] as LanguageRequested
,@Created_Date as Created_Date
,@Created_By as Created_By
,@Updated_Date as Updated_Date
,@Updated_By as Updated_By
from dim.Healthcare_System HSys
inner join dim.Healthcare_Service HSrv
on HSys.Healthcare_System_ID = HSrv.HealthCare_System_ID
inner join dim.Healthcare_Site HSite
on HSite.HealthCare_Service_ID = HSrv.Healthcare_Service_ID
and HSite.HealthCare_System_ID = HSrv.HealthCare_System_ID
inner join dim.Referral Ref
on Ref.ReferralSite_ID = HSite.Site_ID
and Ref.ReferralService_ID = HSite.Service_ID
and Ref.ReferralSystem_ID = HSite.System_ID
right join (select distinct Slot_ID, Source_Slot_ID, Slot_Start_DateTime, Slot_End_DateTime, Created_Date from dim.slot)slot
on ref.Source_Slot_ID = slot.Source_Slot_ID
inner join dim.Appointment_Notification appt
on appt.System_ID = HSys.System_ID
inner join dim.Patient pat
on pat.Source_Patient_ID = appt.Source_Patient_ID
inner join dim.SystemUser SysUser
on SysUser.Healthcare_System_ID = HSys.Healthcare_System_ID
left join dim.Calendar SlotCreateDate
on SlotCreateDate.Full_DateTime = cast(Slot.Created_Date as smalldatetime)
left join dim.Calendar ApptSubmissionTime
on ApptSubmissionTime.Full_DateTime = cast(appt.SubmissionTime as smalldatetime)
left join dim.Calendar ApptCompletionTime
on ApptCompletionTime.Full_DateTime = cast(appt.CompletionTime as smalldatetime)
where not exists
select
Slot_ID
, Slot_DateTime
, Slot_StartDateTime
, Slot_EndDateTime
, Slot_Duration_min
, Slot_CreateDateTime
, Slot_CreateDate_DateKey
, Healthcare_System_ID
, Healthcare_Service_ID
, Healthcare_Supervising_Service_ID
, Healthcare_Site_ID
, Booked_Appt_ID
, Appt_Notification_Submission_DateKey
, Appt_Notification_Completion_DateKey
, Appt_Notification_Duration
, Appt_Notification_ID
, Patient_ID
, Physician_ID
, Referral_ID
, Specialty
, LanguageRequested
, Created_Date
, Created_By
, Updated_Date
, Updated_By
from fact.Appointment
I don't have any issues with the initial insert, but records are not inserted on subsequent inserts when one of the WHERE NOT EXISTS field values changes.
What am I doing wrong?
Thank you for your help.
cdun2so I set up a WHERE NOT EXIST condition as shown below. I ran the query, then updated Slot_Duration_Min to 5. Some of the Slot_Duration_Min values resolve to 15. What I expect is that when I run the query again, that the records where Slot_Duration_Min resolves
to 15 should be inserted again, but they are not. I am using or with the conditions in the WHERE clause because if any one of the values is different, then a new record needs to be inserted:
declare
@Created_By nchar(50)
,@Created_Date datetime
,@Updated_By nchar(50)
,@Updated_Date datetime
select
@Created_By = system_user
,@Created_Date = getdate()
,@Updated_By = system_user
,@Updated_Date = getdate()
insert fact.Appointment
Slot_ID
, Slot_DateTime
, Slot_StartDateTime
, Slot_EndDateTime
, Slot_Duration_min
, Slot_CreateDateTime
, Slot_CreateDate_DateKey
, Healthcare_System_ID
, Healthcare_Service_ID
, Healthcare_Supervising_Service_ID
, Healthcare_Site_ID
, Booked_Appt_ID
, Appt_Notification_Submission_DateKey
, Appt_Notification_Completion_DateKey
, Appt_Notification_Duration
, Appt_Notification_ID
, Patient_ID
, Physician_ID
, Referral_ID
, Specialty
, LanguageRequested
, Created_Date
, Created_By
, Updated_Date
, Updated_By
select distinct
Slot.Slot_ID
, Slot.Slot_Start_DateTime as Slot_DateTime --???
, Slot.Slot_Start_DateTime
, Slot.Slot_End_DateTime
, datediff(mi,slot.Slot_Start_DateTime,slot.Slot_End_Datetime) as Slot_Duration_Min
, Slot.Created_Date as Slot_CreateDateTime
, SlotCreateDate.Date_key as Slot_CreateDate_DateKey
, HSite.Healthcare_System_ID
, HSite.Healthcare_Service_ID
, HSite.Healthcare_Service_ID as Healthcare_Supervising_Service_ID
, HSite.Healthcare_Site_ID
, Ref.Booked_Appt_ID
, ApptSubmissionTime.Date_key as Appt_Notification_Submission_DateKey
, ApptCompletionTime.Date_key as Appt_Notification_Completion_DateKey
, datediff(mi,appt.SubmissionTime,appt.CompletionTime) as Appt_Notification_Duration
, Appt.Appt_Notification_ID
, pat.Patient_ID
, 0 as Physician_ID
, ref.Referral_ID
, Hsrv.Specialty
, appt.[Language] as LanguageRequested
,@Created_Date as Created_Date
,@Created_By as Created_By
,@Updated_Date as Updated_Date
,@Updated_By as Updated_By
from dim.Healthcare_System HSys
inner join dim.Healthcare_Service HSrv
on HSys.Healthcare_System_ID = HSrv.HealthCare_System_ID
inner join dim.Healthcare_Site HSite
on HSite.HealthCare_Service_ID = HSrv.Healthcare_Service_ID
and HSite.HealthCare_System_ID = HSrv.HealthCare_System_ID
inner join dim.Referral Ref
on Ref.ReferralSite_ID = HSite.Site_ID
and Ref.ReferralService_ID = HSite.Service_ID
and Ref.ReferralSystem_ID = HSite.System_ID
right join (select distinct Slot_ID, Source_Slot_ID, Slot_Start_DateTime, Slot_End_DateTime, Created_Date from dim.slot)slot
on ref.Source_Slot_ID = slot.Source_Slot_ID
inner join dim.Appointment_Notification appt
on appt.System_ID = HSys.System_ID
inner join dim.Patient pat
on pat.Source_Patient_ID = appt.Source_Patient_ID
inner join dim.SystemUser SysUser
on SysUser.Healthcare_System_ID = HSys.Healthcare_System_ID
left join dim.Calendar SlotCreateDate
on SlotCreateDate.Full_DateTime = cast(Slot.Created_Date as smalldatetime)
left join dim.Calendar ApptSubmissionTime
on ApptSubmissionTime.Full_DateTime = cast(appt.SubmissionTime as smalldatetime)
left join dim.Calendar ApptCompletionTime
on ApptCompletionTime.Full_DateTime = cast(appt.CompletionTime as smalldatetime)
where not exists
select
Slot_ID
, Slot_DateTime
, Slot_StartDateTime
, Slot_EndDateTime
, Slot_Duration_min
, Slot_CreateDateTime
, Slot_CreateDate_DateKey
, Healthcare_System_ID
, Healthcare_Service_ID
, Healthcare_Supervising_Service_ID
, Healthcare_Site_ID
, Booked_Appt_ID
, Appt_Notification_Submission_DateKey
, Appt_Notification_Completion_DateKey
, Appt_Notification_Duration
, Appt_Notification_ID
, Patient_ID
, Physician_ID
, Referral_ID
, Specialty
, LanguageRequested
, Created_Date
, Created_By
, Updated_Date
, Updated_By
from fact.Appointment fact
where
Slot.Slot_ID = fact.Slot_ID
or
Slot.Slot_Start_DateTime = fact.Slot_DateTime
or
Slot.Slot_Start_DateTime = fact.Slot_StartDateTime
or
Slot.Slot_End_DateTime = fact.Slot_EndDateTime
or
datediff(mi,slot.Slot_Start_DateTime,slot.Slot_End_Datetime) =
fact.Slot_Duration_min
or
Slot.Created_Date = fact.Slot_CreateDateTime
or
SlotCreateDate.Date_key = fact.Slot_CreateDate_DateKey
or
HSite.Healthcare_System_ID = fact.Healthcare_System_ID
or
HSite.Healthcare_Service_ID = fact.Healthcare_Service_ID
or
HSite.Healthcare_Service_ID =
fact.Healthcare_Service_ID
or
HSite.Healthcare_Site_ID = fact.Healthcare_Site_ID
or
Ref.Booked_Appt_ID = fact.Booked_Appt_ID
or
ApptSubmissionTime.Date_key =
fact.Appt_Notification_Submission_DateKey
or
ApptCompletionTime.Date_key =
fact.Appt_Notification_Completion_DateKey
or
datediff(mi,appt.SubmissionTime,appt.CompletionTime) = fact.Appt_Notification_Duration
or
Appt.Appt_Notification_ID = fact.Appt_Notification_ID
or
pat.Patient_ID =
fact.Patient_ID
or
0 = 0
or
ref.Referral_ID = fact.Referral_ID
or
Hsrv.Specialty = fact.Specialty
or
appt.[Language] = fact.LanguageRequested -
Wrong query is getting generated in WHERE NOT EXISTS with group by clause
Query is getting generated wrongly in where not exists section when i use group by function.Please prvoide me any clue to over come the problem.
/* DETECTION_STRATEGY = NOT_EXISTS */
INSERT /*+ APPEND */ INTO STG_ETL.I$_DCMT_TIMEZONE_LOOKUP
TZ_OFFSET,
ADT_CRT_DT,
ADT_UPDT_DT,
IND_UPDATE
SELECT * FROM (
SELECT
to_number(KOFAX.RECEIVED_TZ) TZ_OFFSET,
min(sysdate) ADT_CRT_DT,
min(sysdate) ADT_UPDT_DT,
'I' IND_UPDATE
FROM ESTG.FLAT_FIL_DMS_KOFAX KOFAX
WHERE (1=1)
And (KOFAX.LD_DT = ( select MAX(LD_DT) from ESTG.FLAT_FIL_DMS_KOFAX INNER
where INNER.ENGAGEMENT=KOFAX.ENGAGEMENT
and INNER.KOFAX_FILE_NM = KOFAX.KOFAX_FILE_NM
AND INNER.IM_CUST_ID = KOFAX.IM_CUST_ID
and INNER.BATCH_ID=KOFAX.BATCH_ID)
AND
(TO_DATE(KOFAX.LD_DT)>=TO_DATE(SUBSTR('#WAREHOUSE.P_EDW_LAST_RUN',1,10),'YYYY-MM-DD'))
And (substr(KOFAX.RECEIVED_TZ,1,1) <> '+')
Group By to_number(KOFAX.RECEIVED_TZ)
) S
WHERE NOT EXISTS (
SELECT 'X'
FROM EDW.DCMT_TIMEZONE_LOOKUP T
WHERE T.TZ_OFFSET = S.TZ_OFFSET AND
)Easiest fix for you would be to change the detection_strategy on the IKM from NOT_EXISTS to either :
MINUS
-- Try this out, it should work, it will give the same data through the equiverlant steps.
NONE
-- This will load all incoming data into your I$ table, there will be more rows to crunch in the following 'Flag Rows for Update' step, it might give incorrect results potentially - you will have to test it.
So try MINUS first, failing that, see if NONE gives you what you want in your target.
Are you inserting only new data or updating existing data? -
HOW TO SELECT ONLY THOSE RECORDS WHERE NOT AVAILABLE ON SECOND TABLE
hi
i have two tables one name is menus and second name is UGroupDetail. Actually i have created it for user role privileges for my application
USE [LedgerDB]
GO
/****** Object: Table [dbo].[Menus] Script Date: 03/28/2015 13:45:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Menus](
[RightID] [int] NOT NULL,
[RightName] [nvarchar](200) NULL,
[GroupID] [int] NULL,
CONSTRAINT [PK_Menus] PRIMARY KEY CLUSTERED
[RightID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
second table is
USE [LedgerDB]
GO
/****** Object: Table [dbo].[UGroupDetail] Script Date: 03/28/2015 13:46:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UGroupDetail](
[RightID] [int] NOT NULL,
[RightName] [nvarchar](200) NULL,
[GroupID] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[UGroupDetail] WITH CHECK ADD CONSTRAINT [FK_UGroupDetail_Menus] FOREIGN KEY([RightID])
REFERENCES [dbo].[Menus] ([RightID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[UGroupDetail] CHECK CONSTRAINT [FK_UGroupDetail_Menus]
GO
ALTER TABLE [dbo].[UGroupDetail] WITH CHECK ADD CONSTRAINT [FK_UGroupDetail_UserGroup] FOREIGN KEY([GroupID])
REFERENCES [dbo].[UserGroup] ([GroupID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[UGroupDetail] CHECK CONSTRAINT [FK_UGroupDetail_UserGroup]
UGroupDetail have many groups as assigned to a new user but Menus table has only default groups which is 90 records
Menus table is a primary table and UGroupDetail is a Foreign key table
now i want to combined these tables and want to get only remaining records for each group
for example i have assigned 5 roles to GroupID 2 and now when i apply select commands the result should be 85 out 90 for GroupID 2
but i have not idea how to modify select query for get desired resultI don't really understand the tables. What is GroupID doing in the Menues table? And what does an entry without a RightName mean? Shouldn't that column be NOT NULL?
The UGroupDetail does not have any primary key. From your description, I would expect the PK to be (RightID, GroupID). But strangely enough, GroupID is nullable. So is RightName, but I think this column is redundant and should be removed.
Anyway, if I understand your question correctly, you need something like:
SELECT UG.Name, M.RightName
FROM UserGroups UG
CROSS JOIN Menus M
WHERE NOT EXISTS (SELECT *
FROM UGroupDetail UGD
WHERE UG.GroupID = UGD.GroupID
AND UG.RightID = M.RightID)
Erland Sommarskog, SQL Server MVP, [email protected] -
why can't i access my itunes anymore? whenever i click on it, it makes my laptop freeze/slow down to the point where not even ctrl alt delete works properly and i have to turn the laptop off and then back on to get anything done. it has been this way for the last 2/3 days now and i have uninstalled and reinstalled it but it doesnt work
Hello there, bobbiefromIRL.
The following Knowledge Base article goes over some great steps for troubleshooting your issue:
iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues
http://support.apple.com/kb/ts1717
Thanks for reaching out to Apple Support Communities.
Cheers,
Pedro. -
How to tell what methods where not used in the code?
Hi there,
I wonder if there's a way to check what method are not used in the execution code (void main).
Example:
in the code below, the following method where not used:
setAge, getAge, getName,setName, addFeedback
public class Test
public static void main(String args[])
Employee empl = new Employee("John", 54);
System.out.println(empl.getDeatils());
public class Employee
private int age;
private String name;
public Employee(String name, int age)
this.name=name;
this.age=age;
public String getDeatils()
return name+" ("+age+")";
public void addFeedback()
//do something here.
public int getAge()
return age;
public void setAge(int age)
this.age = age;
public String getName()
return name;
public void setName(String name)
this.name = name;
}Yucca wrote:
georgemc wrote:
Yucca wrote:
Sound like you should visit the logging API or you could do SOP all over your code which would make it very unreadableI don't see why logging code will make his code any less messy than SOP everywhere. Unless you're talking about applying logging by AOP, which is equally messy in a different way.I never implied that the one was tidier than the other. O merely recommended my knowledge on how to help the OP and gave 2 choices. Oh right. It looked like you were suggesting SOP was messier somehow. Never mind, then.
Besides is AOP really that bad when using Interceptors? I know that this is new to Java but interceptors are really not that untidy.I didn't say they were untidy. I didn't say there was anything wrong with AOP. But logging by AOP results in pretty useless, messy logs. "This method was called with these parameters" all over the place, rather than something nice and friendly. Remember, logging is more often read by support staff than developers, so while it might be obvious to you what "getLlama(200, 3)" means, it's probably garbage to the support bods. -
Select last occorence for each field of view where not there a timestamp
I have a view TEST with the following field Field1 , Field2, Field3, ....
Sample TEST
Field1 .................Field2
1 ...................... Rep7
2 ...................... Rep5
3 ...................... Rep4
1 ...................... Rep1
2 ...................... Rep3
3 ...................... Rep6
I want create a select that give the following result take a distinct field1 with the last occorence of field2
For each field1 I want take the last field2
sample of above the result is
Field1..................Field2
1 ...................... Rep1
2 ...................... Rep3
3 ...................... Rep6
Edited by: user9011634 on 19-gen-2010 16.55Well, as i told you before, UNLESS the view has an order by statement in it you're out of luck.
You will NOT get consistently ordered results UNLESS you have an order by statement.
So you can try the code posted for you before, and it may work 90+ percent of the time, but i don't know many places where 90% consistency is good enough.
*note, 90% is an arbitrary number, i can only tell you that it will not be 100% (and that's typically the required correctness rate any shop i've ever worked in). -
SQL command IN is working whereas NOT IN not working
In application code I have the below code.
IF v_service_variant NOT IN(0,1,2,3,4) THEN --Checking whether existing service variant is applicable in 21Cn Fibre.
v_service_variant := 3; --If not making it as a standard service
UPDATE sspt_sessions_table SET service_variant = v_service_variant WHERE sess_id=v_sess_id; --Updating sspt_sessions_table
SELECT DECODE(service_variant_id, 0, 'None', 1, 'Loadbalancing', 2, 'Failover',3, 'BGP4', 4, 'Backup') INTO l_service_variant --To get the service variant name
FROM sspt_maj_resilience WHERE service_variant_id=v_service_variant;
UPDATE sspt_prquote_details SET service_variant = l_service_variant WHERE ftip=l_ftip AND sess_id=v_sess_id; --Updating sspt_prquote_details
COMMIT;
END IF;
Then the statements inside the if condition are not being executed. At the same time if I am replacing NOT IN with IN only and making changes to get if condition true then it is going inside the IF condition.... Could anyone please help me on thisHi,
Does this happen when using SQL*Developer or if you run the SQL in SQLPLUS ?
If it is when running in SQLPLUS then it woul dbe better to raise it in the SQL Forum -
Forum: SQL and PL/SQL
PL/SQL
This forum is for problems using SQL*Developer.
Regards,
Mike -
Select with Where not in (subSelect)
Hi,
Is there any special about that 'not' in this ORacle sql (10g) that it doesn't return me any rows, unlike SQLServer with same code:
select count(*) from t1_ups where id_ups not in (select b.id_ups from t1_dups b)
COUNT(*)
0
vs.
select count(*) from t1_ups where id_ups not in ('abc', 'def','xyz') --select b.id_ups from t1_dups b)
COUNT(*)
16
DDL:
"id_ups" VARCHAR2(20 BYTE), is the same for both tables.I see that if remove <not> it works fine. is there any OR --> AND converssion happaned with negation?
My global task is to make UNION "with replacement" when if any records exist in id_dups they will replace ones from id_ups, so I try to do it in separate parts.
Thanks
Tr
Edited by: trento on Nov 16, 2010 3:00 PMtrento wrote:
Hi,
Is there any special about that 'not' in Yes, you need to be aware how the syntax reacts to NULL values.
create table in_or_not
col1 number
TUBBY_TUBBZ?insert into in_or_not values (2);
1 row created.
Elapsed: 00:00:00.05
TUBBY_TUBBZ?select 1 from dual where 1 not in (select col1 from in_or_not);
1
1
1 row selected.
Elapsed: 00:00:00.00
TUBBY_TUBBZ?insert into in_or_not values (NULL);
1 row created.
Elapsed: 00:00:00.00
TUBBY_TUBBZ?select 1 from dual where 1 not in (select col1 from in_or_not);
no rows selected
Elapsed: 00:00:00.01http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:442029737684 -
can anybody send me example of NOT IN with loop at itab where filed not in (a, ,b, c )
when i use brackets becomes red..i dont know whyCode like the way below;
data: st_tab type table of selopt with header line.
st_tab-sign = 'I'.
st_tab-option = 'EQ'.
st_tab-low = 'A'.
append st_tab. clear st_tab.
st_tab-sign = 'I'.
st_tab-option = 'EQ'.
st_tab-low = 'B'.
append st_tab. clear st_tab.
st_tab-sign = 'I'.
st_tab-option = 'EQ'.
st_tab-low = 'C'.
append st_tab. clear st_tab.
loop at itab not in st_tab.
endloop. -
Collection in where not working
Hi guys,
I haven't manage to figure out why this code does not work... maybe I'm missing something and I do not see it
declare
type tn is table of number;
--n tn; -- not good => pls 00642 local type collection
n ar_utl2.table_of_number_type; -- type table_of_number_type is table of number;
begin
select * bulk collect into n from (
select 1144 nr from dual
union
select 1004 nr from dual
for i in (
--select * from ar_intermediaries where intermediary_id member of n --ora 21700 object does not exist
--select * from ar_intermediaries where intermediary_id in (select t.column_value from table(cast(n as ar_utl2.table_of_number_type))t) --invalid datatype ar_utl2.table_of_number_type
select * from ar_intermediaries where intermediary_id in (select t.column_value from table(n)t) --ora 21700 object does not exist
) loop
dbms_output.put_line('got it');
end loop;
end;Can you help please?
BR, Florin POPn tn; not good => pls 00642 local type collectionYou need to create a schema level array to use it in SQL.
create type numbers_ntt is table of number;
select * from ar_intermediaries where intermediary_id member of n ora 21700 object does not exist
select * from ar_intermediaries where intermediary_id in (select t.column_value from table(cast(n as ar_utl2.table_of_number_type))t) invalid datatype >ar_utl2.table_of_number_type
select * from ar_intermediaries where intermediary_id in (select t.column_value from table(n)t) --ora 21700 object does not existYou can use this:
where t.nr in (select column_value
from table(numbers_nt)); or this
from t,
table(numbers_nt) nt
where t.nr = nt.column_value;------
Demo setup
create type numbers_ntt is table of number;
create table t (nr integer);
insert into t values (1144);
insert into t values (1004);
create procedure print(numbers_in in numbers_ntt,
array_name_in in varchar2 default 'The array') is
begin
dbms_output.put_line(array_name_in || ' - contains ' || numbers_in.count ||
' values:');
--There are no gaps with bulk_collect array, because SQL engine inserts elements consecutively ,it starts with 1
-- and substitutes the old elements
for i in numbers_in.first .. numbers_in.last
loop
dbms_output.put_line(numbers_in(i));
end loop;
dbms_output.new_line;
end print;Another example:
declare
numbers_nt numbers_ntt; -- schema-level type
numbers2_nt numbers_ntt; -- schema-level type
begin
select * bulk collect
into numbers_nt
from t;
print(numbers_nt, 'numbers_nt');
numbers_nt(2) := 1000;
print(numbers_nt, 'numbers_nt');
select t.nr bulk collect
into numbers2_nt
from t
where t.nr in (select column_value
from table(numbers_nt));
print(numbers2_nt, 'numbers2_nt');
numbers_nt.extend;
numbers_nt(numbers_nt.last) := 1004;
print(numbers_nt, 'numbers_nt');
-- with join
select t.nr bulk collect
into numbers2_nt
from t,
table(numbers_nt) nt
where t.nr = nt.column_value;
print(numbers2_nt, 'numbers2_nt');
end;The output:
numbers_nt - contains 2 values:
1144
1004
numbers_nt - contains 2 values:
1144
1000
numbers2_nt - contains 1 values:
1144
numbers_nt - contains 3 values:
1144
1000
1004
numbers2_nt - contains 2 values:
1144
1004 -
Drag-n-n-drop query joins uses WHERE, not INNER JOIN syntax
When I highlight a few tables and drag them onto the sql worksheet, it will build a select statement for me and join the tables by their foreign keys.
That's a nice feature, thanks!
Three questions. Is it possible to:
1. get it to use the INNER JOIN and LEFT OUTER JOIN syntax instead of joining the tables in the WHERE clause?
2. control the table aliases so that it will automatically use the "standard alias" for the table instead of A, B, C, etc.?
3. get it to not put the schema name into the query?
Thanks!
Edited by: David Wendelken on Nov 22, 2008 1:48 PM. Grammar mistake.Hi Gopi,
Your code is Good.
But try to avoid Inner join with more number of Tables ...because this is a performance issue..
try to use..
select (primary key fields mainly,other fields) from LIKP into itab where bolnr in p_bolnr(paramater).
next try to use for all entries option..
select (primary key fields mainly,other fields) from VBFA for all entries in itab where (give the condition)....
simillarly do for the other select ....ok this will try to reduce the performance issue....
<b><REMOVED BY MODERATOR></b>
Message was edited by:
Alvaro Tejada Galindo -
Brain Bender - select where not data
Hi Gurus'
I have an problem that is doing my head in, just cant get the data set back that I want.
I have two tables (more than that really, these are the last two of 6 related tables) 'mitigation' and mitigation_tracking" which have a one to many relation ship.
The primary and foreign keys relationships are shown at the bottom of the post.
In my example the mitigation table (pkey MIT_ID) has 8 records and I want to return the 8 records except if the user (mit_userid) has already submitted an entry into the tracking table.
With a right outer join using MIT_ID mitigaiton to mitigation_tracking will return the 8 records and 3 nulls I want but if I try and limit this because the user has already processed some entries, is where I run into trouble.
MIT_ID RECORD_ID ASSET_ID CATEGORY_ID RE_ID MIT_ID MIT_USERID
10100 10046 10060 10102 10063 10100 BRAD
10071 10046 10060 10102 10063 10071 BRAD
10100 10046 10060 10102 10063 10100 SCOTT
10070 10046 10060 10104 10065 10070 SCOTT
10081 10046 10080 10140 10080 10081 SCOTT
10082 10046 10080 10140 10080
10083 10046 10080 10140 10080
10120 10046 10060 10102 10064
When I try: where (mit_userid is null or MIT_USRE_ID != BRAD)
the return will still include the data with the MIT_ID = 10100 because both BRAD and SCOTT have both processed this record.
What I want in to return only the rows where BRAD has not made an entry into the second mitigation tracking table even if SCOTT has.
I thought it would be easy but no matter how I look at it I cant get a query to work.
Any help would be greatly appreciated.
Data key sets.
MITIGATION
MIT_ID RE_ID CATEGORY_ID ASSET_ID RECORD_ID DATA
10081 10080 10140 10080 10046 Some Data
10082 10080 10140 10080 10046 Some Data
10120 10064 10102 10060 10046 Some Data
10070 10065 10104 10060 10046 Some Data
10071 10063 10102 10060 10046 Some Data
10100 10063 10102 10060 10046 Some Data
10083 10080 10140 10080 10046 Some Data
MITIGATION_TRACKING
MTRACK_ID RECORD_ID ASSET_ID CATEGORY_ID RE_ID MIT_ID MIT_USERID
71 10046 10060 10102 10063 10100 BRAD
70 10046 10060 10102 10063 10071 BRAD
67 10046 10060 10102 10063 10100 SCOTT
68 10046 10060 10104 10065 10070 SCOTT
69 10046 10080 10140 10080 10081 SCOTTI would just like to express my thanks to
The Flying Spontinalli and John Spencer.
Your suggestion have proved to be on the money.
This was one of the last things I needed to do in an APEX application that I was working on and I had been banging my head against the wall for 2 days.
I new that I needed to intersect on the mit_id but did not know about the "NOT IN" and NOT EXISTS"
I appreciate your taking the time to read, understand and respond.
Thanks
Regards
Brad -
Itunes charged my account when songs where not purchased
I was going through the process of purchasing songs from iStore. Right after I hit "Buy Now" I would get a Windows error. I tired this 3 times figuring that nothing downloaded. Well nothing downloaded, but the songs where charged to my account each time. Finally, I was able to pruchase the songs, but now I have charges to my account when I did not receive the music. What do I do?
I sent an email because no one in customer service will help over the phone. That is over 40 dollars in charges for nothing.We are fellow users here on these forums, you are not talking to iTunes Support nor Apple.
Were you buying content for yourself or gifting to another account ? If you were gifting content or an amount then that can only be done via credit card). If you weren't then you will need to contact iTunes Support : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page -
CONNECT BY with CROSS JOIN and WHERE not executing as described in doc
Hello all,
please see these two statements. They are the same, but the 1st uses t1 INNER JOIN t2 while the snd uses a CROSS JOIN with WHERE.
The 2nd statement shows one row more than the first, but the CROSS JOIN with WHERE is the same as the INNER JOIN.
The result would be OK if Oracle did:
JOIN -> CONNECT BY PRIOR -> WHERE
But according to the docs it does:
JOIN (and WHEREs for JOINS) -> CONNECT BY PRIOR -> Rest of WHERE
See http://docs.oracle.com/cd/E11882_01/server.112/e26088/queries003.htm#SQLRF52332 for details. There it says:
Oracle processes hierarchical queries as follows:
A join, if present, is evaluated first, whether the join is specified in the FROM clause or with WHERE clause predicates.
The CONNECT BY condition is evaluated.
Any remaining WHERE clause predicates are evaluated.
+.....+
Is this a bug? I'd say yes, because it differs from the docs and it also is not what people are used to ("a,b WHERE" is the same as "a INNER JOIN b").
Thanks,
Blama
--Statement 1:
WITH t1
AS
(SELECT 1 a, 2 b FROM DUAL UNION ALL
SELECT 2 a, 3 b FROM DUAL UNION ALL
SELECT 3 a, 4 b FROM DUAL UNION ALL
SELECT 4 a, 5 b FROM DUAL UNION ALL
SELECT 5 a, 6 b FROM DUAL),
t2 AS
(SELECT 1 c FROM DUAL UNION ALL
SELECT 2 c FROM DUAL UNION ALL
SELECT 3 c FROM DUAL UNION ALL
SELECT 5 c FROM DUAL)
SELECT DISTINCT t1.a, t2.c, t1.b, level, SYS_CONNECT_BY_PATH(t1.a, '/') Path
FROM t1 INNER JOIN t2
ON t1.a = t2.c
CONNECT BY t1.a = PRIOR t1.b
START WITH t1.a = 1
ORDER BY
1,2,3;
--Result:
--1 1 2 1 /1
--2 2 3 2 /1/2
--3 3 4 3 /1/2/3
--Statement 2:
WITH t1
AS
(SELECT 1 a, 2 b FROM DUAL UNION ALL
SELECT 2 a, 3 b FROM DUAL UNION ALL
SELECT 3 a, 4 b FROM DUAL UNION ALL
SELECT 4 a, 5 b FROM DUAL UNION ALL
SELECT 5 a, 6 b FROM DUAL),
t2 AS
(SELECT 1 c FROM DUAL UNION ALL
SELECT 2 c FROM DUAL UNION ALL
SELECT 3 c FROM DUAL UNION ALL
SELECT 5 c FROM DUAL)
SELECT DISTINCT t1.a, t2.c, t1.b, level, SYS_CONNECT_BY_PATH(t1.a, '/') Path
FROM t1 CROSS JOIN t2
WHERE t1.a = t2.c
CONNECT BY t1.a = PRIOR t1.b
START WITH t1.a = 1
ORDER BY
1,2,3;
--Result:
--1 1 2 1 /1
--2 2 3 2 /1/2
--3 3 4 3 /1/2/3
--5 5 6 5 /1/2/3/4/5My details:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Solaris: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Productionblama wrote:
Hello Paul,
that means that "a,b" isn't the same as "a CROSS JOIN b".
I don't think that that is really the case.
Do you have docs on this one?No explicit docs just (my) logic - having said that, I suppose it is implied that if you are doing ANSI style joins, it's not the where clauses that
are specifying the join.
If you do t1,t2 where t1.a=t2.a then Oracle figures out the kind of join from the (relevant) where clauses and treats the other where clauses after the CONNECT BY.
If you do t1 cross join t2 where t1.a=t2.a then you are saying the join is completely specified by the CROSS JOIN - i.e it's Cartesian. Oracle doesn't look at the where clauses for this. Therefore
all where clauses are treated as 'other' and are evaluated after the CONNECT BY.
So, in my mind it's 10g that has the bug.
Maybe you are looking for
-
Hi , we create plan for the forecast by mass uploading program under the version 001, but some times they will change the forecast manually using MC94 Is there any report which gives values of changes(forecast ) i mean forecast values before and fo
-
Ipad 2 personal hotspot access serious trouble
I bought an Ipad 2 Wifi only. It can acess wifi network in my house but I can´t conect with my Iphone 4 personal hotspot. It´s very strange because I can have a goood conection with Iphone 4 personal hotspot using my Macbook Pro. Both two gadgets (Ip
-
Using 10.6.8 either with a Magic Mouse or a wired microsoft mouse, it auto clicks, for example if I hover the cursor over a bookmark after 2 seonds it automatically selects it, incredibly annoying if I'm browsing a long list I've tried re-syncing the
-
F4 help to get list of Temse Objects
Hi, Im using this FM to fetch/pick the TemSe objects but i couldnot.Im taking the field as PARAMETERS DSN01 LIKE RPCIXXXX-DSN01. Is it good to take DSN01 or need to take TSNAM from REGUT ?.Also im using some C functions also "C_RSTS_READ". The file n
-
Can't find symbol error with registerFont() - why?
I am using the following code which is essentially the same as I copied from a post of someone for whom it apparently works. I am using JDK6 and Netbeans. No matter what I do the line containing registerFont() causes Netbeans to flag it with the foll