SQL to idenfity gaps in ranges
A friday SQL teaser! 11.2.03.
I have a table with indicator and start, end ranges. I need an SQL to return ranges that are not excluded.
create table k_test (indicator varchar2(10),start_val number, end_val number);
insert into k_test values('INCLUDE',000,999);
insert into k_test values('EXCLUDE',000,503);
insert into k_test values('EXCLUDE',507,511);
insert into k_test values('EXCLUDE',514,999);A select statement please to return the ranges that are "open", i.e. not excluded.
504
505
506
512
513I can manage this in PL/SQL, keen to know a clever way in SQL.
Ok, let's do some advertising, because i think this solution is simple to understand and readable and need less effort to solve the problem in my opinion. An all can be seen stepwise.
First imaging an empty excel sheet.
So we start from here and fill in the start data.
--select r from (
select r, rng, start_val, end_val, indicator from t
model
dimension by (r)
measures(1 rng, start_val, end_val, indicator)
rules iterate(0) until iteration_number > start_val[0] (
rng[for r from start_val[iteration_number+1] to end_val[iteration_number+1] increment 1]=
case
when cv(r) >= start_val[iteration_number+1]
and cv(r) <= end_val[iteration_number+1]
and indicator[iteration_number+1]='EXCLUDE'
then 0
when indicator[iteration_number+1]='INCLUDE'
then 1
else nvl(rng[cv()],0)
end
--)where rng = 1
R RNG START_VAL END_VAL INDICATOR
2 1 0 503 EXCLUDE
3 1 507 511 EXCLUDE
4 1 514 999 EXCLUDE
1 1 0 999 INCLUDE
0 1 4 - - The last "artificial" row is only used to hold the value for the max iterations needed, that's the number of rows in t. This cell (Excel!) is adressed with start_val[0].
So now we look at the result of first iteration rules iterate(1):
R RNG START_VAL END_VAL INDICATOR
2 1 0 503 EXCLUDE
3 1 507 511 EXCLUDE
4 1 514 999 EXCLUDE
1 1 0 999 INCLUDE
0 1 4 - -
5 1 - - -
6 1 - - -
7 1 - - -
8 1 - - -
9 1 - - -
10 1 - - -
11 1 - just a snipplet. But we can see, that a INCLUDED-row was processed, because rng wa set to 1 on serveral cells. In fact in all rows from 0 to 999. The rows that were not there before, were created on that iteration.
so what will happen in the next iteration rules iterate(2)?
R RNG START_VAL END_VAL INDICATOR
2 0 0 503 EXCLUDE
3 0 507 511 EXCLUDE
4 0 514 999 EXCLUDE
1 0 0 999 INCLUDE
0 0 4 - -
5 0 - - -
6 0 - - -
7 0 - - -
8 0 -
995 1 - - -
996 1 - - -
997 1 - - -
998 1 - - -
999 1 - - Obviously an excluded row was processed, the one with (0 503) and therefor rng was set to 0 in the rows from 0 to 503.
So that row processing goes on until all rows form the origin table are processed, in this case 4, and everytime rng in the processed range will marked with 0 or 1 depend on the indicator and leaved untouched if the row is out of the range in process.
rules iterate(9999999) until iteration_number > start_val[0] is just a construct not to hardcode the number of iterations.
At the end, all we have to do is counting the rows with rng 1.
So be honest, is this way too complicated ?-)
Similar Messages
-
How do I create a No GAP number range for Belgium Inv. and SO
I need to know how can I set up a NO GAP umber range for Belgium Accounting Documents. I have been told tht this can be achieved by setting up a document numbering by company code. What do I need to do (configure) in order to get the number range to work by Company code?
Thanks
Nelson RodriguezAloha Guido
Thanks for the reply, it has provided a lot of very usefull information. I still need to know what are the steps to follow in order to setup document numbering by company code.
Thanks
Nelson -
How to build an SQL Query to print Week ranges of a Month
Hi Gurus!!
I have a requirement to create a query to display the Week periods of a month.
The inputs will be Year and month.
The result should be some thing like this:
If Year = 2009 and Month = June
The SQL Query should return the following:
01-Jun-2009 to 06-Jun-2009
07-Jun-2009 to 13-Jun-2009
14-Jun-2009 to 20-Jun-2009
21-Jun-2009 to 27-Jun-2009
27-Jun-2009 to 30-Jun-2009
I am confused how to do this. Please help me. Any help would be grately Appreciated.
Thanks
AhmedThis is how My Final Query Looks Like:
SELECT TO_CHAR(SYSDATE+7*(level-1),'DD-MON-RRRR')
||' to '
||TO_CHAR(SYSDATE+7*(level-1)+6,'DD-MON-RRRR') RANGES
FROM dual
connect by level<=5
--Ahmed -
SQL DISTINCT COUNT IN DATE RANGE
Dear All
Thanks for your attention.
A table is storing the task summary of each order
e.g.
Date | Order Number | Task Number
2015-01-01 00:00:01 | ABC123456 | JOB001
2015-01-01 00:01:02 | ABC123456 | JOB002
2015-01-01 00:10:02 | ABC123444 | JOB001
2015-01-01 10:12:59 | ABC123456 | JOB002 (Since the job002 is not done correctly, need to work again)
2015-01-01 18:20:05 | ABC888888 | JOB001
2015-01-01 20:22:42 | ABC789456 | JOB001
2015-01-01 21:02:11 | BBB121212 | JOB002
I would like to write a single query that get the distinct count of order number in sepcific date range
result as expected in three columns:
2015-01-01
task_number | AM | PM
JOB001 | 2 | 2
JOB002 | 1 | 1
explain the figures here:
JOB001 AM = 2 (ABC123456, ABC123444)
JOB002 AM = 1 (two records of ABC123456 count as 1 since we would like to know the number of orders)
JOB001 PM = 2 (ABC888888, ABC789456)
JOB002 PM = 1 (BBB121212)
I wrote a query get similar result but the count of order is not distinct
SELECT task_number,
AM=SUM(CASE WHEN date >= ('2015-01-01 00:00:00') AND date < ('2015-01-01 12:00:00') THEN 1 ELSE 0 END),
PM=SUM(CASE WHEN date >= ('2015-01-01 12:00:00') AND date < ('2015-01-02 00:00:00') THEN 1 ELSE 0 END)
FROM MyTable
WHERE task_number = 'JOB001'
Could anyone advise how to enhance this query to let the result become disintct of order number?
Many Thanks,
swivanTry
select task_number,
count(distinct case when datepart(hour, [date]) >=0 and datepart(hour, [date]) < 12 then [OrderNumbers] END) as AM,
count(distinct case when datepart(hour, [date]) >=12 and datepart(hour, [date]) < 24 then [OrderNumbers] END) as PM FROM myTable
GROUP BY Task_Number
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles
Thank you very much, short and good answer -
SQL Select Records in a range but Not in another range
Dear All
I would like to know the best method to do the following task.
There are records of meeting room usage
room start_time
Room A 2014-08-30 16:55:00.000
Room C 2014-08-30 13:20:00.000
Room B 2014-08-29 21:45:00.000
Room A 2014-08-29 22:00:00.000
I would like to get the rooms used at a range (e.g. 2014-08-30) but cannot be used in another range (e.g. 2014-08-29 or before)
The result should be Room C only.
My apporach is as follows
SELECT room FROM RoomUsage
WHERE start_time >= '2014-08-30 00:00:00' AND start_time <= '2014-08-30 23:59:59'
AND room NOT IN (
SELECT room FROM RoomUsage
WHERE start_time < '2014-08-30 00:00:00'
Is there any better and simple approach to achieve the same result?
Thank you
Best Regards
swivanI tend to use EXCEPT or NOT EXISTS for this kind of thing as I find them more intuitive. I also tend
not to use Not In for JOINs due to its well-known problem with NULLs, ie if there is a NULL in the inner resultset the query short-circuits and you get no records. I therefore prefer to use In / Not In for
short lists eg Not In ( 'a', 'b', 'c' ).
See for yourself:
IF OBJECT_ID('tempdb..#roomUsage') IS NOT NULL DROP TABLE #roomUsage
CREATE TABLE #roomUsage ( room VARCHAR(20) NOT NULL, start_time DATETIME2 NOT NULL )
INSERT INTO #roomUsage
VALUES
( 'Room A', '2014-08-30 16:55:00.000' ),
( 'Room C', '2014-08-30 13:20:00.000' ),
( 'Room B', '2014-08-29 21:45:00.000' ),
( 'Room A', '2014-08-29 22:00:00.000' )
SELECT room
FROM #roomUsage
WHERE start_time >= '2014-08-30 00:00:00' AND start_time <= '2014-08-30 23:59:59'
EXCEPT
SELECT room
FROM #roomUsage
WHERE start_time < '2014-08-30 00:00:00'
SELECT room FROM #roomUsage
WHERE start_time >= '2014-08-30 00:00:00' AND start_time <= '2014-08-30 23:59:59'
AND room NOT IN (
SELECT room FROM #roomUsage
WHERE start_time < '2014-08-30 00:00:00'
-- Oops
SELECT room FROM #roomUsage
WHERE start_time >= '2014-08-30 00:00:00' AND start_time <= '2014-08-30 23:59:59'
AND room NOT IN (
SELECT room FROM #roomUsage
WHERE start_time < '2014-08-30 00:00:00'
UNION ALL
SELECT NULL -
Get the SQLs In between a date range
Get the SQLs irrespective of sessions in the order of its execution from a specified schema with in a date time range
Which version of Oracle are you using?
Jaffar -
SQL Query to get Date Range Values
Hi,
The database is Oracle11i.
I am looking for a way to generate list of dates from a fixed date in the past (could be hardcoded) to current day (sysdate).
That is, if the fixed date is 19 June 2011 and assuming that today is 24 June 2011 the SQL should be able to generate the
following:-
19-June-2011
20-June-2011
21-June-2011
22-June-2011
23-June-2011
24-June-2011
And the constraint is that I can't make any change to the database in question. I can only fire an SQL query (SELECT). No
usage of time dimension kind of approach (time dimension is not available here) and no procedures, PL/SQL etc. Is there any way?
ThanksJaimeen Shah wrote:
Hi,
The database is Oracle11i.
I am looking for a way to generate list of dates from a fixed date in the past (could be hardcoded) to current day (sysdate).
That is, if the fixed date is 19 June 2011 and assuming that today is 24 June 2011 the SQL should be able to generate the
following:-
19-June-2011
20-June-2011
21-June-2011
22-June-2011
23-June-2011
24-June-2011
And the constraint is that I can't make any change to the database in question. I can only fire an SQL query (SELECT). No
usage of time dimension kind of approach (time dimension is not available here) and no procedures, PL/SQL etc. Is there any way?
Thanks
SQL> def date_start = '13/11/2010'
SQL> def date_end = '22/11/2010'
SQL> with
2 data as (
3 select to_date('&date_start', 'DD/MM/YYYY') date1,
4 to_date('&date_end', 'DD/MM/YYYY') date2
5 from dual
6 )
7 select to_char(date1+level-1, 'DD/MM/YYYY') the_date
8 from data
9 connect by level <= date2-date1+1
10 /
THE_DATE
13/11/2010
14/11/2010
15/11/2010
16/11/2010
17/11/2010
18/11/2010
19/11/2010
20/11/2010
21/11/2010
22/11/2010 -
SQL for Parnet child for range values
Gurus,
I need help to figure out a query which will result to get parent child relation for ranges of data
eg:
Name Low High
t1 10000 20000
t2 10000 20001
t3 11000 15000
t4 10500 19000
t5 11000 14500
Results
Name Parent Low High
T2 0 10000 20001
t1 t2 10000 20000
t3 t1 11000 15000
t4 t1 10500 19000
t5 t3 11000 15000
Child will have only one parent
please help
gbkWell normally I would suggest using Start with/Connect by for a hierarchical query.
But you need to provide more accurate data. Somewhere in your table you must have a parent id.
So if you had that it would look something like:
select name, nvl(parent_name, 0) low, high
from table
start with parent_name is null
connect by name = prior parent_name -
Oracle SQl query to find date range based on another cloumn value
Hi Folks,
I want to extract records for the employees who have consecutive vacation/leave from a table. If an emp has vacation of 3 days (MON-WED), the table contains 3 distinct records for him,
e.g. My table contains records as shown below.
EmpName Paycode ApplyDate Amt. of Hrs
emp1 vacation 5/1/2010 8
emp1 vacation 5/2/2010 8
emp1 vacation 5/3/2010 8
I am trying to get the output like this...
Emp Name Paycode Leave Start Date Leave End Date TotalHrs
emp1 vacation 5/1/2010 5/3/2010 24
Note: If the smae emp has sets of vacation in another month, that should come as a separate record with start date and end date(last date of vacation for that set).
I have a query which does not return any rows. Any help to repair this query or any better one would be of great help.
==================================================================
WITH vpt AS (
select personnum as empname, paycodename as paycode, applydate, timeinseconds/3600 as numhours from VP_TOTALS
where applydate between to_date('05/01/2010','MM/DD/YYYY') AND to_date('12/31/2010','MM/DD/YYYY')
AND paycodename in ('US-Vacation','US-Bereavement','US-Sick','US-Jury Duty')
select
empname,
paycode,
min(applydate) as startdate,
max(applydate) as enddate,
sum(numhours) as totalhours
from (
select
empname,
paycode,
applydate,
numhours,
-- number the blocks sequentially
sum(is_block_start) over (partition by empname, paycode order by applydate) as block_num
from (
select
empname,
paycode,
applydate,
numhours,
-- Mark the start of each block
case
when applydate = prev_applydate + 1 then 0 else 1 end as is_block_start
from (
select
empname,
paycode,
applydate,
numhours,
lag (applydate) over (partition by empname, paycode order by applydate) prev_applydate
from vpt
group by empname, paycode, block_num
===================================================================
Thanks,
MahaHi Dear,
Can I do reverse I mean I can get output as your question from your output as below:
I have this table
FID STARTD ATE END DATE
1 01-MAY-10 03-MAY-10
1 09-MAY-10 11-MAY-10
1 03-JUN-10 04-JUN-10
2 03-JUN-10 04-JUN-10
2 04-AUG-10 04-AUG-10
2 06-AUG-10 06-AUG-10
I want like this.
FID FDATE
1 01-MAY-10
1 02-MAY-10
1 03-MAY-10
1 09-MAY-10
1 10-MAY-10
1 11-MAY-10
1 03-JUN-10
1 04-JUN-10
2 03-JUN-10
2 04-JUN-10
2 04-AUG-10
2 06-AUG-10
And:
How can i get date wise entry from Joining date to relieving date like..
FID START DATE END DATE
1 01-MAY-10 03-MAY-12
1 09-MAY-10 11-MAY-11
2 04-AUG-10 04-AUG-11
I want like this.
FID FDATE
1 01-MAY-10
1 03-MAY-10
1 04-MAY-10
1 05-MAY-10
1 16-MAY-10
1 17-MAY-10
1 08-May-10
1 09-May-10
1 03-May-12
Can you please help me.
Thanks,
Edited by: 978452 on Dec 24, 2012 12:02 AM -
SQL Syntax for hour/date range in Query
Hi
I am trying to set up an query for sales order documents procesed in the last 30 minutes to be set as an alert to be run every 30 minutes to the sales manager. I am having difficulty getting the syntax for the last 30 minutes
Any suggestions?
Davidhi,
I'm not sure query is correct,but u can modify it futher to get correct one.
SELECT T0.DocNum, T0.DocDate, T0.CardName, T0.DocTotal FROM ORDR T0 WHERE DateDiff(dd, T0.DocDate ,getdate()) = 0 and
DateDiff(Minute,T0.DocTime,' ') <= 30
Jeyakanthan -
How to get a date range in JDBC sql
I am using the following in my sql to get a date range... but what if the field is a timestamp will that still work or not...
AND a.date>=? AND a.date<=?Suzie,
No offence, but is there something stopping you from testing it yourself?
Good Luck,
Avi. -
How Gap Performance is calculated?
Hi Guys,
I´m working with SSM 7.5 (SP 10) under NetWeaver 7.2 (SQL Server database).
I have the follow values for my KPI:
Name: Revenue
Actual: 415.281,13
Target: 511.318,09
Score: 81,22
Gap Performance: 40,72
Stable Gap Performance Range
Score History:
AprJun 2005: 67,26 (Trend Down)
JulSep 2005: 76,15 (Trend Down)
OctDec 2005: 81,22 (Trend Up)
I need know, how these values resulted in 40,72 (Gap Performance). How this is calculated?
Ps: I´ve already read some explanations into the SDN forum but still not understanding.
Best Regards,
Bruno HeisslerI have kept this explanation provided by Colin Cooper hope it helps - I am not a mathematician but I kind of get what it is thinking of although the challenge is to try and explain this in easy terms to our user community in terms that they can understand easily.
I think colins last sentence is the thing I will hang onto into trying to explain it.
Gap Performance is something that is often confusing!
Gap performance is trend deviation and is a virtual metric. It is based on the comparison between the Score and the Trend of the score and the calculation is ((Score - Trend of Score) % Trend of Score)
It takes the average of the last three Scores and compares them with the current score.
As an example:
if the scores for the last 3 periods are 45.37, 45.37 and 52 the average is 47.58
so the calculation of Gap Performance would be (52-47.58)/47.58100 = 4.42/47.58100 = 9.28
Therefore the higher the Gap Performance the better the the level of improvement. -
Hi,
I need some help on tuning this sql. We run a third party application and I have to ask thrid party for any changes. I have pasted the session statistice from the run for this sql.
SELECT DECODE( RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,
' ')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' '),
RPAD(NVL(:zipout1,' '),4,' ')||RPAD(NVL(:zipin1,' '),3,' '),
'0001', RPAD(NVL(:zipout2,' '),4,'
')||RPAD(SUBSTR(NVL(:zipin2,' '),0,1),3,' '), '0002',
RPAD(NVL(:zipout3,' '),7,' '), '0003',
RPAD('ZZ999',7,' '), '0004' ) AS CHECKER
FROM NWKPCDREC
WHERE NWKPCDNETWORKID = :netid
AND NWKPCDSORTPOINT1TYPE != 'XXXXXXXX'
AND ( (RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,' ')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' ') =
RPAD(NVL(:zipout4,' '),4,' ')||RPAD(NVL(:zipin3,' '),3,' '))
OR (RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,'
')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' ') =
RPAD(NVL(:zipout5,' '),4,' ')||RPAD(SUBSTR(NVL(:zipin4,' '),0,
1),3,' ')) OR (RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,'
')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' ') =
RPAD(NVL(:zipout6,' '),7,' ')) OR
(RPAD(NVL(NWKPCDOUTWDPOSTCODE,' '),4,'
')||RPAD(NVL(NWKPCDINWDPOSTCODE,' '),3,' ') = RPAD('ZZ999',7,
' ')) ) ORDER BY CHECKER
Session Statistics 09 October 2007 22:44:56 GMT+00:00
Report Target : PRD1 (Database)
Session Statistics
(Chart form was tabular, see data table below)
SID Name Value Class
37 write clones created in foreground 0 Cache
37 write clones created in background 0 Cache
37 user rollbacks 16 User
37 user commits 8674 User
37 user calls 302838 User
37 transaction tables consistent reads - undo records applied 0 Debug
37 transaction tables consistent read rollbacks 0 Debug
37 transaction rollbacks 9 Debug
37 transaction lock foreground wait time 0 Debug
37 transaction lock foreground requests 0 Debug
37 transaction lock background gets 0 Debug
37 transaction lock background get time 0 Debug
37 total file opens 12 Cache
37 table scans (short tables) 8062 SQL
37 table scans (rowid ranges) 0 SQL
37 table scans (long tables) 89 SQL
37 table scans (direct read) 0 SQL
37 table scans (cache partitions) 2 SQL
37 table scan rows gotten 487042810 SQL
37 table scan blocks gotten 7327924 SQL
37 table fetch continued row 17 SQL
37 table fetch by rowid 26130550 SQL
37 switch current to new buffer 6400 Cache
37 summed dirty queue length 0 Cache
37 sorts (rows) 138607 SQL
37 sorts (memory) 13418 SQL
37 sorts (disk) 0 SQL
37 session uga memory max 5176776 User
37 session uga memory 81136 User
37 session stored procedure space 0 User
37 session pga memory max 5559884 User
37 session pga memory 5559884 User
37 session logical reads 115050107 User
37 session cursor cache hits 0 SQL
37 session cursor cache count 0 SQL
37 session connect time 1191953042 User
37 serializable aborts 0 User
37 rows fetched via callback 1295545 SQL
37 rollbacks only - consistent read gets 0 Debug
37 rollback changes - undo records applied 114 Debug
37 remote instance undo header writes 0 Global Cache
37 remote instance undo block writes 0 Global Cache
37 redo writes 0 Redo
37 redo writer latching time 0 Redo
37 redo write time 0 Redo
37 redo wastage 0 Redo
37 redo synch writes 8683 Cache
37 redo synch time 722 Cache
37 redo size 25463692 Redo
37 redo ordering marks 0 Redo
37 redo log switch interrupts 0 Redo
37 redo log space wait time 0 Redo
37 redo log space requests 1 Redo
37 redo entries 81930 Redo
37 redo buffer allocation retries 1 Redo
37 redo blocks written 0 Redo
37 recursive cpu usage 101 User
37 recursive calls 84413 User
37 recovery blocks read 0 Cache
37 recovery array reads 0 Cache
37 recovery array read time 0 Cache
37 queries parallelized 0 Parallel Server
37 process last non-idle time 1191953042 Debug
37 prefetched blocks aged out before use 0 Cache
37 prefetched blocks 1436767 Cache
37 pinned buffers inspected 89 Cache
37 physical writes non checkpoint 3507 Cache
37 physical writes direct (lob) 0 Cache
37 physical writes direct 3507 Cache
37 physical writes 3507 Cache
37 physical reads direct (lob) 0 Cache
37 physical reads direct 2499 Cache
37 physical reads 1591668 Cache
37 parse time elapsed 336 SQL
37 parse time cpu 315 SQL
37 parse count (total) 28651 SQL
37 parse count (hard) 1178 SQL
37 opens requiring cache replacement 0 Cache
37 opens of replaced files 0 Cache
37 opened cursors current 51 User
37 opened cursors cumulative 28651 User
37 no work - consistent read gets 59086317 Debug
37 no buffer to keep pinned count 0 Other
37 next scns gotten without going to DLM 0 Parallel Server
37 native hash arithmetic fail 0 SQL
37 native hash arithmetic execute 0 SQL
37 messages sent 9730 Debug
37 messages received 0 Debug
37 logons current 1 User
37 logons cumulative 1 User
37 leaf node splits 111 Debug
37 kcmgss waited for batching 0 Parallel Server
37 kcmgss read scn without going to DLM 0 Parallel Server
37 kcmccs called get current scn 0 Parallel Server
37 instance recovery database freeze count 0 Parallel Server
37 index fast full scans (rowid ranges) 0 SQL
37 index fast full scans (full) 210 SQL
37 index fast full scans (direct read) 0 SQL
37 immediate (CURRENT) block cleanout applications 4064 Debug
37 immediate (CR) block cleanout applications 83 Debug
37 hot buffers moved to head of LRU 20004 Cache
37 global lock sync gets 0 Parallel Server
37 global lock sync converts 0 Parallel Server
37 global lock releases 0 Parallel Server
37 global lock get time 0 Parallel Server
37 global lock convert time 0 Parallel Server
37 global lock async gets 0 Parallel Server
37 global lock async converts 0 Parallel Server
37 global cache read buffer lock timeouts 0 Global Cache
37 global cache read buffer blocks served 0 Global Cache
37 global cache read buffer blocks received 0 Global Cache
37 global cache read buffer block timeouts 0 Global Cache
37 global cache read buffer block send time 0 Global Cache
37 global cache read buffer block receive time 0 Global Cache
37 global cache read buffer block build time 0 Global Cache
37 global cache prepare failures 0 Global Cache
37 global cache gets 0 Global Cache
37 global cache get time 0 Global Cache
37 global cache freelist waits 0 Global Cache
37 global cache defers 0 Global Cache
37 global cache cr timeouts 0 Global Cache
37 global cache cr requests blocked 0 Global Cache
37 global cache cr blocks served 0 Global Cache
37 global cache cr blocks received 0 Global Cache
37 global cache cr block send time 0 Global Cache
37 global cache cr block receive time 0 Global Cache
37 global cache cr block flush time 0 Global Cache
37 global cache cr block build time 0 Global Cache
37 global cache converts 0 Global Cache
37 global cache convert timeouts 0 Global Cache
37 global cache convert time 0 Global Cache
37 global cache blocks corrupt 0 Global Cache
37 free buffer requested 1597281 Cache
37 free buffer inspected 659 Cache
37 execute count 128826 SQL
37 exchange deadlocks 1 Cache
37 enqueue waits 0 Enqueue
37 enqueue timeouts 0 Enqueue
37 enqueue requests 23715 Enqueue
37 enqueue releases 23715 Enqueue
37 enqueue deadlocks 0 Enqueue
37 enqueue conversions 0 Enqueue
37 dirty buffers inspected 437 Cache
37 deferred (CURRENT) block cleanout applications 21937 Debug
37 db block gets 230801 Cache
37 db block changes 160407 Cache
37 data blocks consistent reads - undo records applied 460 Debug
37 cursor authentications 488 Debug
37 current blocks converted for CR 0 Cache
37 consistent gets 114819307 Cache
37 consistent changes 460 Cache
37 commit cleanouts successfully completed 37201 Cache
37 commit cleanouts 37210 Cache
37 commit cleanout failures: write disabled 0 Cache
37 commit cleanout failures: hot backup in progress 0 Cache
37 commit cleanout failures: cannot pin 0 Cache
37 commit cleanout failures: callback failure 3 Cache
37 commit cleanout failures: buffer being written 0 Cache
37 commit cleanout failures: block lost 6 Cache
37 cold recycle reads 0 Cache
37 cluster key scans 17 SQL
37 cluster key scan block gets 36 SQL
37 cleanouts only - consistent read gets 83 Debug
37 cleanouts and rollbacks - consistent read gets 0 Debug
37 change write time 108 Cache
37 calls to kcmgrs 0 Debug
37 calls to kcmgcs 391 Debug
37 calls to kcmgas 8816 Debug
37 calls to get snapshot scn: kcmgss 171453 Parallel Server
37 bytes sent via SQL*Net to dblink 0 User
37 bytes sent via SQL*Net to client 25363874 User
37 bytes received via SQL*Net from dblink 0 User
37 bytes received via SQL*Net from client 29829542 User
37 buffer is pinned count 540816 Other
37 buffer is not pinned count 86108905 Other
37 branch node splits 6 Debug
37 background timeouts 0 Debug
37 background checkpoints started 0 Cache
37 background checkpoints completed 0 Cache
37 Unnecesary process cleanup for SCN batching 0 Parallel Server
37 SQL*Net roundtrips to/from dblink 0 User
37 SQL*Net roundtrips to/from client 302837 User
37 Parallel operations not downgraded 0 Parallel Server
37 Parallel operations downgraded to serial 0 Parallel Server
37 Parallel operations downgraded 75 to 99 pct 0 Parallel Server
37 Parallel operations downgraded 50 to 75 pct 0 Parallel Server
37 Parallel operations downgraded 25 to 50 pct 0 Parallel Server
37 Parallel operations downgraded 1 to 25 pct 0 Parallel Server
37 PX remote messages sent 0 Parallel Server
37 PX remote messages recv'd 0 Parallel Server
37 PX local messages sent 0 Parallel Server
37 PX local messages recv'd 0 Parallel Server
37 OS Voluntary context switches 0 OS
37 OS User time used 0 OS
37 OS System time used 0 OS
37 OS Swaps 0 OS
37 OS Socket messages sent 0 OS
37 OS Socket messages received 0 OS
37 OS Signals received 0 OS
37 OS Page reclaims 0 OS
37 OS Page faults 0 OS
37 OS Maximum resident set size 0 OS
37 OS Involuntary context switches 0 OS
37 OS Integral unshared stack size 0 OS
37 OS Integral unshared data size 0 OS
37 OS Integral shared text size 0 OS
37 OS Block output operations 0 OS
37 OS Block input operations 0 OS
37 DML statements parallelized 0 Parallel Server
37 DFO trees parallelized 0 Parallel Server
37 DDL statements parallelized 0 Parallel Server
37 DBWR undo block writes 0 Cache
37 DBWR transaction table writes 0 Cache
37 DBWR summed scan depth 0 Cache
37 DBWR revisited being-written buffer 0 Cache
37 DBWR make free requests 0 Cache
37 DBWR lru scans 0 Cache
37 DBWR free buffers found 0 Cache
37 DBWR cross instance writes 0 Global Cache
37 DBWR checkpoints 0 Cache
37 DBWR checkpoint buffers written 0 Cache
37 DBWR buffers scanned 0 Cache
37 Commit SCN cached 0 Debug
37 Cached Commit SCN referenced 1 Debug
37 CR blocks created 203 Cache
37 CPU used when call started 280528 Debug
37 CPU used by this session 280528 User
Regards
Raj
--------------------------------------------------------------------------------Thank you everybody for helping me out while tuning the query. I have managed to bring down the run time from 60 minutes to 12 minutes.
I am posting the exisitng query, existing database objects ddl and the new query and new ddl to share my learning. This is my first use of forum, senior members, please letme know if I shouldn't have put all this here.
/pre original code
SELECT decode(rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' '), rpad(nvl(:zipout1, ' '), 4, ' ')
|| rpad(nvl(:zipin1, ' '), 3, ' '), '0001', rpad(nvl(:zipout2, ' '), 4,
' ') || rpad(substr(nvl(:zipin2, ' '), 0, 1), 3, ' '), '0002',
rpad(nvl(:zipout3, ' '), 7, ' '), '0003', rpad('ZZ999', 7, ' '), '0004')
AS checker, a.nwkpcdbarcode1to7 nwkpcdbarcode1to7,
a.nwkpcdbarcode15 nwkpcdbarcode15,
a.nwkpcdbarcodeseqkey nwkpcdbarcodeseqkey,
a.nwkpcdsortpoint1code nwkpcdsortpoint1code,
a.nwkpcdsortpoint1type nwkpcdsortpoint1type,
a.nwkpcdsortpoint1name nwkpcdsortpoint1name,
a.nwkpcdsortpoint1extra nwkpcdsortpoint1extra,
a.nwkpcdsortpoint2type nwkpcdsortpoint2type,
a.nwkpcdsortpoint2name nwkpcdsortpoint2name,
a.nwkpcdsortpoint3type nwkpcdsortpoint3type,
a.nwkpcdsortpoint3name nwkpcdsortpoint3name,
a.nwkpcdsortpoint4type nwkpcdsortpoint4type,
a.nwkpcdsortpoint4name nwkpcdsortpoint4name,
b.nwkprfnetworksequence nwkprfnetworksequence,
b.nwkprfnetworkid nwkprfnetworkid, b.nwkprfnetworkname nwkprfnetworkname,
b.nwkprfminweight / 100 AS nwkprfminweight, b.nwkprfmaxweight / 100 AS
nwkprfmaxweight, b.nwkprfminlengthgirth nwkprfminlengthgirth,
b.nwkprfmaxlengthgirth nwkprfmaxlengthgirth,
b.nwkprfminlength nwkprfminlength, b.nwkprfmaxlength nwkprfmaxlength,
b.nwkprfparceltypecode nwkprfparceltypecode,
b.nwkprfparceltypename nwkprfparceltypename
FROM wh1.nwkpcdrec a, wh1.nwkprefrec b
WHERE a.nwkpcdnetworkid = b.nwkprfnetworkid
AND a.nwkpcdsortpoint1type != 'XXXXXXXX'
AND (rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' ') = rpad(nvl(:zipout4, ' '), 4, ' '
) || rpad(nvl(:zipin3, ' '), 3, ' ')
OR rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' ') = rpad(nvl(:zipout5, ' '), 4, ' '
) || rpad(substr(nvl(:zipin4, ' '), 0, 1), 3, ' ')
OR rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' ') = rpad(nvl(:zipout6, ' '), 7, ' '
OR rpad(nvl(a.nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(
a.nwkpcdinwdpostcode, ' '), 3, ' ') = rpad('ZZ999', 7, ' '))
AND :weight1 >= b.nwkprfminweight
AND :weight2 <= b.nwkprfmaxweight
AND b.nwkprfminlengthgirth <= 60
AND b.nwkprfmaxlengthgirth >= 60
AND b.nwkprfminlength <= 15
AND b.nwkprfmaxlength >= 15
ORDER BY b.nwkprfnetworkid, checker
CREATE TABLE "WH1"."NWKPCDREC" ("NWKPCDFILECODE" VARCHAR2(2),
"NWKPCDRECORDTYPE" VARCHAR2(4), "NWKPCDNETWORKID" VARCHAR2(2),
"NWKPCDOUTWDPOSTCODE" VARCHAR2(4), "NWKPCDINWDPOSTCODE"
VARCHAR2(3), "NWKPCDSORTPOINT1CODE" VARCHAR2(2),
"NWKPCDSORTPOINT1TYPE" VARCHAR2(8), "NWKPCDSORTPOINT1NAME"
VARCHAR2(16), "NWKPCDSORTPOINT1EXTRA" VARCHAR2(16),
"NWKPCDSORTPOINT2TYPE" VARCHAR2(8), "NWKPCDSORTPOINT2NAME"
VARCHAR2(8), "NWKPCDSORTPOINT3TYPE" VARCHAR2(8),
"NWKPCDSORTPOINT3NAME" VARCHAR2(8), "NWKPCDSORTPOINT4TYPE"
VARCHAR2(8), "NWKPCDSORTPOINT4NAME" VARCHAR2(8), "NWKPCDPPI"
VARCHAR2(8), "NWKPCDBARCODE1TO7" VARCHAR2(7),
"NWKPCDBARCODE15" VARCHAR2(1), "NWKPCDBARCODESEQKEY"
VARCHAR2(7), "NWKPCDFILLER1" VARCHAR2(7), "NWKPCDFILLER2"
VARCHAR2(30),
CONSTRAINT "UK_NWKPCDREC" UNIQUE("NWKPCDNETWORKID",
"NWKPCDOUTWDPOSTCODE", "NWKPCDINWDPOSTCODE")
USING INDEX
TABLESPACE "WH1_INDEX"
STORAGE ( INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
PCTFREE 10 INITRANS 2 MAXTRANS 255)
TABLESPACE "WH1_DATA_LARGE" PCTFREE 10 PCTUSED 40 INITRANS 1
MAXTRANS 255
STORAGE ( INITIAL 4096K NEXT 4096K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
NOLOGGING
pre original script/
/pre modified script
CREATE TABLE "WH1"."NWKPCEREC_OLD" ("NWKPCDFILECODE" VARCHAR2(2),
"NWKPCDRECORDTYPE" VARCHAR2(4), "NWKPCDNETWORKID" VARCHAR2(2),
"NWKPCDOUTWDPOSTCODE" VARCHAR2(4), "NWKPCDINWDPOSTCODE"
VARCHAR2(3), "NWKPCDSORTPOINT1CODE" VARCHAR2(2),
"NWKPCDSORTPOINT1TYPE" VARCHAR2(8), "NWKPCDSORTPOINT1NAME"
VARCHAR2(16), "NWKPCDSORTPOINT1EXTRA" VARCHAR2(16),
"NWKPCDSORTPOINT2TYPE" VARCHAR2(8), "NWKPCDSORTPOINT2NAME"
VARCHAR2(8), "NWKPCDSORTPOINT3TYPE" VARCHAR2(8),
"NWKPCDSORTPOINT3NAME" VARCHAR2(8), "NWKPCDSORTPOINT4TYPE"
VARCHAR2(8), "NWKPCDSORTPOINT4NAME" VARCHAR2(8), "NWKPCDPPI"
VARCHAR2(8), "NWKPCDBARCODE1TO7" VARCHAR2(7),
"NWKPCDBARCODE15" VARCHAR2(1), "NWKPCDBARCODESEQKEY"
VARCHAR2(7), "NWKPCDFILLER1" VARCHAR2(7), "NWKPCDFILLER2"
VARCHAR2(30))
TABLESPACE "WH1_DATA_LARGE" PCTFREE 10 PCTUSED 40 INITRANS 1
MAXTRANS 255
STORAGE ( INITIAL 4096K NEXT 4096K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
NOLOGGING
insert into wh1.nwkpcdrec_old select * from wh1.nwkpcdrec;
drop table wh1.nwkpcdrec;
CREATE TABLE "WH1"."NWKPCDREC" ("NWKPCDFILECODE" VARCHAR2(2),
"NWKPCDRECORDTYPE" VARCHAR2(4), "NWKPCDNETWORKID" VARCHAR2(2),
"NWKPCDOUTINWDPOSTCODE" VARCHAR2(7) NOT NULL,
"NWKPCDOUTWDPOSTCODE" VARCHAR2(4), "NWKPCDINWDPOSTCODE"
VARCHAR2(3), "NWKPCDSORTPOINT1CODE" VARCHAR2(2),
"NWKPCDSORTPOINT1TYPE" VARCHAR2(8), "NWKPCDSORTPOINT1NAME"
VARCHAR2(16), "NWKPCDSORTPOINT1EXTRA" VARCHAR2(16),
"NWKPCDSORTPOINT2TYPE" VARCHAR2(8), "NWKPCDSORTPOINT2NAME"
VARCHAR2(8), "NWKPCDSORTPOINT3TYPE" VARCHAR2(8),
"NWKPCDSORTPOINT3NAME" VARCHAR2(8), "NWKPCDSORTPOINT4TYPE"
VARCHAR2(8), "NWKPCDSORTPOINT4NAME" VARCHAR2(8), "NWKPCDPPI"
VARCHAR2(8), "NWKPCDBARCODE1TO7" VARCHAR2(7),
"NWKPCDBARCODE15" VARCHAR2(1), "NWKPCDBARCODESEQKEY"
VARCHAR2(7), "NWKPCDFILLER1" VARCHAR2(7), "NWKPCDFILLER2"
VARCHAR2(30))
TABLESPACE "WH1_DATA_LARGE" PCTFREE 10 PCTUSED 40 INITRANS 1
MAXTRANS 255
STORAGE ( INITIAL 4096K NEXT 4096K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
NOLOGGING
INSERT INTO WH1.NWKPCDREC SELECT
NWKPCDFILECODE,
NWKPCDRECORDTYPE,
NWKPCDNETWORKID,
rpad(nvl(nwkpcdoutwdpostcode, ' '), 4, ' ') || rpad(nvl(nwkpcdinwdpostcode, ' '), 3, ' '),
nwkpcdoutwdpostcode,
nwkpcdinwdpostcode,
NWKPCDSORTPOINT1CODE,
NWKPCDSORTPOINT1TYPE,
NWKPCDSORTPOINT1NAME,
NWKPCDSORTPOINT1EXTRA,
NWKPCDSORTPOINT2TYPE,
NWKPCDSORTPOINT2NAME,
NWKPCDSORTPOINT3TYPE,
NWKPCDSORTPOINT3NAME,
NWKPCDSORTPOINT4TYPE,
NWKPCDSORTPOINT4NAME,
NWKPCDPPI,
NWKPCDBARCODE1TO7,
NWKPCDBARCODE15,
NWKPCDBARCODESEQKEY,
NWKPCDFILLER1,
NWKPCDFILLER2
FROM WH1.NWKPCDREC_OLD;
CREATE UNIQUE INDEX "WH1"."UK_NWKPCDREC"
ON "WH1"."NWKPCDREC" ("NWKPCDNETWORKID",
"NWKPCDOUTINWDPOSTCODE")
TABLESPACE "WH1_INDEX" PCTFREE 10 INITRANS 2 MAXTRANS
255
STORAGE ( INITIAL 8192K NEXT 8192K MINEXTENTS 1 MAXEXTENTS
2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1)
LOGGING
begin
dbms_stats.gather_table_stats(ownname=> 'WH1', tabname=> 'NWKPCDREC', partname=> NULL);
end;
begin
dbms_stats.gather_index_stats(ownname=> 'WH1', indname=> 'UK_NWKPCDREC', partname=> NULL);
end;
SELECT decode(a.nwkpcdoutinwdpostcode, rpad(nvl(:zipout1, ' '), 4, ' ') ||
rpad(nvl(:zipin1, ' '), 3, ' '), '0001', rpad(nvl(:zipout2, ' '), 4, ' '
) || rpad(substr(nvl(:zipin2, ' '), 0, 1), 3, ' '), '0002', rpad(
nvl(:zipout3, ' '), 7, ' '), '0003', rpad('ZZ999', 7, ' '), '0004') AS
checker, a.nwkpcdbarcode1to7 nwkpcdbarcode1to7,
a.nwkpcdbarcode15 nwkpcdbarcode15,
a.nwkpcdbarcodeseqkey nwkpcdbarcodeseqkey,
a.nwkpcdsortpoint1code nwkpcdsortpoint1code,
a.nwkpcdsortpoint1type nwkpcdsortpoint1type,
a.nwkpcdsortpoint1name nwkpcdsortpoint1name,
a.nwkpcdsortpoint1extra nwkpcdsortpoint1extra,
a.nwkpcdsortpoint2type nwkpcdsortpoint2type,
a.nwkpcdsortpoint2name nwkpcdsortpoint2name,
a.nwkpcdsortpoint3type nwkpcdsortpoint3type,
a.nwkpcdsortpoint3name nwkpcdsortpoint3name,
a.nwkpcdsortpoint4type nwkpcdsortpoint4type,
a.nwkpcdsortpoint4name nwkpcdsortpoint4name,
b.nwkprfnetworksequence nwkprfnetworksequence,
b.nwkprfnetworkid nwkprfnetworkid, b.nwkprfnetworkname nwkprfnetworkname,
b.nwkprfminweight / 100 AS nwkprfminweight, b.nwkprfmaxweight / 100 AS
nwkprfmaxweight, b.nwkprfminlengthgirth nwkprfminlengthgirth,
b.nwkprfmaxlengthgirth nwkprfmaxlengthgirth,
b.nwkprfminlength nwkprfminlength, b.nwkprfmaxlength nwkprfmaxlength,
b.nwkprfparceltypecode nwkprfparceltypecode,
b.nwkprfparceltypename nwkprfparceltypename
FROM wh1.nwkpcdrec a, wh1.nwkprefrec b
WHERE a.nwkpcdnetworkid = b.nwkprfnetworkid
AND a.nwkpcdoutinwdpostcode IN (rpad(nvl(:zipout4, ' '), 4, ' ') ||
rpad(nvl(:zipin3, ' '), 3, ' '), rpad(nvl(:zipout5, ' '), 4, ' ')
|| rpad(substr(nvl(:zipin4, ' '), 0, 1), 3, ' '), rpad(nvl(:zipout6,
' '), 7, ' '), rpad('ZZ999', 7, ' '))
AND a.nwkpcdsortpoint1type != 'XXXXXXXX'
AND :weight1 >= b.nwkprfminweight
AND :weight2 <= b.nwkprfmaxweight
AND b.nwkprfminlengthgirth <= 60
AND b.nwkprfmaxlengthgirth >= 60
AND b.nwkprfminlength <= 15
AND b.nwkprfmaxlength >= 15
ORDER BY b.nwkprfnetworkid, checker
pre modified script/ -
MS Access querying SQL Server: How to configure Network ACL?
I need to set up a highly restrictive ACL for access to a particular SQL server in our network. This ACL will reside on our core switch at the "front door" of our network and permit access to the SQL server only using the ports that
are necessary. The purpose is to A) Try to keep unauthorized users from gaining access to the host server and B) Should someone somehow gain unauthorized access to the host server. keep them from being able to "hop off" to other PC's on
the network.
The server will be accessed by clients using MS Access to query the SQL database and bring back reports. A few admins are actually able to make minor changes to the database such as updating a user list or location list. In other words, both
read and write access is needed to the SQL database.
I know that the default SQL server port is 1433, but according to a Microsoft Support article I read, "client ports are assigned a random value between 1024 and 5000".
I was really hoping I could just put something like "permit PC1 access to SQL Server on Port 1433" in my ACL, but after reading the MS Support article it sounds like I've got to allow almost 4,000 ports through?
Could someone help demystify this for me so I can build the right ACL?The tool to use is SQL Server Configuration Management.
But what you can configure is which port SQL Server listens to. Which port the client listens to is not controllable as far as I know. But that can of course be many, since a client can have many connections to SQL Server. (And the range is not
restricted to 1024-5000. I connected over TCP locally, and I see this with netstat -a
TCP 127.0.0.1:6621 NATSUMORI:ms-sql-s ESTABLISHED
Then again, I don't see why you would have to open any ports for the clients at all. I have never heard of this being a problem.
Erland Sommarskog, SQL Server MVP, [email protected] -
Custom report of Full SQL Server Installation using ConfigMgr 2012 R2
I am trying to create a custom SQL report that would return servers and workstations that have a full version of SQL installed. The queries I try return clients that have the management tools and etc installed, but I just need a report that shows full
installations. SQL versions in my environment range from 2005 to 2014. Any help is appreciated. Thanks!For some good information about your SQL installation you can use something like this:
http://www.mnscug.org/blogs/sherry-kissinger/328-installed-sql05-sql08-sql12-sql14-version-information-via-configmgr-hardware-inventory
My Blog: http://www.petervanderwoude.nl/
Follow me on twitter: pvanderwoude
Maybe you are looking for
-
How can I put music on my iPod onto my new iTunes?
I have a bunch of music on my iPod, but I cannot copy it from my iPod onto my new current version of iTunes. I got the music from my old computer and old iTunes set up and now when I want to put the music from my iPod to my new computer iTunes, it is
-
Messages sent on iPhone not displaying correctly in Entourage sent messages
Hi. I was really looking forward to "full Exchange support" on my iPhone, but am unhappy to report that that's not what I've got. When I send messages from my iPhone and Entourage imports them into the sent messages folder via Active Sync, the messag
-
Sending IDoc to Non-SAP system
Hi Folks, I have to send an IDoc to the external system. Kindly let me know the steps to be performed for it. Reagrds, santosh
-
Clicking a Link opens old websites in Firefox 4.0 Help?!
Basically... say I click on a link while im on a flash-game or something similar and then the link opens in a new window, the link will open a new page in Firefox (which is fine...) but then will open my last visited page instead of opening the link
-
Morning, I am looking to merge polygons together in order to create a boundary that encapsulates them. Can anyone point me in the right direction for material covering problems of this nature. I have browsed the forums extensivley however, solutions