Query in days

Dear gurus,
I'm under query below for more than 20 hours now and it is still ongoing.

SELECT clnt,
sg_cd,
bg_dt,
end_dt,
working_days (submit_dt, process_dt) AS working_days
OF prc_clms
WHERE sg_cd IN ('2', '3', '12', '15',' 16', ' 18')
AND (TO_DATE('31-JAN-13') - bg_dt) < = 450
AND amount_paid > 0;

-as the elongated table (prc_clms) contains about 280 Mill record and this table is partitioned index BITMAP.
-I am computer workng days by using the function working_days (submit_dt, process_dt)

Please let me know if something is missing in my query, or anything that should not be used.

Any advise is much appreciated!
JP

Tags: Database

Similar Questions

  • Query (no, day, Date)

    Hello

    This query shows how many days

    Select level as dow, to_char (trunc (: P_date, 'day') + level - 1, 'day', 'NLS_DATE_LANGUAGE = ARABIC') as day, TO_DATE (: P_date, "dd-mm-rrrr") + T2D rownum-1 of dual connect by level < = 7;

    I want to change the query starting with

    7 Saturday date Saturday

    1 Sunday Sunday date

    2 Monday Monday date

    3 Tuesday

    and so on.

    Amatu Allah.

    Hello

    I see it; you want to spend 2 parameters DATE (start date and an end date) and generate a result set contains a line for each day in this range.

    In response #5, Kendeeny showed how to generate the 7 dates starting at a given date.  You can change that to generate however many you need, based on 2 parameters, as follows:

    WITH the settings THAT

    (

    SELECT TO_DATE (December 19, 2015 ", 'DD-MM-YYYY') AS first_date

    , TO_DATE (27 December 2015 ", 'DD-MM-YYYY') AS last_date

    OF the double

    )

    SELECT the LEVEL - 1 AS day_name + first_date

    OF parameters

    CONNECT BY LEVEL<= 1="" +="" last_date="" -="">

    ;

    It produces just the DATEs:

    DAY_NAME

    ----------

    19/12/2015

    20/12/2015

    21/12/2015

    22/12/2015

    23/12/2015

    24/12/2015

    25/12/2015

    26/12/2015

    27/12/2015

    Now, we must add the other 2 columns we want.

    DAY_ID DAY_DATE DAY_NAME

    ---------- --------- ----------

    7 Saturday, December 19, 2015

    1 Sunday, December 20, 2015

    2 Monday, December 21, 2015

    3 Tuesday, December 22, 2015

    4 Wednesday, December 23, 2015

    5 Thursday, December 24, 2015

    6 Friday, December 25, 2015

    7 Saturday, December 26, 2015

    1 Sunday, December 27, 2015

    The day_date column is easy using TO_CHAR.

    Day_id is more complicated.  Here's a way to do it, using the TRUNC:

    WITH the settings THAT

    (

    SELECT TO_DATE (December 19, 2015 ", 'DD-MM-YYYY') AS first_date

    , TO_DATE (27 December 2015 ", 'DD-MM-YYYY') AS last_date

    OF the double

    )

    got_d AS

    (

    SELECT the LEVEL - 1 AS d + first_date

    OF parameters

    CONNECT BY LEVEL<= 1="" +="" last_date="" -="">

    )

    SELECT 2 + d - TRUNC (d + 1, 'IW') AS day_id

    TO_CHAR (d

    , 'Day '.

    -, ' NLS_DATE_LANGUAGE = ARABIC '.

    ) AS day_date

    , TO_CHAR (d, 'dd-mm-yyyy') AS day_name

    OF got_d

    ORDER BY d

    ;

    TRUNC (d, 'IW') returns later Monday less than or equal to d.  This is a handy feature, and it is independent of the settings NLS_DATE_LANGUAGE and NLS_TERRITORY.

    d - TRUNC (d, 'IW') maps the days of the week to consecutive integers, but it assigns the lowest value on Monday.  We want Sunday to have the lowest number, so I used

    d - (TRUNC (d + 1, 'IW') instead.)  The 'magic number' 1 reflects the fact that Monday is a day after the Sunday.  It returns a number in the range from-1 to 5, but we want numbers in the range 1 to 7, that is exactly 2 more, so add 2.

  • Range query date day 1 to day 1-14 years

    I use:

    Oracle SQL Developer (3.0.04)

    Build hand - 04.34

    Oracle Database 11g

    Enterprise Edition 11.2.0.1.0 - 64 bit Production

    I'll have time to diffitult get this filter works:

    {Code}

    where date_value between: day1 and: day 1-14

    {Code}

    What I am doing wrong?

    I am looking for a single day of entry and have it return a range of 14 days. So if I put "June 25, 2013", it must understand that day and the 14 day return track.

    Hello

    When you say "BETWEEN x AND y", x must be the smallest value.

    You need something like:

    WHERE the date_value BETWEEN day 1 - 14 AND day 1

    This assumes that the date_value and day1 are DATEs.  There is no variable binding DATE.  "If: day 1 is a string, such as June 25, 2013", then use TO_DATE to get a DATE based on this string:

    WHERE the date_value BETWEEN TO_DATE (: day1, "MON-DD-YYYY")-14

    AND TO_DATE (: day1, 'DD-MON-YYYY')

  • The query makes a full table scan?

    I have a simple select query that filters on the last 10 or 11 days of data in a table. In the first case, it runs in 1 second. In the second case it takes 15 minutes and still not done.

    I can say that the second query (11 days) makes a full table scan.
    -Why is this happening? ... I guess some kind of threshold?
    -Are there a way to avoid this? ... or encourage Oracle to play nice.

    I find confusing from the point of view before end/query to get very different performances.

    Jason
    Oracle 10g
    Toad quest 10.6

    CREATE TABLE delme10 AS 
    SELECT *
    FROM ed_visits
    WHERE first_contact_dt >= TRUNC(SYSDATE-10,'D');
    
    Plan hash value: 915912709
    
    --------------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------
    |   0 | CREATE TABLE STATEMENT       |                   |  4799 |  5534K|  4951   (1)| 00:01:00 |
    |   1 |  LOAD AS SELECT              | DELME10           |       |       |            |          |
    |   2 |   TABLE ACCESS BY INDEX ROWID| ED_VISITS         |  4799 |  5534K|  4796   (1)| 00:00:58 |
    |*  3 |    INDEX RANGE SCAN          | NDX_ED_VISITS_020 |  4799 |       |    15   (0)| 00:00:01 |
    --------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - access("FIRST_CONTACT_DT">=TRUNC(SYSDATE@!-10,'fmd'))
    
    
    CREATE TABLE delme11 AS 
    SELECT *
    FROM ed_visits
    WHERE first_contact_dt >= TRUNC(SYSDATE-11,'D');
    Plan hash value: 1113251513
    
    -----------------------------------------------------------------------------------------------------------------
    | Id  | Operation              | Name      | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    -----------------------------------------------------------------------------------------------------------------
    |   0 | CREATE TABLE STATEMENT |           | 25157 |    28M| 14580   (1)| 00:02:55 |        |      |            |
    |   1 |  LOAD AS SELECT        | DELME11   |       |       |            |          |        |      |            |
    |   2 |   PX COORDINATOR       |           |       |       |            |          |        |      |            |
    |   3 |    PX SEND QC (RANDOM) | :TQ10000  | 25157 |    28M| 14530   (1)| 00:02:55 |  Q1,00 | P->S | QC (RAND)  |
    |   4 |     PX BLOCK ITERATOR  |           | 25157 |    28M| 14530   (1)| 00:02:55 |  Q1,00 | PCWC |            |
    |*  5 |      TABLE ACCESS FULL | ED_VISITS | 25157 |    28M| 14530   (1)| 00:02:55 |  Q1,00 | PCWP |            |
    -----------------------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       5 - filter("FIRST_CONTACT_DT">=TRUNC(SYSDATE@!-11,'fmd'))

    This seems to change the plan to explain it...

    alter session set optimizer_index_cost_adj=10;
    
  • Can I create a recovery disc in a drive that already contains data?

    I went through this link "http://windows.microsoft.com/en-in/windows-8/create-usb-recovery-drive".

    It is said that when I create the recovery USB drive, old data in USB will be removed is even a hard drive?

    Can I create the recovery drive into a USB port and which copy to hard drive and use the HDD when necessary for recovery?

    Please help me to understand the working of recovery mechanism in Windows 8.

    Thank you

    Ananth

    Hello

    Yes that is right that the recovery disk is created on a sterile USB drive. Do not put any other data after the creation of the disc of recovery in this matter, otherwise it can not work properly.

    I hope that answers your query, good day!

  • Why performance changes with the same conditions

    Hello everyone,

    I created an analysis and give filters as below;

    Tarih.Year = 2015

    Tarih.Month = 7

    Tarih.LastDayOfMonthFlag = 1

    Therefore, I want to display the values of date 31/07/2015 (mm/dd/yyyy). However, the analysis run punctuality is so bad when I use these filters

    "On the other hand, when I give the filter for Tarih.Date = July 31, 2015", then the analytical results are seen immediately in one second.

    Why the same conditions differ in the execution of the terms? Can you help me please.

    Kind regards

    Dilek

    Hi Dilek,

    While logically, this looks like the same query ("last day of July" vs "31 July") they'll be different queries in OBIEE, resulting from the different performance characteristics. Perhaps a strike a different logical Table (LTS), perhaps including different physical Source tables in a join, perhaps a hundred different maybes :-)

    You must compare the logical and physical SQL that is executed as a result of your two queries. You can find this in the nqquery.log file - if it is not there then use SET LOGLEVEL setting logging for 2 (Google is your friend, for more details).

    Compare the time spent in the database on the two motions; What's a bigger than the other? Or is the time spent in the BI server after data is returned from the DB? Whatever it is, you probably need to change your SPR so that he "understands" (i.e. the logic model is mapped optimal) this way to combine date objects you have.

  • PHP - delete multiple records in the database by using the checkboxes?

    It took zillions of times over the years, BUT my Google search has been exhausted. I can't find a coherent tutorial or explanation on how to do this.

    Someone else has a link to a tutorial?

    I found and implemented, with a few tweaks, which updates several records of price field. Most likely the removal works in a similar way, by making a loop on all records, but can't get my head around it for the moment.

    See you soon

    Operating system.

    OK, even once, the warning I ever wrote a single php page. But try this.

    Once again, use it for your form fields in the repeat region.

    and for your delete statement

    {foreach ($_POST ['action'] as $dayID)}

    $query = 'DELETE days WHERE the dayID = $dayID;

    mysql_query ($Query) or die ("' error in query: $query '");

    }

    > The data type for the field of dayID is int, is the primary car key.

    FYI - given that the data type is numeric, you do not need to pack quotes around it.

  • Two Union queries and get a value

    Hello... I am new in programming... need help... I have a union like this query...

    Select tb_user.userid,
    Day NVL ((Sum (TB_class. (Time)), 0) AS
    Tb_user, TB_class, TB_classcon, TB_DETAIL, TB_partner, tbl_department
    where TB_classcon.userid = tb_user.userid
    AND TB_classcon. IDDETAIL = TB_DETAIL. IDDETAIL
    AND TB_DETAIL. IDpartner = TB_partner. IDpartner
    AND TB_partner.code = TB_class.code
    and tbl_department.deptcode = tb_user.deptcode
    and tb_user.deptcode = '70'
    AND to_char (TB_DETAIL.statdate, 'YYYY') = 2011
    AND TB_classcon. STATUS = "arrived."
    Tb_user.userid group

    UNION

    Select tb_user.userid,
    (SELECT NVL ((SUM (TB_KURBAH.time)), 0) FROM TB_KURBAH WHERE TB_KURBAH.) IDSTAF = tb_user.userid) AS day
    OF tb_user, TB_class, TB_classcon, TB_DETAIL, TB_partner, tbl_department, TB_KURBAH
    where TB_KURBAH.userid! = tb_user.userid
    AND TB_classcon. IDDETAIL = TB_DETAIL. IDDETAIL
    AND TB_DETAIL. IDpartner = TB_partner. IDpartner
    AND TB_partner.code = TB_class.code
    and tbl_department.deptcode = tb_user.deptcode
    and tb_user.deptcode = '70'
    AND to_char (TB_DETAIL.statdate, 'YYYY') = 2011
    AND TB_classcon. STATUS = "arrived."
    Tb_user.userid group

    Result

    day of the user ID
    33478 5
    33478 6
    8 33500
    3 33655
    34260 0
    34260 2

    Result of the query 1
    day of the user ID
    33478 6
    34260 2

    2 query result
    day of the user ID
    3 33655
    33478 5
    8 33500
    34260 0

    But I need help to get the result like this...

    day of the user ID
    33478 11 (6 + 5)
    33500 8 (0 + 8)
    3 33655 (0 + 3)
    34260 2 (2 + 0)

    Help me please... tq...

    Wrap your query

    select userid, sum(day) from (
    
    your query
    
    )
    group by userid
    
  • Current month

    I can't this month IE for now his ' 05 "(May) this expression."

    SELECT case when 1 = 0 then 'time of the query. Day of another timestampadd (sql_tsi_day,-1, current_date) end "use Tracking.

    Or want to anyway I can get the month cuurent to display in my promt.i ' 05 "

    Please notify

    Thank you
    Bhupendra Gupta

    Hey

    Try this...

    SELECT case when 1 = 0 then 'time of the query. "" Another month number month ' (timestampadd (sql_tsi_day,-1, current_date)) end "use Tracking.

  • Need default date (current date - 1) prompt

    Hello

    I have a command prompt in which there is a schedule that is associated with a filter
    I have need of Defalut date to be defined as (sysdate - 1).
    Can you please let me know how can I do this?

    Thank you
    Bhupendra Gupta

    Kishore Guggilla wrote:
    instead of cast (null as the date), use any existing date column that is in the database...

    For example: SELECT case when 1 = 0 then 'time of the query. Day of another timestampadd (sql_tsi_day,-1, current_date) end "use Tracking.

    'Time to queries ". Date is a date column in the subject area 'Use Tracking'...

  • A design of query for the conversion of time difference in days, hours, Minutes

    Hi all

    A design of query for the conversion of time difference of time in number of days remaining remaining hours minutes and rest in seconds. Made this one till now. Please suggest for all modifications, until now, it seems to work very well, kindly highlight for any anomaly.

    WITH DATA (startDAte, EndDate, Datediff) AS (SELECT to_date ('2015-10-01 10:00:59 ',' yyyy-mm-dd hh24:mi:ss'), to_date ('2015-20-01 03:00:49 ',' yyyy-mm-dd hh24:mi:ss'), to_date('2015-10-01 10:00','yyyy-dd-mm hh24:mi:ss')-to_date('2015-20-01 03:00','yyyy-dd-mm hh24:mi:ss') FROM dual)

    UNION ALL SELECT to_date ('2015-10-01 10:00:39 ',' yyyy-mm-dd hh24:mi:ss'), to_date ('2015-20-01 03:00:40 ',' yyyy-mm-dd hh24:mi:ss'), to_date('2015-10-01 10:00','yyyy-dd-mm hh24:mi:ss')-to_date('2015-20-01 03:00','yyyy-dd-mm hh24:mi:ss') FROM dual

    UNION ALL SELECT to_date ('2015-11-01 10:30:45 ',' yyyy-mm-dd hh24:mi:ss'), to_date ('2015-11-01 11:00:50 ',' yyyy-mm-dd hh24:mi:ss'), to_date('2015-11-01 10:30','yyyy-dd-mm hh24:mi:ss')-to_date ('2015-11-01 11:00 ',' yyyy-mm-dd hh24:mi:ss') FROM dual

    UNION ALL SELECT to_date ('2015-11-01 09:00:50 ',' yyyy-mm-dd hh24:mi:ss'), to_date ('2015-11-01 10:00:59 ',' yyyy-mm-dd hh24:mi:ss'), to_date('2015-11-01 09:00','yyyy-dd-mm hh24:mi:ss')-to_date ('2015-11-01 10:00 ',' yyyy-mm-dd hh24:mi:ss') FROM dual

    UNION ALL SELECT to_date ('2015-11-01 08:30:49 ',' yyyy-mm-dd hh24:mi:ss'), to_date ('2015-11-01 09:30:59 ',' yyyy-mm-dd hh24:mi:ss'), to_date('2015-11-01 08:30','yyyy-dd-mm hh24:mi:ss')-to_date('2015-11-01 09:30','yyyy-dd-mm hh24:mi:ss') FROM dual

    )

    Select

    trunc ((EndDate-StartDate)) days.

    trunc (((enddate-startdate)-to_number (trunc ((enddate-startdate))) * 24) hours)

    trunc (to_number (((enddate-startdate)-to_number (trunc ((enddate-startdate))) * 24-trunc (((enddate-startdate)-to_number (trunc ((enddate-startdate))) * 24)) * 60) Minutes,))

    (to_number (((enddate-startdate)-to_number (trunc ((enddate-startdate))) * 24-trunc (((enddate-startdate)-to_number (trunc ((enddate-startdate))) * 24)) * 60 - trunc (to_number (((enddate-startdate)-to_number (trunc ((enddate-startdate))) * 24-trunc (((enddate-startdate)-to_number (trunc ((enddate-startdate))) * 24)) * 60)) * 60 seconds))))

    data;

    Thanks for the answers in advance.

    AHA!

    TO_TIMESTAMP expects a string as input, so it first makes an implicit conversion from DATE to a string, in the format of NSL_DATE_FORMAT.

    To convert the TIMESTAMP DATE independently NLS_DATE_FORMAT, use

    CAST ( AS TIMESTAMP)

  • query for the first day of the month

    Hi all

    How to get the first day of the month in the sql query.

    SQL> select trunc(sysdate,'mm') first_day from dual;
    
    FIRST_DAY
    ---------
    01-AUG-15
    
    SQL> select trunc(sysdate,'month') first_day  from dual;
    
    FIRST_DAY
    ---------
    01-AUG-15
    
    SQL> select trunc(sysdate,'mon')  first_day from dual;
    
    FIRST_DAY
    ---------
    01-AUG-15
    
    SQL>
    
  • How to display the use of temporary space using OEM for a query that is run on a specific day

    Where scroll in OEM to get the temp space, total used by a query that is run on a day specific/tiime.

    --> PERFORMANCE--> SQL MONITORING DATABASE--> find your sql performance ()--> click the status-->

    --> METRICS DETAILS click--> you will give details on the temporary use.

    (2) see the report--> you will give more details,

    Thank you

    Concerning

    Krishnan

  • Clarification of the SQL query in 2 day + Guide APEX

    I worked through the Oracle Database Express Edition 2 day + Application Express Developer's Guide, and try to decipher the SQL query in Chapter 4 (building your app).

    The code is:

    SELECT d.DEPARTMENT_ID,

    d.DEPARTMENT_NAME,

    (select count (*) from oehr_employees where department_id = d.department_id)

    "Number of employees", he said.

    substr (e.first_name, 1, 1) |'. ' || Select 'Name Manager',

    c.COUNTRY_NAME 'place '.

    OEHR_DEPARTMENTS d,

    E OEHR_EMPLOYEES

    OEHR_LOCATIONS l,

    C OEHR_COUNTRIES

    WHERE d.LOCATION_ID = l.LOCATION_ID

    AND l.COUNTRY_ID = c.COUNTRY_ID

    AND e.department_id = d.DEPARTMENT_ID

    AND d.manager_id = e.employee_id

    AND instr (superior (d.department_name), superior (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0)

    I don't know exactly what is happening in the last line. I think I understand what the different functions but I'm not clear on the use of the: P2_REPORT_SEARCH string.

    What does this string? This code simply checking that d.department_name isn't NA?

    I have SQL experience but am not very familiar with the Oracle PL/SQL implementation. Can someone please give me a brief breakdown that check is doing in the context of the overall query? The application seems to work even if the conditional statement is not included.

    Thank you.

    2899145 wrote:

    Thanks for the reply. I apologize if the information I added was incomplete. The code came from the day 2 + Application Express (version 4.2) Developer Guide.

    In the section 'your own Application of 4 Buuilding' https://docs.oracle.com/cd/E37097_01/doc.42/e35122/build_app.htm#TDPAX04000 , they describe the creation of a report

    page that includes the "manager_id" and 'location_id '. The SQL query, I pasted above extracted from the data in other tables to substitute the real 'name of the Manager' and 'rent '.

    for the corresponding ID values. It makes sense, and the part of the SQL query that explicitly doing this makes sense.

    However, given that the document is a guide for the development of the APEX, I guess the command:

    AND instr (upper (d.department_name), upper (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0

    done something valuable, and I do not recognize what is exactly the value.

    From a practical point of view why would I need to include this conditional statement?  Which only added to the application?

    Looking at the guide in question, it is clear that the

    AND instr(upper(d.department_name),upper(nvl(:P2_REPORT_SEARCH,d.department_name)))>0
    

    the line is completely unnecessary in the context of this tutorial, and it can be removed. The search in the tutorial app page is implemented by using a report filter interactive rather than a P2_REPORT_SEARCH element, which does not seem to exist at all. (It's a quirk of the APEX that bind variable references to non-existent items are replaced with NULL silently rather than exceptions). I thought that perhaps it would be legacy code a version of the tutorial prior to the introduction of interactive reports at the APEX 3.1, but I can't find explicit instructions to create such an element of filter in the 3.0 tutorial. I guess it must have been automatically generated by the application wizard when you create a standard report page.

    If you do not want to see the effect he would have (as described in the post above), leave it in the source report, add a text element of P2_REPORT_SEARCH, and a button "submit" on page 2 and experimenting to find different values of the element and clicking on the submit button...

  • SQL Query to extract data between days and hours

    Hi friends,

    I need, it's for a report.

    Description of the requirement:

    Need of data in a table located in an OPEN State for more than 30 minutes

    Well, this requirement can be obtained from

    Select * from xyz where status = 'OPEN' and last_update_date < = sysdate---30 (30/1440) minutes and it is a parameter

    the query above will search all data that are in the OPEN State beginning to sysdate - (30/1440). So I want to change the query to restrict the data, by adding another parameter as DAY

    for example if I give 10 day, it should recover all the data only within 10 days and sysdate-30 minutes.

    We use the last_update_date column to restrict the day.

    If I do not give any date for entry must retrieve all records of sysdate-30 minutes.

    If I don't give minutes that he must retrieve all the records in the OPEN State.

    is the question clear enough? my English is bad.

    Please suggest me a query...

    Thank you and best regards,

    Arun Thomas T

    Hello

    Select * from xyz where status = 'OPEN' and

    last_update_date between nvl (sysdate -: days, last_update_date) and nvl2 (: days, last_update_date, nvl (sysdate -: minutes/1440, last_update_date));

    that should be:

    If the days parameter is entered then start - days of sysdate and end up last_update_date

    If days is not entered then boot from the begingin and put end to:

    1 sysdate -: minutes/1440 if minutes are entered

    2. up to the last_update_date if the minutes are not entered

Maybe you are looking for

  • Changed the name of data

    SUMIFS (data: $C, data: $B, $A2, given: $A, "> =" & B$ 1, data: $A, "<" & (EOMONTH(A1,0) will GET ($1.0 B) + 1)) It's the formula that I used until I changed the names of "data Plan". The original names were: A1 A6 A12 B1 B6 etc... I changed the plan

  • How can move the data from 10.4.11 to El Capitan?

    I recently acquired a new iMac running El Capitan. My previous iMac is a 20 "G5 iSight running 10.4.11 - I have about 200 GB of music (in iTunes) and photos (in iPhoto) and various other documents and records I want to store and access on the new iMa

  • Connect to win8

    Hi all I recently bought a new laptop, win8 running (my previous one ran win7). in the past I used to connect to Skype by using my Skype name, win8, the login screen requires email address. I tried to use the email associated with my account (as it a

  • Satellite P200 - 10G - some programs do not work

    Hello world. OK, so we have a record of product recovery and we have tried to reinstall Windows, but it wouldn't work. Some of our programs as the built-in webcam and Bluetooth don't work without reason. Other programs like Google Earth and AVG, anti

  • Satellite A200 - only flashing cursor upper left corner

    Hi, please help. So, I have a Toshiba Satellite A200. After giving windows 7 a go for a few weeks on this machine, I get an update message 'new chipset drivers available' Yay! So to install these drivers, I have to restart the laptop computer for the