the list of numbers between two columns
HelloI need the list of numbers between two columns.
My source table contains the intervals with different ranges and I'm currently thinking dividing them by size.
I was able to get a solution following the information contained in the Web page:
http://StackOverflow.com/questions/3971981/get-list-of-numbers-in-between-two-columns
The solution I've used is based on the following example:
with t as (
select 10 startnum, 15 endnum from dual
union all
select 18, 22 from dual
union all
select 10000, 19999999999 from dual
)
select lvl
from (select level lvl
from dual
connect by level <= (select max(endnum) from t)) a
where exists (
select 1
from t
where lvl between t.startnum and t.endnum )
But this doesn't work in my table if I have few and modest intervals (maximum 5 digits range).In the example, I was trying to understand why this might be failing, but I do not have a conclusion yet.
There is something I noticed and that I try to understand, that is:
If I change this query to:
with t as (
select 10 startnum, 15 endnum from dual
union all
select 18, 22 from dual
union all
select 19999999990, 19999999999 from dual
)
select lvl
from (select level lvl
from dual
connect by level <= (select max(endnum) from t)) a
where exists (
select 1
from t
where lvl between t.startnum and t.endnum )
It will increase from 2 to 3 seconds to return results to a few minutes at least (canceled after a few minutes!)Thus, using this example to understand if my problem is related to having many between start and end number or if it is linked with having small intervals between large numbers.
Can someone explain to me why I have this speed of different treatment depending on the value of the interval? And why it takes longer with the small interval?
I need to apply it to different beaches (from 2 ranges of numbers to 16 range) and in all ranges, I will have small intervals to check.
For example:
endnum startnum
7341 7342
7422-7423
7439 7456
2522200050 2522200054
2522200146 2522200150
4216969839880 4216969839884
4216969839893 4216969839897
Having this problem I can only ask the first values I have in the picture!
Best regards
Ricardo Tomas
Hi, Ricardo,
Here's one way:
WITH cntr AS
(
SELECT LEVEL - 1 AS n
FROM (
SELECT MAX ( endnum - startnum) AS max_diff
FROM t
)
CONNECT BY LEVEL <= max_diff + 1
)
SELECT startnum + c.n
FROM t
JOIN cntr c ON t.endnum >= t.startnum + c.n
;
In your original query, you generate all the numbers from 1 to the highest endnum. You only need enough numbers to cover the range of startnum to endnum. (This method also works if startnum is less than 1).
Joins are usually faster than EXISTS subqueries.
Tags: Database
Similar Questions
-
Hello
I would like to create sequential numbers between these two columns of the specified table.
Existing data in the table
Column1 Column2 5 7 13 14 18 19 24 27 29 29 power required:
5
6
7
13
14
18
19
24
25
26
27
29
Could someone help me with this please.
Thank you.
XQUERY solution:
with
data in the form of
(select 5 Column1, Column2 7 Union double all the)
Select 13,14 in union double all the
Select 18,19 Union double all the
Select 24,27 Union double all the
Select double 29,29
)
Select n
data,.
XMLTable)
"xs:integer ($s) at xs:integer ($e).
passing of Column1 as "s",.
Column2 like 'e '.
columns
path number n '. »
)
/
N
----------
5
6
7
13
14
18
19
24
25
26
27N
----------
2912 selected lines.
SQL >
SY.
-
Need help on the list of months between two Dates
Hi all
I have a table which has startdate and enddate and need a select to list all the months between these two dates for each given ID.
I did some tests and could not figure out how to get the startdate and enddate table (instead of hard coding) tests in the select statement.
Could someone please help on this (Oracle 11 g 2),
Thanks in advance!
create table testing( id number, start_date date, end_date date); insert into testing values(100, to_date('05-FEB-2011', 'DD-MON-YYYY'), to_date('28-MAY-2011', 'DD-MON-YYYY')); insert into testing values(200, to_date('20-JUN-2011', 'DD-MON-YYYY'), to_date('28-DEC-2011', 'DD-MON-YYYY')); commit; select * from testing; ID START_DAT END_DATE ---------- --------- --------- 100 05-FEB-11 28-MAY-11 200 20-JUN-11 28-DEC-11 Elapsed: 00:00:00.01 *for testing.id = 100:* select to_char(add_months(to_date('05-FEB-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates from (select level l from dual connect by level <= months_between(trunc(to_date('28-MAY-2011', 'DD-MON-YYYY'), 'MONTH'), trunc(to_date('05-FEB-2011', 'DD-MON-YYYY'), 'MONTH')) + 1); DATES ----------------- 2011-Feb 2011-Mar 2011-Apr 2011-May Elapsed: 00:00:00.01 *for testing.id = 200:* select to_char(add_months(to_date('20-JUN-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates from (select level l from dual connect by level <= months_between(trunc(to_date('28-DEC-2011', 'DD-MON-YYYY'), 'MONTH'), trunc(to_date('20-JUN-2011', 'DD-MON-YYYY'), 'MONTH')) + 1); DATES ----------------- 2011-Jun 2011-Jul 2011-Aug 2011-Sep 2011-Oct 2011-Nov 2011-Dec 7 rows selected.
SQL> select * from testing 2 / ID START_DAT END_DATE ---------- --------- --------- 100 05-FEB-11 28-MAY-11 200 20-JUN-11 28-DEC-11 SQL> select id, 2 to_char(add_months(start_date,column_value - 1),'YYYY-Mon') dates 3 from testing, 4 table( 5 cast( 6 multiset( 7 select level 8 from dual 9 connect by add_months(trunc(start_date,'MM'),level - 1) <= end_date 10 ) 11 as sys.OdciNumberList 12 ) 13 ) 14 order by id, 15 column_value 16 / ID DATES ---------- -------- 100 2011-Feb 100 2011-Mar 100 2011-Apr 100 2011-May 200 2011-Jun 200 2011-Jul 200 2011-Aug 200 2011-Sep 200 2011-Oct 200 2011-Nov 200 2011-Dec 11 rows selected. SQL>
SY.
-
How to write a query for the data exchange between two columns?
How to write a query for the data exchange between two columns?
I tried a request, does NOT work.
Thank you.update tmp t1 set t1.m1=t1.m2 and t1.m2=(select t2.m1 from tmp t2 where t2.student_id = t1.student_id)
Published by: user533361 on October 23, 2009 14:04Just plain and simple:
update tmp t1 set t1.m1=t1.m2, t1.m2=t1.m1 /
SY.
-
How to view the menu of bookmarks in two columns
Firefox 3.6.7 under Windows 7. I wish I had the menu bookmark appears in two columns to avoid the bottom of the scroll list.
Sorry, it's not a function for this integrated into Firefox.
See if this extension fits your needs.
https://addons.Mozilla.org/en-us/Firefox/addon/74381/Read all the comments from the user before installing it, there might be a problem on Win7 or with later versions of 3.6. versions #.
-
Dynamic calculation of the number of days between two dates in a table
Hello
I'm working on request where I dynamically calculate the number of days between two dates in a table.
The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.
APEX version: 5.0
Hi BO123,
BO123 wrote:
Hello
I'm working on request where I dynamically calculate the number of days between two dates in a table.
The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.
APEX version: 5.0
one of the way to do this by calling ajax on change of end_date.
See the sample code given below to fetch the resulting duration and making the field read only after calculation
Step 1: Change your page
under CSS-> Inline, put the code below
.row_item_disabled { cursor: default; opacity: 0.5; filter: alpha(opacity=50); pointer-events: none; }
Step 2: Create on demand Ajax process I say CALC_DURATION
Please check Procces Ajax, see line 6.7 How to assign a value to the variable sent by ajax call
Declare p_start_date date; p_end_date date; p_duration number; Begin p_start_date := to_date(apex_application.g_x01); p_end_date := to_date(apex_application.g_x02); --do your calculation and assign the output to the variable p_duration select p_end_date - p_start_date into p_duration from dual; -- return calculated duration sys.htp.p(p_duration); End;
Step 3: Create the javascript function
Change your page-> the function and the declaration of the Global Variable-> put the javascript function
You must extract the rowid in the first place, for which you want to set the time, see line 2
assuming f06, f07 and f08 is the id of the start date, and end date columns respectively, and duration
See no line no 8 how set the value returned by the process of ajax at the duration column
Replace your column to the respective column identifiers in the code below
function f_calulate_duration(pThis) { var row_id = pThis.id.substr(4); var start_date = $('#f06_'+row_id).val(); apex.server.process ( "CALC_DURATION", { x01: start_date,x02: $(pThis).val() }, { success: function( pData ) { // set duration to duration column $('#f08_'+row_id).val(pData); // disable duration column $("#f08_" + row_id).attr("readonly", true).addClass('row_item_disabled'); } }); }
Step 4: choose the end date call the javascript function
Go to report attributes-> edit your Date column end-> column-> Attrbiutes element attributes-> put the code below
onchange="javascript:f_calulate_duration(this);"
hope this helps you,
Kind regards
Jitendra
-
JavaScript anomaly on the number of days between two dates
Use ApEx 4.0, I found an anomaly in a javascript code that calculates the number of days between two dates, the current_date and the past_date. If the past and present is the or before March 10, 2013, and the current_date lies between 10 March 2013 and November 3, 2013, the number of days will be from 1 day to less than the actual number. Between November 3, 2013 and on 4 November 2013, the increments of number by 2, then the count will be accurate from this date forward.
Here are some examples:
March 10, 2013 = 69 days of December 31, 2012
March 11, 2013 = 69 days of December 31, 2012
March 12, 2013 = 70 days of December 31, 2012
November 3, 2013 = 306 days in December 31, 2012
November 4, 2013 = 308 days in December 31, 2012
11 March should be 70 and 12 March should be 71. November 3 is 307 and 4 November corrects the number of fake, which began March 11.
Change the past_date to March 10, 2013 produces the following:
March 10, 2013 = 0 days of March 10, 2013
March 11, 2013 = 0 days of March 10, 2013
March 12, 2013 = 1 days of March 10, 2013
But change the past_date to 11 March 2013, product of the correct numbers:
March 11, 2013 = 0 days of March 11, 2013
March 12, 2013 = 1 days of March 11, 2013
March 13, 2013 = 2 days of March 11, 2013
I would certainly all help to determine the cause of this anomaly. Here's the javascript code:
var w1 = ($v ("P48_PAST_DATE"));
W1 = (w1.toString ());
vmon var = (w1.substr (3.3));
vyr var = (w1.substr (7));
var r = (vyr.length);
If (r == 2)
vyr. = (parseFloat (vyr) + 2000);
vday var = (w1.substr (0.2));
var y = (vmon.concat ("", vday, ",", vyr));
y = Date.parse (y);
var w2 = ($v ("P48_CURRENT_DATE"));
var vmon2 = (w2.substr (3.3));
var vyr2 = (w2.substr (7));
var vday2 = (w2.substr (0.2));
var x = (vmon2.concat ("", vday2, ",", vyr2));
x = Date.parse (x);
var numdays = (x - y);
numdays = (Math.floor(numdays / 86400000));
$s ("P48_NUMBEROFDAYS", numdays);Did you google for something like "javascript number of days between two dates. I think you will find the explanation to this observation:
This method does not work correctly if there is an advanced economies jump between the two dates.
There are examples available to calculate the difference between two dates.
-
Thick border line between two columns
Hello all;
I have a requirement where the user must be able to distinguish between two columns hnce asking a thick line, rather than the usual 'by default'.
Everything is 'Default' until then.
I clicked on properties of the 1st column and in the section "Border", I chose "Custom" and made the right wall of the cell in black color.
I see a thick border now, but it has eliminated the 'default' border separating lines. His party make the entire column look like a single cell.
I don't want any change with the exception only of the border of a column of a black line.
Any help is greately appreciated.
Thank you!The column properties-> Options of Style CSS custom (HTML only)-> use custom CSS Style->
the following CSS code
border-right-width: 1px; border-right-color: green;or go with someone with the necessary changes
Appreciate if you score as correct if it works
Published by: Srini VIEREN on December 11, 2012 16:43
-
List of years between two dates
Hello
I am new to Livecycle Designer and learning I will.
I have a few questions related to the same question.
1. is it possible to create a list of years between two dates, especially the exercises? (I'm in Australia so it's July 1 to June 30).
for example
User between two dates in date fields:
(Start Date of the project field) July 1, 2012 and (end Date of the project field) 30 June 2015
Have an auto list to fill out as below:
(List)
2013
2014
2015
or ideally
(List)
2012/13
2013/14
2014/15
linking this (if possible).
2. is it possible to have to repeat the lines created automatically in a table for each of the fiscal years indicated in the list above?
If either / both of them are possible help that someone could provide would be very appreciated.
Thank you
Ivan
Hello
Please find an example that shows what I think you would do here - https://workspaces.acrobat.com/?d=F9t-rLq3bapw2d-XY0dRuQ
I ran a few test cases and did not include the error handling to keep the code as easy to read as possible.
If you open the form and look at the code in the click event of the update button, then that's where all the magic happens.
Hope this helps
Malcolm
-
Can I synchronize the activity of health between two watches from Apple?
I have two Apple - one for work, one for out watches. If I change watches in the middle of the day, the follow-up of the first watch of activity is not synchronized with the second watch. Is it possible to enable this so that the follow-up activity is specific for the whole day?
Thank you!
N ° it is not possible to synchronize the activity of health between two watches from Apple.
-
How to make the difference in percentage between two matrices?
Hello everyone, I just want to ask how to make the difference in percentage between two binary matrices. This is to compare two images converted to matrices in LabView. Thank you.
Well, in the current image interesting pixels are zero in the reference image. Here is a small example that would take all the zero 100% pixel, then look at the pixels of same in the other image to see how are always 0.
Modify if needed.
-
Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?
Hello
2796614 wrote:
Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?
Of course, it is possible. According to what the text file looks like to, you can create an external table that treats the text file as if it were a table. Otherwise, you can always read the file in PL/SQL, using the utl_file package and INSERT of PL/SQL commands.
You have problems whatever you wantt? If so, your zip code and explain what the problem is.
Whenever you have any questions, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the exact results you want from these data, so that people who want to help you can recreate the problem and test their ideas. In this case, also post a small sample of the text involved file.
If you ask about a DML operation, such as INSERT, then INSERT statements, you post should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: Re: 2. How can I ask a question on the forums?
-
Count the number of records between two values of keys (BTREE)
How can I count the number of keys between two values?
I use python driver and BTREE access method.
= >
Ideally, what I want is a set of whole time series data (intervals may change) to a given number of points on average. The keys are timestamps and the values are the data that it takes on average. I need to count the number of records between two timestamps so that I can divide this figure by the number of points I need and data on average. What is the best way to do it? Or should I keep the timestamp constant intervals and use the RECNO access method?
Thank you
(first post btw... and why is there not a lot of people at stackoverflow that answering the questions of Berkeley DB?)BDB is an integrated db and there no internal counters or statistics you might grap to use for this. You will have to do it manually.
You can create a cursor, grap the records you want, whenever you get the next card that you bump a counter.
If you are using RECNO, you can use a slider to obtain the number of registration (DB_GET_RECNO), and if all that you data is in
sequentail records with no missing documents, you can find the total number of take the last rec #-original rec # + 1 to get a count.
If you pass the SQL API, you can issue a SQL query to give you a count. Select count (*) where...
As you enter the data anyway, so better perhaps to count records as you go along.
Thank you
Mike
-
find the difference in days between two dates
Hello world
I'm trying to find out the difference in days between two dates and the execution of the query that I'm passing
SELECT TO_char(sysdate, 'dd/mm/yyyy') - TO_char('15/11/2011', 'dd/mm/yyyy') DAYS FROM DUAL
the error I get is
ORA-01722: invalid number
01722 00000 - "invalid number."
* Cause:
* Action:
Could someone please help.
Thanks in advanceuser10636796 wrote:
Hello worldThanks a lot for all the replies. I am trying to apply it in a statement to my table like this
SELECT trunc (sysdate) - TO_char (date_last_recommended, ' dd/mm/yyyy') DAYS OF recommendation;
SELECT trunc (sysdate) - TRUNC (date_last_recommended) DAYS OF recommendation;
-
Calculate the difference in days between two Dates
Hello
I'm trying to understand how to calculate the difference in days between two dates using JavaScript in LiveCycle. (Minimum = JavaScript knowledge)
Where 'Start_Date' and 'Current_Date' are the names of the two dates in the palette of the hierarchy. (the two Date/time field)
* Current date is using the object > value > execution property > current Date/time
I need a text or number field showing the difference in days. (Difference_in_Days)
I noticed the following code is pretty standard among other responses:
var
Start_date = new Date (Start_Date);
var
Current_Date = new Date (Current_Date);
var
nAgeMilliseconds = Current_Date.getTime) - Start_date.getTime ();
var
nMilliSecondsPerYear = 365 * 24 * 60 * 60 * 1000 ;
I know there is lack of code and code above are may not be not correct.
Please notify.
OK, that's because of the way that javascript and works of the calculate event. The field will be filled with whatever the script resolves at the end of execution. Technically, your script does not have a value because the last thing you do is an assignment to a variable. Change the last line as follows:
Math.ABS ((firstDate.getTime)
((- secondDate.getTime (()) / (oneDay));
(eliminate the variable assignment) and get rid of the app.alert. Your script will "return" (have) regardless of the value of calculation from the East and which will be stored in the field.
Maybe you are looking for
-
I downloaded the myheritage.com software that automatically and without my consent changed my default browser from firefox to its own. I changed the default, but I still can't connect to the internet with firefox. The opening tab label is (untitled)
-
This seems to be a common problem.I tried FN F9 - doesn't do a thing.Downloaded and reinstalled the driver.Touchpad is listed in devices and status, Manager is that it works correctly. USB mouse works fine. A reflection more?See you soonMich PS: comp
-
driver for USB - 6221 LabView 6.0 XP
I'm trying to connect an old laptop with Windows XP and Labview 6.0.2 for USB-6221. I can't find the drivers on the site of NOR. Can someone point me at home or another source? Thank you.
-
Laptop bought in April 2015.Using plugged to the power source. Lid closed and left on. Came back and the light flickered. Black and white screen. Cannot turn off computer. Held down button walk / stop but no answer - just keeps blinking! Can't seem t
-
Problems with the PC at startup after installing update KB980248
I'm not computer savvy very so I will try my best... A few weeks ago, I ran update KB980248 the next morning, when I turned on the pc it seemed to freeze on the startup screen displays the Dell logo and bottom right, he had the F2 and F12 options. Fi