SQL query to get the dates between two dates
Hello
We have a chart with start date and end date... Now I need to get all the dates between the start date and end date...
Table looks to below...
Create the table date_table (start_date, end_date date);
The table data will be as below:
start_date end_date
January 1, 2013 January 4, 2013
February 1, 2013 February 3, 2013
............... .................
............... ..................
............... .................
May 1, 2013 may 3, 2013
I want a result like below...
holiday_dates
January 1, 2013
January 2, 2013
January 3, 2013
January 4, 2013
February 1, 2013
February 2, 2013
February 3, 2013
.................
.................
.................
.................
May 1, 2013
May 2, 2013
May 3, 2013
Can anyone help... ?
Ramesh9158 wrote:
Hello
Your query will not work for our case...
First... We do not know the number of rows in the table... If we cannot use the union...
Second... hard coding of dates... but we do not know what could be that goes back in the table... it could be no matter what it takes not only as appearing to the interpreter...
Hey riri.
My code will work everywhere I use with with union all statement to create the example data.
Try the query:
-The main query
Select d1 + row_number() over (partition by iden) - stopped by iden holiday 1
Of
connect by level<= d2="" -="" d1="" +="">=>
and prior iden iden =
and prior sys_guid() is not null
----
Ramin Hashimzade
Tags: Database
Similar Questions
-
Dynamic action - Get the difference between two dates + times
I have problems a little dynamic to work action. I'm trying to get the time between two dates with the time difference.
Here is what I got (this is apex 4.0):
Two date pickers + two numbers fields (date/start/end times)
I created a dynamic action on the page who fires on the point lose focus (above points).
The real action for the DA is the body of the PL/SQL function:
When I change the values on the page, I get the following error:declare end_date DATE; start_date DATE; Begin start_date := to_char(:P1_START_DATE || ' ' || :P1_START_TIME, 'DD-MON-YYYY HH:MIAM'); end_date := to_char(:P1_END_DATE || ' ' || :P1_END_TIME, 'DD-MON-YYYY HH:MIAM'); :P1_HOURS := end_date-start_date; End;
AJAX call back Server error ORA-06502: PL/SQL: digital or value error: character number conversion error to set the value.
I'm guessing that there is a problem with the date formatting, but I can't make it work. Thanks in advance!Hi djston,
because you chose the dynamic action of 'Set value' with the "Body of the PL/SQL function" type you need to return the value. Try the following code
declare end_date DATE; start_date DATE; Begin start_date := to_date(:P1_START_DATE || ' ' || :P1_START_TIME, 'DD-MM-YYYY HH:MIAM'); end_date := to_date(:P1_END_DATE || ' ' || :P1_END_TIME, 'DD-MM-YYYY HH:MIAM'); RETURN (end_date-start_date)*24; End;
and P1_REQUESTED_HOURS like 'item affected. "
Concerning
Patrick
-----------
My Blog: http://www.inside-oracle-apex.com
APEX 4.0 Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolfPublished by: Patrick Wolf on January 17, 2011 10:54
-
How to write a simple select query to get the data of the table as an XML.
How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select queryselect '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' from temp_table where id_num BETWEEN 1 AND 10;
without using XMLGEN, XMLQUERY or any other packages built and function?I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.
What is wrong with him?
At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:SQL> create or replace function my_url_escape (url in varchar2) 2 return varchar2 3 deterministic 4 is 5 begin 6 return utl_url.escape(url, false, 'AL32UTF8'); 7 end; 8 / Function created SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual; MY_URL_ESCAPE('HTTP://SOME.URI -------------------------------------------------------------------------------- http://some.uri.com/param?lang=fr&text=contr%C3%B4le
-
SQL query to get the NULL records after the last matching flag
I have a xx1 table with id and flag columns. So I want the data in this table, after the last flag matched. I want that data to id 7 in the rooms. Even if the id 2,3,5 are null flag 'Y' was at 6. ID so I need a query to get the data of the xx1 table after the last correspondence flag (from 7 to 9 id).
SQL > create table xx1
2 (identification number,
3 flag varchar2 (10));
Table created.
SQL > insert into xx1 values (1, 'Y');
1 line of creation.
SQL > insert into values xx1 (2, null);
1 line of creation.
SQL > insert into values xx1 (3, null);
1 line of creation.
SQL > insert into xx1 values (4, 'Y');
1 line of creation.
SQL > insert into values xx1 (5, null);
1 line of creation.
SQL > insert into xx1 values (6, 'Y');
1 line of creation.
SQL > insert into values xx1 (7, null);
1 line of creation.
SQL > insert into values xx1 (8, null);
1 line of creation.
SQL > insert into values xx1 (9, null);
1 line of creation.
SQL > select * from xx1.
FLAG OF THE ID
---------- ----------
1. IS
2
3
4. IS
5
6. IS
7
8
9
9 selected lines.
SQL >
Hello
user11164339 wrote:
Hi Frank - when I run the query, I don't see the results data.
I get
FLAG OF THE ID
----- ----------
7
8
9
What you do differently?
-
Need a sql query to get several dates in rows
Hi all
I need a query to get the dates of the last 7 days and each dates must be in a line...
but select sysdate double... gives a line...
Output of expexcted
Dates:
October 1, 2013
30 sep-2013
29 sep-2013
28 sep-2013
27 sep-2013
26 sep-2013
Try:
SQL > SELECT sysdate-7 + LEVEL FROM DUAL
2. CONNECT BY LEVEL<=>=>
3 * ORDER BY 1 DESC
SQL > /.
SYSDATE-LEVEL 7 +.
-----------------------------
October 1, 2013 13:04:52
30 - Sep - 2013 13:04:52
29 - Sep - 2013 13:04:52
28 - Sep - 2013 13:04:52
27 - Sep - 2013 13:04:52
26 - Sep - 2013 13:04:52
25 - Sep - 2013 13:04:52
7 selected lines.
-
Query to get the difference between 2 totals of 2 different queries
I wanted to know if it is possible to get the difference between 2 totals of 2 different queries. Let me explain with an example:
1 application ofst - sum (homepass) Select table 1
2th query: select sum (homepass) from table2
Is it possible to display the difference as -
Select sum (homepass) in table 1 - sum (homepass) from table2
I know that the above query would give syntax error, but is there a better way or something to get the above done task from a single query.
Hopefully, my question is clear.
Please get back with the answer to my query.
Concerning
You can always do something like
SELECT a.cnt - b.cnt FROM (SELECT sum(homepass) cnt from table1) a, (SELECT sum(homepass) cnt from table2) b
I'd be somewhat dubious, although on a data model that had two tables with the same name of the column where it really made sense to subtract one amount from each other. This would strongly imply that there should be a single table with an additional column TYPE eventually.
Justin
-
The most elegant way to get the difference between two tables - not least!
Hello
Simplified example of what I'm trying to achieve - I have two tables ORIGINAL and REVISED.
My aim is to compare the two, such as; -
When there is data in the two tables I get the difference between the Budget column, and if there is no difference, so I don't want no lines.
When data exists in the ORIGINAL, but not in review, I want to the inverse of the current value of the Budget column.
Where the data exist in REVISED I want the REVISED value.
I can see how I can do this, see below, but is there a more elegant solution?
Data for the ORIGINAL table
Data for the REVISED tableselect '801040' entity, '2186' expense_type, 234000 budget from dual union all select '801040' entity, '3001' expense_type, 1000 budget from dual union all select '801040' entity, 'P132' expense_type, 34000 budget from dual union all select '801040' entity, 'P135' expense_type, 43000 budget from dual
Desired outputselect '801040' entity, '2186' expense_type, 235000 budget from dual union all select '801040' entity, 'P132' expense_type, 34000 budget from dual union all select '801040' entity, 'P139' expense_type, 56000 budget from dual
ENTITY EXPENSE_TYPE DIFFERENCE
------ ------------ ----------
801040 2186 1000
801040 3001-1000
801040 P135-43000
801040 P139 56000
5 selected lines.
Code current to achieve this, is there a better way?
Thanks a lot for your comments,.select original.entity , original.expense_type , (nvl(revised.budget,0) - original.budget) as difference from original , revised where original.entity = revised.entity(+) and original.expense_type = revised.expense_type(+) and (nvl(revised.budget,0) - original.budget) != 0 union all select revised.entity , revised.expense_type , revised.budget as difference from revised where not exists (select 'x' from original where original.entity = revised.entity and original.expense_type = revised.expense_type) and revised.budget != 0
Robert.
Published by: Robert Angel on January 17, 2012 03:31 to change is not equal to! = - Thanks for the heads upSQL> with original 2 as 3 ( 4 select '801040' entity, '2186' expense_type, 234000 budget 5 from dual 6 union all 7 select '801040' entity, '3001' expense_type, 1000 budget 8 from dual 9 union all 10 select '801040' entity, 'P132' expense_type, 34000 budget 11 from dual 12 union all 13 select '801040' entity, 'P135' expense_type, 43000 budget 14 from dual 15 ) 16 , revised 17 as 18 ( 19 select '801040' entity, '2186' expense_type, 235000 budget 20 from dual 21 union all 22 select '801040' entity, 'P132' expense_type, 34000 budget 23 from dual 24 union all 25 select '801040' entity, 'P139' expense_type, 56000 budget 26 from dual 27 ) 28 select * 29 from ( 30 select nvl(o.entity, r.entity) entity, 31 nvl(o.expense_type, r.expense_type) expense_type, 32 nvl(r.budget,0) - nvl(o.budget,0) budget 33 from original o 34 full join revised r 35 on o.entity = r.entity 36 and o.expense_type = r.expense_type 37 ) 38 where budget <> 0 39 / ENTITY EXPE BUDGET ------ ---- ---------- 801040 2186 1000 801040 P135 -43000 801040 3001 -1000 801040 P139 56000 SQL>
-
SQL query to represent the data in the graph bar
Hello
JDev 11.1.1.5.0
We must create a dashboard to track the translation. We have created the ADF table with buttons 'Create', 'Update' and 'Delete' to manipulate the table.
Our DB table structure is
File_id (PK), File_Name, ToSpanish - ARE (YES/NO), beginning of the ToSpanish, ToChina(YES/No), ToChina-Date... etc.
Once the translated file required language then user must update the DB table using the button "Update".
So far, we have implemented the requirement above.
We need represent the status of the translation in the graph bar with the language as X access and file count get access Ex: Spanish-100 China - 200 files files
Please suggest the sql query to retrieve the necessary info from the DB table that can be represented in the graph bar. Also, it would be great, if you can provide a pointers to create a bar chart.
Thanks in advance,
MSR.
If you set your major increment and minor than 1, then you won't not show decimal points. You can try setting these 10 or 100 to reach your goal.
Subtype = "BAR_VERT_CLUST" >
-
Query to get the data of the column and the metadata in the same set of results.
Is it possible to build a query to get the values of the columns in a table and also be able to get some metadata (data type, data_length, data_precision, data_scale) for columns in the same set of results.If I use a join, have a common value to join on the two tables?
you use a cross join, not requiring common values.
create table T (n number, d date, v varchar2(30)); insert into T values (1,sysdate,'ABC'); commit; select C.column_name, c.data_type, c.data_length, case c.column_id when 1 then to_char(T.N) when 2 then to_char(T.D) when 3 then T.V end VALUE from USER_TAB_COLUMNS C, T where C.table_name='T' order by c.column_id;
-
Hello everyone,
How can I create a query having 2 date and 2 variable of the type:
Thanks in advancefrom 1 date 05/06/2004 to 2 date 15/06/2004 yes for 2 days no for 1 day that is, i wish get the date with yes for 2 days and not for 1 day, this is, that I want 05/06/2004 sabato 06/06/2004 domenica 08/06/2004 martedì 09/06/2004 mercoledi 11/06/2004 venerdi 12/06/2004 sabato 14/06/2004 lunedi 15/06/2004 martedi
Hello
The WHERE clause controls the lines will appear.
If your needs change, change the WHERE clause to reflect their.For example:
DEFINE from_date = "TO_DATE ('05/06/2004', 'DD/MM/YYYY')" DEFINE to_date = "TO_DATE ('15/06/2004', 'DD/MM/YYYY')" DEFINE yes_cnt = 3 DEFINE no_cnt = 2 SELECT &from_date + LEVEL - 1 AS dt FROM dual WHERE MOD ( LEVEL , &yes_cnt + &no_cnt ) BETWEEN 1 AND &yes_cnt CONNECT BY LEVEL <= 1 + &to_date - &from_date ORDER BY dt;
This will work as long as you want the first & yes_cnt lines to display (assuming that there are many) and the following lines & no_cnt don't step to display, and then another & yes_cnt lines to display and the other & no_cnt lines not to display and so on.
I guess & yes_cnt is a positive integer and that & no_cnt is a non-negative integer. (I.e. & no_cnt can be 0)
-
IOM sql Query to get the status of the failed task
Hello world
We have an obligation as we need to get the status of a particular task (say Create User in OID - Completed\Rejected status resource) for the particular user. We are able to get the status of the provisioed of resources to the user but not the status of the special mission which is trigerred for the user.can someone put some light on it. We must have the SQL query to do this.
Thanks in advance.
Kind regards
MKNHello
Use this query to get the status of the task, also check the coomentsSELECT USR. USR_LOGIN, OSI. SCH_KEY, ANN. SCH_STATUS, STA. STA_BUCKET OF
OSI, CHS, STA, MIL, TOS, PKG, OUEDRAOGO, USR, OBJ, OST
WHERE OSI.MIL_KEY = MIL.MIL_KEY
AND ANN. SCH_KEY = OSI. SCH_KEY
AND STA. STA_STATUS = SCH. SCH_STATUS
AND TOS. PKG_KEY = PKG. PKG_KEY
AND MIL. TOS_KEY = TOS. TOS_KEY
AND OUÉDRAOGO. USR_KEY = USR. USR_KEY
AND OUÉDRAOGO. OST_KEY = OST. OST_KEY
AND OST. OBJ_KEY = OBJ. OBJ_KEY
AND OSI. ORC_KEY = OUEDRAOGO. ORC_KEY
AND OBJ. OBJ_NAME = "User AD".
AND OST. OST_STATUS = "Provisioning" - filter accordinglly
AND STA. STA_BUCKET = 'pending' - filter accordinglly
AND PKG. PKG_NAME = "AD User" - filter accordinglly
AND MIL.MIL_NAME = 'System' - filter accordinglly Validation
;
Thank you
Kuldeep -
SQL query to get the numbers from 0 to 99
How can we write a sql query to get values from 0 to 99... This should not come from any tableSELECT LEVEL - 1 FROM DUAL CONNECT BY LEVEL <= 100 /
SY.
-
SQL query to get the range of Date values
Hello
The database is Oracle11i.
I'm looking for a way to generate a list of the dates of a fixed date in the past (could be hardcoded) at the time of the day (sysdate).
In other words, if the fixed date is June 19, 2011, and assuming today ' today is June 24, 2011 the SQL must be able to generate the
Next: -.
June 19, 2011
June 20, 2011
June 21, 2011
June 22, 2011
June 23, 2011
June 24, 2011
And the constraint is that I can not make any change to the database in question. I can only shoot a (SELECT) SQL query. NO.
use time dimension type of approach (time dimension is not available here) and no procedure, etc. from PL/SQL. Is it possible?
Thank youJaimeen Shah wrote:
HelloThe database is Oracle11i.
I'm looking for a way to generate a list of the dates of a fixed date in the past (could be hardcoded) at the time of the day (sysdate).
In other words, if the fixed date is June 19, 2011, and assuming today ' today is June 24, 2011 the SQL must be able to generate the
Next: -.
June 19, 2011
June 20, 2011
June 21, 2011
June 22, 2011
June 23, 2011
June 24, 2011And the constraint is that I can not make any change to the database in question. I can only shoot a (SELECT) SQL query. NO.
use time dimension type of approach (time dimension is not available here) and no procedure, etc. from PL/SQL. Is it possible?
Thank you
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 query to get the number of days monthwise
Hello
I'm new to sql, can someone please tell me query to find the number of days between the two dates months wise.
say
FIRSTDATE last date
21/03/2011-25/06/2011
March April May June
9 22 23 18Hello
Welcome to the forum!
Here's one way:
WITH all_dates AS ( SELECT start_date + LEVEL - 1 AS a_date FROM ( SELECT TO_DATE ('21/03/2011', 'DD/MM/YYYY') AS start_date , TO_DATE ('25/06/2011', 'DD/MM/YYYY') AS end_date FROM dual ) CONNECT BY LEVEL <= end_date + 1 - start_date ) SELECT TO_CHAR ( TRUNC (a_date, 'MONTH') , 'fmMonth YYYY' ) AS month , COUNT (*) AS num_days FROM all_dates WHERE a_date - TRUNC (a_date, 'IW') < 5 GROUP BY TRUNC (a_date, 'MONTH') ORDER BY TRUNC (a_date, 'MONTH') ;
What is a 'working day '? I guess you mean every day except Saturday or Sunday, but the query aboveare sometimes figures less than you have asked:
MONTH NUM_DAYS --------------- ---------- March 2011 9 April 2011 21 May 2011 22 June 2011 18
Are a few days working on Saturday or Sunday? How do you get the 22 working days in April 2011 and 23 in may?
SQL is good at obtaining results with a variable number of rows, but you have to say exactly the desired number of columns when you write the query.
If you really need the output of the way you said, with any number of columns, then watch in swing or a grouping of the chain . See the FAQ forum
https://forums.Oracle.com/forums/Ann.jspa?annID=1535
"4. How can I convert rows to columns. -
SQL query to get the items for which transactions have not been saved
Hi people,
Have a small doubt I want to compile a SQL query in the inventory where I get these items for what transactions do not have been recorded during a period of at least one specified number of days.
The days might be 30 days or 2 months depends on. If I want to get those items for which no transactions were reported for lets say 30 days. Could someone give me an idea of how to go about this thing? I use r12. I came up with the following query, but it gives a lot of records. The commented parts of this query is only commented on
SELECT DISTINCT msi.segment1,
MSI. Description,
MSI.primary_uom_code,
MSI.inventory_item_id
MSI mtl_system_items_b / *,.
mtl_material_transactions mmt * /.
WHERE / * msi.inventory_item_id = mmt.inventory_item_id
AND msi.organization_id = mmt.organization_id
AND NVL ((SELECT SUM (transaction_quantity)
OF mtl_onhand_quantities
WHERE inventory_item_id = msi.inventory_item_id),
0) = 0
AND TRUNC (mmt.transaction_date) < = SYSDATE - & D
AND * / NOT EXISTS (SELECT *)
OF mtl_material_transactions mmt
WHERE msi.inventory_item_id = mmt.inventory_item_id
AND msi.organization_id = mmt.organization_id
AND TRUNC (mmt.transaction_date) < SYSDATE - & D);
Hi fatimakhellil
Try the following code and mark it as correct if your problem be resolved.
SELECT DISTINCT msi.segment1,
MSI. Description,
MSI.primary_uom_code,
MSI.inventory_item_id,
MSI.organization_id,
Ms.secondary_inventory_name,
(select max (transaction_date) in the mtl_material_transactions where msi.inventory_item_id = inventory_item_id
AND msi.organization_id = organization_id) last_transaction_date
OF mtl_system_items_b msi.
Ms. mtl_secondary_inventories
WHERE ms.organization_id (+) = msi.organization_id
AND msi.source_subinventory = ms.secondary_inventory_name (+)
AND NOT EXISTS (SELECT *)
OF mtl_material_transactions mmt
WHERE msi.inventory_item_id = mmt.inventory_item_id
AND msi.organization_id = mmt.organization_id
AND mmt.subinventory_code = ms.secondary_inventory_name
AND mmt.organization_id = ms.organization_id
AND TRUNC (mmt.transaction_date) BETWEEN TRUNC (SYSDATE - & d) AND TRUNC (SYSDATE))
Maybe you are looking for
-
Satellite U500-1F5 - how to turn on Bluetooth?
I just bought Satellite U500-1F5 and I want to know how to turn on bluetooth? Thanks in advance
-
Capture network in areas of low signal Signal
Dear motorcycle team, First of all a big thank you to the motorcycle team together to provide a beautiful and excellent mobile phone at a competitive price in the Indian market. Moto X Play Rulez... Come back my mobile 2 days. One thing I noticed in
-
Access a chart xy both inside and outside of a loop
Every morning. Semi-new LabVIEWer here (five weeks fun). This one has left me speechless. I take data from up to three units GPIB, generating three sets of data current-voltage, and I'm working on a xy real-time graph. Data in a table to two dimens
-
Internal Bay wiring HP z800 does support higher speeds?
Hello I'm interested if internal Bay wiring HP z800 supports higher speeds - 12 Gbit/s and 6 Gbps? Or should I use berries 5.25 "to mount and connect directly to the controller SAS 12Gbps with data speed has approved longer cables? Thanks for the rep
-
BlackBerry Smartphones receive files via bluetooth on my BlackberryTorch
I'm having a problem to receive the file on my torch because I does'nt have the option 'receive via bluetooth' on my Blackberry torch. I'm on the 6.0.0.448 version. I am a new user of the blackberry torch, and I love it, except for this problem. Can