|
|
Re: NEAREST [message #225990 is a reply to message #225923] |
Thu, 22 March 2007 03:50 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
I think you need to use ABS(review_Date-sysdate) - otherwise it wont
You can do it without analytic function too (if you're on 8i) SELECT *
FROM (SELECT *
FROM bill
ORDER BY abs(review_date-sysdate))
WHERE rownum = 1;
|
|
|
|
|
Re: NEAREST [message #226080 is a reply to message #226001] |
Thu, 22 March 2007 08:11 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
hi
i forgot to inform u that the date is in varchar2(30)
can i should use date function which function i need to use
thanxs
|
|
|
|
|
Re: NEAREST [message #227529 is a reply to message #226255] |
Wed, 28 March 2007 08:36 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
HI
one more request the data in the column is stored as varchar2(30)
some of the data is
21-mar-2007
TBD_ENTERED
TBD
25-MAR-2007
I THINK BEcause of TBD_ENTERED the data is not returned
if i use it for other column it works
pls advice
thanxs
|
|
|
Re: NEAREST [message #227572 is a reply to message #227529] |
Wed, 28 March 2007 12:28 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
See how storing DATEs in VARCHAR2 columns is causing you headaches? They'll only get worse.
You'll need to filter on records that are valid DATEs. Search for IS_DATE or DATE IN VARCHAR2 COLUMN.
|
|
|
Re: NEAREST [message #229376 is a reply to message #227572] |
Sat, 07 April 2007 01:22 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
hi
its long time unable to solve the issue
pls can any be little more albort/brief on this
i have stored the date data in varchar2(30) in column name expected_date and order_date in proj table
1. i want to get the nearest date of current (next) for expected_date
2. i want to get the nearest date of current (previous) for ordered_date
3.i want to get the All projects with order_date within 3 months of the current date
think today is 05April2007
i want for next =06April2007
and for previous i want 04April2007
and for 3 month 05July2007
|
|
|
|
Re: NEAREST [message #229382 is a reply to message #229381] |
Sat, 07 April 2007 02:07 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
CREATED THE FUNCTION
CREATE OR REPLACE FUNCTION is_date1(i_date IN varchar2) RETURN DATE IS
v_date DATE;
BEGIN
v_date := TO_DATE(i_date ,'dd/mm/rrrr');
RETURN v_date;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END is_date1;
create or replace FUNCTION is_dateORA(p_test date)
RETURN varchar2
IS
v_check_date DATE;
ret varchar2(30):='valid date';
BEGIN
BEGIN
v_check_date := TO_DATE(p_test);
EXCEPTION
WHEN OTHERS THEN
ret:='not a valid date';
RETURN
ret;
end;
RETURN ret;
END;
Function created.
SQL> select is_date1(sysdate) from dual;
IS_DATE1(
---------
07-APR-07
SQL> select is_dateORA(sysdate) from dual;
IS_DATEORA(SYSDATE)
------------------------------------------
valid date
HOW DO I RUN WITH MY ISSUE
PLS PROVIDE ME HELP
ITS URGENT
[Updated on: Sat, 07 April 2007 02:15] Report message to a moderator
|
|
|
|
Re: NEAREST [message #229388 is a reply to message #229385] |
Sat, 07 April 2007 03:35 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
hi
mike i dint mean to disturb u
as the situation was circuital here i just requested for an urgent
ok i do feel that is forum is the best i have gone through which responds to the issue as soon as possible
pls do the needful
thanxs
|
|
|
|
Re: NEAREST [message #229391 is a reply to message #229388] |
Sat, 07 April 2007 04:54 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
hi
hope i am clear now
the data is expected_date column and proj table is
TBD-APR-2007
TBD-APR-2010
25-MAR-2009
TBD-FEB-2009
TBD-FEB-2006
27-FEB-2009
TBD-MAR-2005
TBD-MAR-2008 so on
find the nearest date of the current date (next) say june date
find the nearest date of the current date (previous)say feb date
|
|
|
Re: NEAREST [message #229392 is a reply to message #229391] |
Sat, 07 April 2007 05:08 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
It is as clear as mud.
What is "TBD-APR-2007"? Is it data you have in your table?
Post a "select ... from proj ..."
Format it (query and result)
Post the result you want and the rules to get the result.
"Nearest" is nearest from what?
And what is nearest?
As Tom Kyte often said: "Explain this as if you explain it to your Mom".
In the end, explain why the previous answers don't fit your requirements. (You still don't answer this question, it seems to me this is the third time I ask you this).
Regards
Michel
[just a correction in bold line]
[Updated on: Sat, 07 April 2007 05:10] Report message to a moderator
|
|
|
Re: NEAREST [message #229398 is a reply to message #229392] |
Sat, 07 April 2007 05:28 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
SQL> select FK_PROJ_ID,EXPECTED_DATE,REVIEWED_DATE,STATUS from PROJ_APPROVALS;
FK_PROJ_ID EXPECTED_DATE REVIEWED_DATE S
---------- ------------------------------ ------------------------------ -
10020 31-FEB-2008
10020 31-FEB-2008
10020 31-FEB-2008
10003 13-JUL-2007
10015 TBD-APR-2010 07-Apr-2007 Y
10015 27-FEB-2009 13-Apr-2007 Y
10016 24-MAR-2011 Y
10016 25-MAR-2009 N
10016 23-FEB-2009 N
10017 TBD-FEB-2008 05-Apr-2007 Y
10017 TBD-APR-2007 03-Apr-2007 N
FK_PROJ_ID EXPECTED_DATE REVIEWED_DATE S
---------- ------------------------------ ------------------------------ -
10017 03-Apr-2007 N
10018 TBD-FEB-2007
10018 TBD-MAR-2008
10018 TBD-MAR-2008
10015 2-FEB-2010 05-Apr-2007 Y
10019 TBD-FEB-2007
10019 TBD-MAR-2008
10019 TBD-MAR-2008
19 rows selected.
nearest means nearest to sysdate
[Updated on: Sat, 07 April 2007 05:49] Report message to a moderator
|
|
|
|
Re: NEAREST [message #229401 is a reply to message #229399] |
Sat, 07 April 2007 06:13 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
HI
i need 3month before and after
is this query correct
1. SELECT MIN(TO_DATE(expected_date,'DD-MON-YYYY')-90) ,TO_CHAR(MIN(TO_DATE(expected_date,'DD-MON-YYYY')),'D-MON-YYYY') MD
FROM PROJ_APPROVALS WHERE EXPECTED_DATE NOT LIKE '%TB%' AND (TO_DATE(expected_date,'DD-MON-YYYY')+ 90) >0
GROUP BY FK_APPROVER_CAT_ID]
2.SELECT expected_date
, TO_CHAR( TO_DATE( expected_date, 'DD-MON-YYYY ) + 1 ) dayafter
, TO_CHAR( TO_DATE( expected_date, 'DD-MON-YYYY ) - 1 ) daybefore
FROM PROJ_APPROVALS ;
[U]how to select[/U]
to select with "MIN( a_date )" and MAX( a_date )").
|
|
|
|
|
Re: NEAREST [message #229405 is a reply to message #229403] |
Sat, 07 April 2007 06:34 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
Your first post was from over two weeks ago. You had plenty time to find a solution, so please stop whining about the urgency of your problem.
This forum is not meant to be a place where you can feed your requirements and retrieve a full blown query. We still expect you to do your own work. After all, YOU get paid for your work, we don't.
|
|
|
date [message #230895 is a reply to message #225923] |
Fri, 13 April 2007 04:22 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
hi
select records which are > then three month from the sysdate(current date)
SELECT TO_CHAR(TO_DATE(tested_DATE, 'DD-MON-RR') ,'MON-DD-YYYY')"Year" FROM testing;
sysdate + 90
thanxs
|
|
|
|
|
find date [message #231982 is a reply to message #225923] |
Thu, 19 April 2007 00:25 |
oracle_coorgi
Messages: 188 Registered: September 2006 Location: INDIA-karnataka
|
Senior Member |
|
|
hi
iam getting correct records from the first query
1.select * from test where test_DATE < SYSDATE + 90 i need to get the out put as above query using between from the second query
2.select * from test where sysdate-test_DATE between 0 and 91
thanxs
|
|
|
Re: find date [message #231988 is a reply to message #231982] |
Thu, 19 April 2007 00:43 |
ammishra
Messages: 179 Registered: January 2007 Location: india
|
Senior Member |
|
|
Hi oracle_coorgi,
I don't think you will get the same answer from both query.
let say
test_DATE=4/19/2005
select * from test where test_DATE < SYSDATE + 90
this query will return the record for test_DATE=4/19/2005
..
but second query will become like that ..
select * from test where 730 between 0 and 91
this will not select the record which testdate is 4/19/2005
--Yash
|
|
|
|
Re: find date [message #231993 is a reply to message #231990] |
Thu, 19 April 2007 00:56 |
ammishra
Messages: 179 Registered: January 2007 Location: india
|
Senior Member |
|
|
Try this
select * from test where (sysdate+90)-test_DATE between 0 and (sysdate+90)-test_DATE
--Yash
|
|
|
|
Re: find date [message #231997 is a reply to message #231982] |
Thu, 19 April 2007 01:11 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
You still don't say why you can't use add_months.
But after at least 3 threads on this topic in different forums I doubt you will ever answer this question.
|
|
|