Simple Query with subquery returns the 'wrong' result
DB version: 11.2
We created about 27 schemas in the last 4 days. The below query confirms that.
SQL > select username, created from dba_users where created > sysdate-4;
USERNAME CREATED
MANHSMPTOM_DEV_01 12 Jul 2012 11:55:16
PRSM01_OAT_IAU 13 Jul 2012 01:51:03
F_SW 11 Jul 2012 17:52:42
FUN_CDD_HK_SIT 09 Jul 2012 15:33:57
CEMSCOMPTOM_UAT_01 12 Jul 2012 11:43:45
STORM02_OAT_IAU 13 Jul 2012 02:06:29
27 rows selected. -------------> Truncated outputFrom DBA_TS_QUOTAS.max_bytes column , we can determine the space quota allocated for a user/schema
SQL > desc dba_ts_quotas
Name Null? Type
TABLESPACE_NAME NOT NULL VARCHAR2(30)
USERNAME NOT NULL VARCHAR2(30)
BYTES NUMBER
MAX_BYTES NUMBER
BLOCKS NUMBER
MAX_BLOCKS NUMBER
DROPPED VARCHAR2(3)So, I wanted to see the allocated space for the users created in the last 4 days. The below query should return only 27 records because the subquery returns only 27 records. Instead it returned 66 records !
select username, tablespace_name, max_bytes/1024/1024 quotaInMB
from dba_ts_quotas
where username in (select username from dba_users where created > sysdate-4);Any idea why ? I know it is not a bug with oracle. Its just I haven't been eating fish lately.
Hi,
J.Kiechle wrote:
So, I wanted to see the allocated space for the users created in the last 4 days.DBA_TS_QUOTAS doesn't give the allocated space but rather the maximum allowed for a given user.
J.Kiechle wrote:
The below query should return only 27 records because the subquery returns only 27 records. Instead it returned 66 records !What if your user John has Quotas on 3 tablespace TBS1, TBS2 and TBS3 ?
You cannot expect the outer query to only retrieve at most 27 rows just because the inner query returns 27 rows.
For allocated space by tablespace for recently created users, you'd better query dba_segments. something like :select owner, tablespace_name, trunc(sum(bytes)/1024/1024) alloc_mb
from dba_segments
where owner in (select username from dba_users where created > sysdate - 4)
group by owner, tablespace_name
order by owner, tablespace_name;
Similar Messages
-
Simple query with like return wrong result
Hi,
I run simple query with like.
If I use parameter I get wrong results.
If I use query without parameter results are ok.
My script:
ALTER SESSION SET NLS_SORT=BINARY_CI;
ALTER SESSION SET NLS_COMP=LINGUISTIC;
-- drop table abcd;
create table abcd (col1 varchar2(10));
INSERT INTO ABCD VALUES ('122222');
insert into abcd values ('111222');
SELECT * FROM ABCD WHERE COL1 LIKE :1; -- wrong result with value 12%
COL1
122222
*111222*
select * from abcd where col1 like '12%'; -- result ok
COL1
122222
I use Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
and query run in Oracle SQL Developer 3.1.07.Hi,
welcome to the forum.
When you put some code please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
You should specify exactly how you run your code.
If I run this statement in SQL Plus:SQL> ALTER SESSION SET NLS_SORT=BINARY_CI;
Session altered.
SQL> ALTER SESSION SET NLS_COMP=LINGUISTIC;
Session altered.
SQL>
SQL> -- drop table abcd;
SQL> create table abcd (col1 varchar2(10));
Table created.
SQL>
SQL> INSERT INTO ABCD VALUES ('122222');
1 row created.
SQL> insert into abcd values ('111222');
1 row created.
SQL>
SQL> SELECT * FROM ABCD WHERE COL1 LIKE :1;
SP2-0552: Bind variable "1" not declared.
SQL>
I got this error. So I wonder how you set value 12%
Please specify exactly how you run your test as we cannot reproduce your problem.
Regards.
Al -
Query with subquery should return value but doesn't
When I run this SQL, it returns no value:
SELECT vfn.cat
FROM vps_fishery_ner vfn, valid_fishery vf
WHERE vfn.plan = vf.plan
AND vfn.cat = vf.cat
AND vf.permit_year = 2010
AND vf.moratorium_fishery = 'T'
AND vfn.vp_num = 211652
AND vfn.ap_year = 2010
AND vfn.plan = 'MUL'
AND vfn.date_issued = (SELECT MAX(date_issued)
FROM vps_fishery_ner
WHERE vp_num = 211652
AND ap_year = 2010);
In order to test, I take out the subquery and run it separately:
SELECT MAX(date_issued)
FROM vps_fishery_ner
WHERE vp_num = 211652
AND ap_year = 2010;
Returns 02-APR-10
Then I paste this date into the original query (using the TRUNC function, of course, since I hardcode only the DDMMYY part of the date):
SELECT vfn.cat
FROM vps_fishery_ner vfn, valid_fishery vf
WHERE vfn.plan = vf.plan
AND vfn.cat = vf.cat
AND vf.permit_year = 2010
AND vf.moratorium_fishery = 'T'
AND vfn.vp_num = 211652
AND vfn.ap_year = 2010
AND vfn.plan = 'MUL'
AND TRUNC(date_issued) = TO_DATE('02-APR-10');
And this returns the required value, 'A'.
So why doesn't the full query with subquery work, if the value that is returned by the subquery is valid and works when you just paste it in?
Thanks.Hi,
Not sure about your question.
But you say when you uss 01-apr-10 you get the expected results.
So why dont you try using trunc on botht sides
SELECT vfn.cat
FROM vps_fishery_ner vfn, valid_fishery vf
WHERE vfn.plan = vf.plan
AND vfn.cat = vf.cat
AND vf.permit_year = 2010
AND vf.moratorium_fishery = 'T'
AND vfn.vp_num = 211652
AND vfn.ap_year = 2010
AND vfn.plan = 'MUL'
AND trunc(vfn.date_issued) = (SELECT MAX(trunc(date_issued))
FROM vps_fishery_ner
WHERE vp_num = 211652
AND ap_year = 2010);Rememeber if you are couting on some Index to be used you might want to recheck.
IN answer to your question why it does not return with subquery included, because the TIME PART is not the same.
You yourself proved it by using the supplying only the date part.
Regards,
Bhushan -
NOT IN operator giving the wrong results
DB version:10gR2
Why is NOT IN giving the wrong results. Isn't NOT EXISTS operator a flawless alternative to NOT IN?
create table my_table1 (col1 number);
insert into my_table1 values (1);
insert into my_table1 values (2);
commit;
create table my_table2 ( col1 number);
insert into my_table2 values (1);
commit;
select * from my_Table1;
COL1
1
2
select * from my_table2;
COL2
1
--correct result
SELECT * FROM my_table1 t1 WHERE NOT EXISTS
(SELECT * FROM my_table2 t2 WHERE t1.col1 = t2.col1)
COL1
2
---correct result using IN
SELECT * FROM my_table1 t1 where col1 not in (select col1 FROM my_table2 t2);
COL1
2
Inserting a NULL to my_Table2
Now the query using NOT IN is returning wrong results.
insert into my_table2 values (null);
commit;
SELECT * FROM my_table1 t1 where col1 not in (select col1 FROM my_table2 t2);
no rows selected
Query using NOT EXISTS is still giving the right results.
SELECT * FROM my_table1 t1 WHERE NOT EXISTS
(SELECT * FROM my_table2 t2 WHERE t1.col1 = t2.col1);
COL1
2ScottsTiger wrote:
can i use NOT EXISTS(with a proper Co-related subquery) as a safe alternative to NOT IN?Depends on your data and what you need to achieve.
Personally I avoid using NOT EXISTS or NOT IN if I can really help it.
My preferred method is to outer join the tables together and then remove any resultant rows where a value exists and I didn't want one. ;) -
2 queries should return the same result (but they dont...)
hello
i have a following query:
select col1,extract(year from datum) yr, COUNT(*)
from tableA@dblink where
DATUM between '1-jan-1985' and '31-dec-2012'
and col2 > 100 and col2 not in ('999999')
and TRIM(TO_CHAR(col1)) in ('0','1')
group by col1,extract(year from DATUM);the above query returns the count: 143 982 for year 1991
however when i put the filter directly into this year the query returns a different number: 143 917
select col1,extract(year from datum) yr, COUNT(*)
from tableA@dblink where
DATUM between '1-jan-1991' and '31-dec-1991'
and col2 > 100 and col2 not in ('999999')
and TRIM(TO_CHAR(col1)) in ('0','1')
group by col1,extract(year from DATUM);please can you help me understand why is this happening and why these 2 counts are different?
id appreciate any tips
thanks very much
rgdsUserMB wrote:
please can you help me understand why is this happening and why these 2 counts are different?
id appreciate any tipsThis is tricky. All others of cause are right. You must compare date columns with date values.
If you don't explicitly compare as a date value, then it might happen that a string comparison is made.
And if that happens both of your counts would return a wrong result. For example all dates that start with
'4' are not counted. Like '4-jan-1991'. The string '4-jan-1991' is greater then the string '31-dec-1991'. Therefore it would not be included in the count.
I don't think this happened. But the danger is there.
However I have a problem seeing, what the difference between your two counts can be.
The two important parts are the date between filter and the group by condition.
DATUM between '1-jan-1985' and '31-dec-2012'
DATUM between '1-jan-1991' and '31-dec-1991'
group by col1,extract(year from DATUM);The second option returns less results than the first option. Some rows must be missing because of this different filter condition.
If this would be a text comparison then there shouldn't be a difference. Only if it is a date comparison then this could be explained.
Here is an example:
Dates like 31-dec-1991 17:53:14 are included in the first count+group, but not included in the second count.
Why? Because the string '31-dec-1991' is converted into a date. This date is 31-dec-1991 00:00:00 (midnight). Everything from this day, that is not exactly on midnight is greater than this value and therefore not included in your second query.
So as others already pointed out you need to either truncate the date or to compare it a little differently.
select col1,extract(year from datum) yr, COUNT(*)
from tableA@dblink
where DATUM >= to_date('01-01-1991','dd-mm-yyyy')
and DATUM < to_date('01-01-1992','dd-mm-yyyy')
and col2 > 100 and col2 not in ('999999')
and TRIM(TO_CHAR(col1)) in ('0','1')
group by col1,extract(year from DATUM);This should give the same result as your first query.
Note that I changed the month from a month name to a number. This makes it independent from national language settings. E.g. DEZ = German, DEC = American
Edited by: Sven W. on Oct 9, 2012 2:04 PM -
I am using TABLE(CAST()) operation in PL/SQL and it is returning me no data.
Here is what I have done:
1. Created Record type
CREATE OR REPLACE TYPE target_rec AS OBJECT
target__id NUMBER(10),
target_entity_id NUMBER(10),
dd CHAR(3),
fd CHAR(3),
code NUMBER(10),
target_pct NUMBER,
template_nm VARCHAR2(50),
p_symbol VARCHAR2(10),
pm_init VARCHAR2(3),
target_name VARCHAR2(20),
targe_type VARCHAR2(30),
target_caption VARCHAR2(30),
sort_order NUMBER (4)
2. Created Table type
CREATE OR REPLACE TYPE target_arr AS TABLE OF target_rec
3. Created Stored procedure which accepts parameter of type target_arr and runs the Table(Cast()) function on it.
Following is the simplified form of my procedure.
PROCEDURE get_target_weights
p_in_template_target IN target_arr,
p_out_count OUT NUMBER,
IS
BEGIN
SELECT count(*) into p_out_count
FROM TABLE(CAST(p_in_template_target AS target_arr)) arr;
END;
I am calling get_target_weights from my java code and passing p_in_template_target with 10140 records.
Scenario 1: If target_pct in the last record is 0, p_out_count returned from the procedure is 0.
Scenario 2: If target_pct in the last record is any other value(say 0.01), p_out_count returned from the procedure is 10140.
Please help me understand why the Table(Cast()) is not returning the correct results in Scenario 1. Also adding or deleting any record from the test data returns the correct results (i.e. if keep target_pct in the last record as 0 but add or delete any record).
Let me know how can I attach the test data I am using to help you debugging as I don’t see any Attach file button on Post Message screen on the forum.I am not able to reproduce this problem with a small data set. I can only reproduce with the data having 10140 records.
I am not sure if this is the memory issue as adding a new record also solves the problem.
This should not be the error because of wrong way of filling the records in java as for testing purpose I just saved the records which I am sending from java in a table. I updated the stored procedure as well to read the data from the table and then perform TABLE(CAST()) operation. I am still getting 0 as the output for scenario 1 mentioned in my last mail.
Here is what I have updated:
1. Created the table target_table
CREATE Table target_table
target_id NUMBER(10),
target_entity_id NUMBER(10),
dd CHAR(3),
fd CHAR(3),
code NUMBER(10),
target_pct NUMBER,
template_nm VARCHAR2(50),
p_symbol VARCHAR2(10),
pm_init VARCHAR2(3),
target_name VARCHAR2(20),
target_type VARCHAR2(30),
target_caption VARCHAR2(30),
sort_order NUMBER (4)
2. Inserted data into the table : The script has around 10140 rows. Pls let me know how can I send it to you
3. Updated procedure to read data from table and stored into variable of type target_arr. Run Table(cast()) operation on target_arr and get the count
PROCEDURE test_target_weights
IS
v_target_rec target_table%ROWTYPE;
CURSOR wt_cursor IS
Select * from target_table;
v_count NUMBER := 1;
v_target_arr cws_target_arr:= target_arr ();
v_target_arr_rec target_rec;
v_rec_count NUMBER;
BEGIN
OPEN wt_cursor;
loop
fetch wt_cursor into v_target_rec; -- fetch data from table into local record.
exit when wt_cursor%notfound;
--move data into target_arr
v_target_arr_rec := cws_curr_pair_entity_wt_rec(v_target_rec target_id,v_target_rec. target_entity_id,
v_target_rec.dd,v_target_rec.fd,v_target_rec.code,v_target_rec.target_pct,
v_target_rec.template_nm,v_target_rec.p_symbol,v_target_rec.pm_init,v_target_rec.template_name,
v_target_rec.template_type,v_target_rec.template_caption,v_target_rec.sort_order);
v_target_arr.extend();
v_target_arr(v_count) := v_target_arr_rec;
v_count := v_count + 1;
end loop;
close wt_cursor;
-- run table cast on target_arr
SELECT count(*) into v_rec_count
FROM TABLE(CAST(v_target_arr AS target_arr)) arr;
DBMS_OUTPUT.enable;
DBMS_OUTPUT.PUT_LINE('p_out_count ' || v_rec_count);
DBMS_OUTPUT.PUT_LINE('v_count ' || v_count);
END;
Output is
p_out_count 0
v_count 10140
Expected output
p_out_count 10140
v_count 10140 -
The same selection doesn't return the same result in 2 identical systems
Hi,
After a copy we have 2 systems with same data.
In a program the same selection doesn't returns the same result, it seems that the sort is different.
I have checked indexes but they are ok in both systems.
Here is the selection:
SELECT but000~partner
INTO TABLE lt_partner
*UP TO 50 ROWS
FROM but000
JOIN but020
ON but020partner = but000partner
JOIN adrc
ON adrcaddrnumber = but020addrnumber
JOIN but100
ON but100partner = but000partner
WHERE but020~addr_valid_from LE '20100727000000'
AND but020~addr_valid_to GE '20100727000000'.
Is there a customizing point to define how the database must be sorted ?
Thanks.
Edited by: julien schneerberger on Jul 27, 2010 4:18 PMHi,
Thank you for your answer.
Result is the same and I don't sort data after the selection.
Do you think the system copy has "broke" the records order in database ?
If it is the case it will be impossible to reproduce the same sort, is it right ?
Edited by: julien schneerberger on Jul 27, 2010 5:19 PM
Edited by: julien schneerberger on Jul 27, 2010 5:20 PM -
Hi
I am trying to wright a SQL query that will return the date the timesheet was submitted and date/time it was approved, can anyone guide me on this?
I basically need person name who submitted, date - time it was submitted for approval, then the person who approved it and the date - time that it was approved
Thanks
RubyRuby,
you can start with HXC_TIMECARD_SUMMARY table for submitter detail. But for approver details, i think you need WF tables to get the data for item type HXCEMP. -
Ldapsearch does not return the correct result
We are using the Netscape Directory server 4.12. We try to use the Radiator Radius server to query the Directory server for authentication.
When we use the filter:
uid=itkychan
to query if the user is in the Directory, it returns the correct result.
However, we would like to query if the username is in a specified group, e.g. tss_ns_grp, in the Directory, we try to use the following command:
#./ldapsearch -b "o=The xxx University,c=HK" -h hkpu19
"(&(cn=tss_ns_grp)(|(&(objectclass=groupofuniquenames)(uniquemember=uid=itkychan))(&(objectclass=groupofnames)(member=uid=itkychan))))"
but no result is returned.
itkychan is a member of the group tss_ns_grp. The following is a portion of the LDIF file:
dn: cn=tss_ns_grp, o=The xxx University, c=HK
objectclass: top
objectclass: groupOfUniqueNames
objectclass: mailGroup
cn: tss_ns_grp
mail: [email protected]
mailhost: abcd.xxxu.edu.hk
uniquemember: cn=xxxxxxxxxxxxxx, uid=itkychan, ou=xxxu_ITS, o=The xxx University, c=HK
uniquemember: cn=xxxxxxxxxxxxxx, uid=itjcheng, ou=polyu_ITS, o=The xxx University, c=HK
uniquemember: .....You will have to use the full DN for the member and uniquemember e.g.
(...(uniquemember=cn=xxxxxxxxxxxxxx, uid=itkychan, ou=xxxu_ITS, o=The xxx University, c=HK)...) -
ADF how can i execute a query with parameters when the page renders
hi
i am using ADF web 11g
i need to execute a query with parameters when the page renders
thankshello,
I'm a fan of Java code, I really am.
But when you use ADF, you decided to move to a more declarative environment.
So why not do it declarative, the adf way?
In your pagedef insert a action binding.
This can be anything, a call to the application module, a call on the iterator(Like executeWithparams, etc.)
Create an invokeAction in your pagedef and set the condition.
This example refreshes(Action 2 is execute query) the data.
First the method binding:
<action IterBinding="PersoonIterator" id="Execute" InstanceName="LSAppModuleDataControl.Persoon"
DataControl="LSAppModuleDataControl" RequiresUpdateModel="true" Action="2"/>And the invoke action
<invokeAction Binds="Execute" id="refreshData"/>This always refreshes the data on page entry, but anything is possible, you can set condictions for the invokeAction.
-Anton
PS Yes I know that pagedefs become backing beans in the end and yes that is Java code, but if you wanna play the ADF way, the goal is the reduction of Java code and the increased performance of declarative programming. -
Does anyone have a simple program that will return the size of a file
Does anyone have a simple program that will return the size of a file?
I quite hate it when I receive the incorrect amount of yoctocandela per metre squared. Swarthy people
can't properly convert poundal feet to barleycorn; throws off the whole conversion! Aaah, you get what
you paid for.I recognize those figures; you've got your outsourced file sizes from Zanzibar; admit it! I always apply
the scientific approach when I've got file sizes back from Zanzibar: I simply divide those numbers by
pi (very scientific) and drop the eleven (ueber scientific, because 11 is prime even when looked upon
as a binary number) least significant bits. And remember: never compare two floating point numbers
for equality. (<--- that's a free tip)
Jos ;-) -
Shouldn't using WITH return the same results as if you'd put the results in a table first?
First off, here's my version info:
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for HPUX: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
I just reread the documentation again on the subquery factoring clause of SELECT statement, and I didn't see any restrictions that would apply.
Can someone help me understand why I'm getting different results? I'd like to be able to use the statement that creates MAT3, but for some reason it doesn't work. However, when I break it up and store the last TMP subquery in a table (MAT1), I'm able to get the expected results in MAT2.
Sorry if the example seems a little esoteric. I was trying to put something together to help illustrate another problem, so it was convenient to use the same statements to illustrate this problem.
drop table mat1;
create table mat1 as
with skus as (
select level as sku_id
from dual
connect by level <= 1000
tran_dates as (
select to_date('20130731', 'yyyymmdd') + level as tran_date
from dual
connect by level <= 31
sku_dates as (
select s.sku_id,
t.tran_date,
case when dbms_random.value * 5 < 4
then 0
else 1
end as has_changes,
round(dbms_random.value * 10000, 2) as unit_cost
from skus s
inner join tran_dates t
on 1 = 1
select d.sku_id,
d.tran_date,
d.unit_cost
from sku_dates d
where d.has_changes = 1
drop table mat2;
create table mat2 as
select m.sku_id,
m.tran_date,
m.unit_cost,
min(m.tran_date) over (partition by m.sku_id order by m.tran_date rows between 1 following and 1 following) as next_tran_date
from mat1 m
drop table mat3;
create table mat3 as
with skus as (
select level as sku_id
from dual
connect by level <= 1000
tran_dates as (
select to_date('20130731', 'yyyymmdd') + level as tran_date
from dual
connect by level <= 31
sku_dates as (
select s.sku_id,
t.tran_date,
case when dbms_random.value * 5 < 4
then 0
else 1
end as has_changes,
round(dbms_random.value * 10000, 2) as unit_cost
from skus s
inner join tran_dates t
on 1 = 1
tmp as (
select d.sku_id,
d.tran_date,
d.unit_cost
from sku_dates d
where d.has_changes = 1
select m.sku_id,
m.tran_date,
m.unit_cost,
min(m.tran_date) over (partition by m.sku_id order by m.tran_date rows between 1 following and 1 following) as next_tran_date
from tmp m
select count(*) from mat2;
select count(*) from mat3;
from tmp m
select count(*) from mat2;
select count(*) from mat3;
select count(*) from mat2;
COUNT(*)
31000
Executed in 0.046 seconds
select count(*) from mat3;
COUNT(*)
0
Executed in 0.031 secondsI think there's something else going on.
I made the change you suggested, with a slight modification to retain the same functionality of flagging ~80% of the rows as not having changes. I then copied that section of my script - included below - and pasted it into my session twice. Unfortunately, I got different results each time. I have had a number of strange problems when using the WITH clause, which is one of the reasons I jumped at posting something here when I encountered it again in this context.
Can you help me understand why this would happen?
drop table mat3;
create table mat3 as
with skus as (
select level as sku_id
from dual
connect by level <= 1000
tran_dates as (
select to_date('20130731', 'yyyymmdd') + level as tran_date
from dual
connect by level <= 31
sku_dates as (
select s.sku_id,
t.tran_date,
case when dbms_random.value(1,100) * 5 < 400
then 0
else 1
end as has_changes,
round(dbms_random.value * 10000, 2) as unit_cost
from skus s
inner join tran_dates t
on 1 = 1
tmp as (
select d.sku_id,
d.tran_date,
d.unit_cost
from sku_dates d
where d.has_changes = 1
select m.sku_id,
m.tran_date,
m.unit_cost,
min(m.tran_date) over (partition by m.sku_id order by m.tran_date rows between 1 following and 1 following) as next_tran_date
from tmp m
select count(*) from mat2;
select count(*) from mat3;
152249 < mattk > drop table mat3;
Table dropped
Executed in 0.016 seconds
152249 < mattk > create table mat3 as
2 with skus as (
3 select level as sku_id
4 from dual
5 connect by level <= 1000
6 ),
7 tran_dates as (
8 select to_date('20130731', 'yyyymmdd') + level as tran_date
9 from dual
10 connect by level <= 31
11 ),
12 sku_dates as (
13 select s.sku_id,
14 t.tran_date,
15 case when dbms_random.value(1,100) * 5 < 400
16 then 0
17 else 1
18 end as has_changes,
19 round(dbms_random.value * 10000, 2) as unit_cost
20 from skus s
21 inner join tran_dates t
22 on 1 = 1
23 ),
24 tmp as (
25 select d.sku_id,
26 d.tran_date,
27 d.unit_cost
28 from sku_dates d
29 where d.has_changes = 1
30 )
31 select m.sku_id,
32 m.tran_date,
33 m.unit_cost,
34 min(m.tran_date) over (partition by m.sku_id order by m.tran_date rows between 1 following and 1 following) as next_tran_date
35 from tmp m
36 ;
Table created
Executed in 0.53 seconds
152250 < mattk > select count(*) from mat2;
COUNT(*)
0
Executed in 0.047 seconds
152250 < mattk > select count(*) from mat3;
COUNT(*)
31000
Executed in 0.047 seconds
152250 < mattk >
152251 < mattk > drop table mat3;
Table dropped
Executed in 0.016 seconds
152252 < mattk > create table mat3 as
2 with skus as (
3 select level as sku_id
4 from dual
5 connect by level <= 1000
6 ),
7 tran_dates as (
8 select to_date('20130731', 'yyyymmdd') + level as tran_date
9 from dual
10 connect by level <= 31
11 ),
12 sku_dates as (
13 select s.sku_id,
14 t.tran_date,
15 case when dbms_random.value(1,100) * 5 < 400
16 then 0
17 else 1
18 end as has_changes,
19 round(dbms_random.value * 10000, 2) as unit_cost
20 from skus s
21 inner join tran_dates t
22 on 1 = 1
23 ),
24 tmp as (
25 select d.sku_id,
26 d.tran_date,
27 d.unit_cost
28 from sku_dates d
29 where d.has_changes = 1
30 )
31 select m.sku_id,
32 m.tran_date,
33 m.unit_cost,
34 min(m.tran_date) over (partition by m.sku_id order by m.tran_date rows between 1 following and 1 following) as next_tran_date
35 from tmp m
36 ;
Table created
Executed in 0.078 seconds
152252 < mattk > select count(*) from mat2;
COUNT(*)
0
Executed in 0.031 seconds
152252 < mattk > select count(*) from mat3;
COUNT(*)
0
Executed in 0.047 seconds -
Query with subquery containing group clause doesn't return any rows - WHY ?
Hi,
My query doesn't return any values :
select g1.NTRX from gtrx g1
where exists
(SELECT b.cfunctrx, b.cpro1trx, b.nmsgitrx, b.nmrc, b.ncrd, b.namtstrx,
b.dltimtrx, b.nrtrftrx,count(*)
FROM gtrxacq a, gtrx b
WHERE a.ntrx = b.ntrx AND a.acq_bus_date = (SELECT curr_bus_date -1
FROM gmbr
WHERE nmbr = 0)
and g1.NTRX=b.NTRX
GROUP BY b.cfunctrx,
b.cpro1trx,
b.nmsgitrx,
b.nmrc,
b.ncrd,
b.namtstrx,
b.dltimtrx,
b.nrtrftrx
HAVING COUNT (*) > 1);
but such query returns some number of rows :
SELECT b.cfunctrx, b.cpro1trx, b.nmsgitrx, b.nmrc, b.ncrd, b.namtstrx,
b.dltimtrx, b.nrtrftrx,count(*)
FROM gtrxacq a, gtrx b
WHERE a.ntrx = b.ntrx AND a.acq_bus_date = (SELECT curr_bus_date -1
FROM gmbr
WHERE nmbr = 0)
/*and g1.NTRX=b.NTRX*/
GROUP BY b.cfunctrx,
b.cpro1trx,
b.nmsgitrx,
b.nmrc,
b.ncrd,
b.namtstrx,
b.dltimtrx,
b.nrtrftrx
HAVING COUNT (*) > 1
AND when i put results from query above into query :
select g1.NTRX from gtrx g1
where
g1.CFUNCTRX= 200 and g1.CPRO1TRX= 000 and g1.NMSGITRX= 1240 and
g1.NMRC= '000000000000675' and g1.NCRD= 405671**********
and g1.NAMTSTRX=14.26 and g1.DLTIMTRX=to_date('07/08/2008 15:07:02','MM/DD/YYYY HH24:MI:SS')
and g1.NRTRFTRX= '000414598393';
it returns values.
what is wrong ?
Best Regards Arkadiusz Masnybut such query returns some number of rows :
/*and g1.NTRX=b.NTRX*/Add b.NTRX into group by and recheck. -
Distinct Count doesn't return the expected results
Hi All,
I was fighting a little trying to implement a Distinct Count measure over an account dimension in my cube. I read a couple of posts relateed to that and I followed the steps posted by the experts.
I could process the cube but the results I'm getting are not correct. The cube is returning a higher value compared to the correct one calculated directly from the fact table.
Here are the details:
Query of my fact table:
select distinct cxd_account_id,
contactable_email_flag,
case when recency_date>current_date-365 then '0-12' else '13-24' end RECENCY_DATE_ROLLUP,
1 QTY_ACCNT
from cx_bi_reporting.cxd_contacts
where cxd_account_id<>-1 and recency_date >current_date-730;
I have the following dimensions:
Account (with 3 different hierarchies)
Contactable Email Flag (Just 3 values, Y, N, Unknown)
Recency_date (Just dimension members)
All dimensions are sparse and the cube is a compressed one. I defined "MAXIMUM" as aggregate for Contactable Email flag and Recency date and at the end, SUM over Account.
I saw that there is a patch to fix an issue when different aggregation rules are implemented in a compressed cube and I asked the DBA folks to apply it. They told me that the patch cannot be applied because we have an advanced version already installed (Patch 11.2.0.1 ).
These are the details of what we have installed:
OLAP Analytic Workspace 11.2.0.3.0 VALID
Oracle OLAP API 11.2.0.3.0 VALID
OLAP Catalog 11.2.0.3.0 VALID
Is there any other patch that needs to be applied to fix this issue? Or it's already included in the version we have installed (11.2.0.3.0)?
Is there something wrong in the definition of my fact table and that's why I'm not getting the right results?
Any help will be really appreciated!
Thanks in advance,
MartínNot sure I would have designed the dimensions /cubes as you, but there is another method you can obtain distinct counts.
Basically relies on using basic OLAP DML Expression language and can be put in a Calculated Measure, or can create two Calculated measures
to contain each specific result. I use this method to calculate distinct counts when I want to calculate averages, etc ...
IF account_id ne -1 and (recency_date GT today-365) THEN -
CONVERT(NUMLINES(UNIQUELINES(CHARLIST(Recency_date))) INTEGER)-
ELSE IF account_id ne -1 and (recency_date GT today-730 and recency_date LE today-365) THEN -
CONVERT(NUMLINES(UNIQUELINES(CHARLIST(Recency_date))) INTEGER)-
ELSE NA
This exact code may not work in your case, but think you can get the gist of the process involved.
This assumes the aggregation operators are set to the default (Sum), but may work with how you have them set.
Regards,
Michael Cooper -
JPA, Toplink, Query with getSingleResult returns Vector, should it?
I don't understand why when I do a simple query "Select count(*) From ...." and get use the EntityManager my code is something like this:
getEntityManager().createNativeQuery(sql).getSingleResult()
and what I get is a Vector object that has inside a BigDecimal object. I wonder how portable this is if I use hibernate. I bought a book that was written by a couple of guys from Oracle and their example returns a Object array instead of a Vector even when getResultList() function is called.
I can't find any documentation where it indicates what is returned from getSingleResult() and getResultList().
Any help from any gurus are most welcomed....Bug 2219 (https://glassfish.dev.java.net/issues/show_bug.cgi?id=2219 ) deals with native queries not returning the correct types unless it is to return an entity or results specified using a ResultRetMapping.
Michael's blog examples are all using JPQL which do not have this problem, so you could switch to using JPQL to get the proper results as well.
Best Regards,
Chris
Maybe you are looking for
-
Every time I go to the iTunes app it boots me off
When I go into the iTunes app, I click on the area to view all songs and as soon as my iPod downloads all of the songs the app stops and it takes me back to the home page for my iPod. Any fixes for this?? I just bought and loaded a new iTunes card an
-
CannotUser execute task -- " anonymous " has not been assigned task
Hi, I'm trying to build a prototype a workflow using WLI Integration(WLPI). I've created a workflow using WLPI Studio and am able to start the instances using JMS messages. However, when I try to execute one of the task which I 've assigned to user "
-
Acct assignment required for GRIR clearing
Hi, User was performing GRIR clearing and has the following error : "...require G/L 600008 to match to an assignment..." When checked under OKB9, the company code has 2 plants assigned to 2 different cost centers for this GL acct / cost element. Plea
-
IPod Glue Major Glue Problem, HELP
Hey guys! Recently after I bought my iPod Nano 6th gen, I got a case for it, got all my songs on it, awesome! But there's more. See I'm a perinoid guy, and all the cases left the back metal clip naked, and dropping the iPod on that section could caus
-
Airplay speakers from ATV2/3
In the settings-->Airplay section, it is possible to send audio to airplay speakers from apple tv. Example to another airport express or something. Does anyone know if this feature is restricted to audio from music only. When I play a movie, the audi