Home » SQL & PL/SQL » SQL & PL/SQL » construct full date based on value yyyymm (11g)
construct full date based on value yyyymm [message #632034] Fri, 23 January 2015 09:36 Go to next message
cplusplus1
Messages: 58
Registered: October 2012
Location: usa
Member
I have value YYYYMM, in column "close_per", need to make it the first date of that month and year.

Select close_per from charge_det;

want to have teh rsult as 01mmyyyy.

Can you please tell me how.

Thank you very much for the helpful info.
Re: construct full date based on value yyyymm [message #632035 is a reply to message #632034] Fri, 23 January 2015 09:39 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
cplusplus1 wrote on Fri, 23 January 2015 07:36
I have value YYYYMM, in column "close_per", need to make it the first date of that month and year.

Select close_per from charge_det;

want to have teh rsult as 01mmyyyy.

Can you please tell me how.

Thank you very much for the helpful info.



Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/


What datatype is CLOSE_PER?
Re: construct full date based on value yyyymm [message #632036 is a reply to message #632035] Fri, 23 January 2015 09:41 Go to previous messageGo to next message
cplusplus1
Messages: 58
Registered: October 2012
Location: usa
Member
I am sorry, it is varchar.
Re: construct full date based on value yyyymm [message #632038 is a reply to message #632036] Fri, 23 January 2015 09:52 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
cplusplus1 wrote on Fri, 23 January 2015 07:41
I am sorry, it is varchar.


what is the datatype of the desired results?
Re: construct full date based on value yyyymm [message #632039 is a reply to message #632038] Fri, 23 January 2015 09:56 Go to previous messageGo to next message
cplusplus1
Messages: 58
Registered: October 2012
Location: usa
Member
it is a varchar2(10) dd-MM-yyyy

Thank you very much.

Re: construct full date based on value yyyymm [message #632040 is a reply to message #632039] Fri, 23 January 2015 10:03 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
cplusplus1 wrote on Fri, 23 January 2015 07:56
it is a varchar2(10) dd-MM-yyyy

Thank you very much.



>want to have teh rsult as 01mmyyyy.

You would confuse your own mother to know if you were actually her child.

It appears you are not qualified to be anywhere close to any keyboard.

It is not possible to meet your posted requirements.
Re: construct full date based on value yyyymm [message #632041 is a reply to message #632040] Fri, 23 January 2015 10:08 Go to previous messageGo to next message
cplusplus1
Messages: 58
Registered: October 2012
Location: usa
Member
you are a total / close to taking social security benefits. why sitting here. every single time your a nonsense. ask 20 questions.
Re: construct full date based on value yyyymm [message #632042 is a reply to message #632041] Fri, 23 January 2015 10:12 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>why sitting here. every single time your a nonsense. ask 20 questions
because the details actually do matter; otherwise Garbage In & Garbage Out (like storing DATE in VARCHAR2 varaibles)
Re: construct full date based on value yyyymm [message #632043 is a reply to message #632042] Fri, 23 January 2015 10:16 Go to previous messageGo to next message
cplusplus1
Messages: 58
Registered: October 2012
Location: usa
Member
just give me any logic, i will atleast can use yours to work it. You keep on asking and asking, i am being more respectful to you .
Re: construct full date based on value yyyymm [message #632045 is a reply to message #632043] Fri, 23 January 2015 10:28 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

What is your problem to go from YYYYMM to 01mmyyyy or dd-MM-yyyy?
I fail to see what can be the problem, it's so basic that with the almost half hundred questions you posted, almost all around strings or dates, you still unable to do this and you're still unable to correctly post a question.
I agree with BlackSwan, you are completely unskilled for this job.

Please read OraFAQ Forum Guide.
Always post your Oracle version, with 4 decimals.
With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Re: construct full date based on value yyyymm [message #632046 is a reply to message #632045] Fri, 23 January 2015 10:47 Go to previous messageGo to next message
cplusplus1
Messages: 58
Registered: October 2012
Location: usa
Member
I got it. thanks a lot for both of you famous old timers geriatric patients on this board. you both ask too many questions, with a footer note forum guide. with all due respect, you guys criticize a lot look at your old posts.


Re: construct full date based on value yyyymm [message #632047 is a reply to message #632039] Fri, 23 January 2015 10:58 Go to previous messageGo to next message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
cplusplus1 wrote on Fri, 23 January 2015 09:56
it is a varchar2(10) dd-MM-yyyy

Thank you very much.



HUGE design mistake!

Dates should be stored as DATE. Given your design, there is nothing to prevent this:

insert into charge_det (close_per) values ('guess what day it is');
Re: construct full date based on value yyyymm [message #632048 is a reply to message #632046] Fri, 23 January 2015 11:04 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
cplusplus1 wrote on Fri, 23 January 2015 17:47
I got it. thanks a lot for both of you famous old timers geriatric patients on this board. you both ask too many questions, with a footer note forum guide. with all due respect, you guys criticize a lot look at your old posts.


So post it, this is also part of the guide and you often forget it.
Also you didn't mention the numerous times we helped you in our old posts.

Re: construct full date based on value yyyymm [message #632049 is a reply to message #632047] Fri, 23 January 2015 11:14 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
@EdStevens: It will fail, as it the input string too long. But, here are some ideas for original poster; I hope he is aware of string concatenation operation.
with x as ( select column_value c
  from table( sys.odcivarchar2list( '201411', '201412', '201501', '201502', '201503' ) )
)
select c, '01' day_nr, '-' separator, substr(c,5,2) month_nr, substr(c,1,4) year_nr
from x;

Of course, it will produce garbage if the input is in different format, but at least it will not fail with any exception caused by converting it to real DATEs.
Re: construct full date based on value yyyymm [message #632050 is a reply to message #632049] Fri, 23 January 2015 12:10 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
I hope he is aware of string concatenation operation.
Laughing

Re: construct full date based on value yyyymm [message #632053 is a reply to message #632050] Fri, 23 January 2015 12:25 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
how do you spell S-Q-L?
Re: construct full date based on value yyyymm [message #632059 is a reply to message #632049] Fri, 23 January 2015 12:46 Go to previous messageGo to next message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
flyboy wrote on Fri, 23 January 2015 11:14
@EdStevens: It will fail, as it the input string too long.



Oh, good grief! Ok, so make the statement "insert into charge_det (close_per) values ('qwertyuiop');"
That will fit the OP's 10-char limit.

SQL> create table edstest (bogus_date varchar(10));

Table created.

SQL> insert into edstest values ('bogusdate');

1 row created.

SQL> insert into edstest values ('20150123');

1 row created.

SQL> insert into edstest values ('5/4/12');

1 row created.

SQL> insert into edstest values ('1234567890');

1 row created.

SQL> insert into edstest values ('33-01-2525');

1 row created.

SQL> select * from edstest;

BOGUS_DATE                                                                      
----------                                                                      
bogusdate                                                                       
20150123                                                                        
5/4/12                                                                          
1234567890                                                                      
33-01-2525



My point is that if one stores dates in anything but a DATE column, then one CANNOT guarantee the validity of the data.



Quote:

Of course, it will produce garbage if the input is in different format, but at least it will not fail with any exception caused by converting it to real DATEs.


That's exactly my point. It will fail WHEN (not "if") the data is in a different format. And it WILL fail with exception caused by converting it to real DATES because one cannot guarantee that a VARCHAR has something that CAN be converted to a real date. Even if one tries. What date is represented by the string '10/11/12'?

Re: construct full date based on value yyyymm [message #632062 is a reply to message #632059] Fri, 23 January 2015 13:05 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>What date is represented by the string '10/11/12'?

you have 6 guesses since I promise you that the first 5 will be wrong.
Re: construct full date based on value yyyymm [message #632070 is a reply to message #632050] Fri, 23 January 2015 16:20 Go to previous messageGo to next message
cplusplus1
Messages: 58
Registered: October 2012
Location: usa
Member
I just read today, France is the most hospitable country in the world. Congratulations Michel.

Using this straight:
to_char(to_date('01'||CLOSING_PER, 'ddyyyymm'),'dd-mm-yyyy')


observed too many posts by BlackSwaaan and Michel Caydot: arrogant responses , too old get some rest. There are lot of other members here who are better learn from them.

[Updated on: Fri, 23 January 2015 16:34]

Report message to a moderator

Re: construct full date based on value yyyymm [message #632073 is a reply to message #632070] Fri, 23 January 2015 18:32 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
cplusplus1 wrote on Fri, 23 January 2015 17:20
Using this straight:


Overkill. I suggest you RTFM:

The default date values are determined as follows:

•The year is the current year, as returned by SYSDATE.

•The month is the current month, as returned by SYSDATE.

•The day is 01 (the first day of the month).

•The hour, minute, and second are all 0.

Therefore:

to_char(to_date(CLOSING_PER, 'yyyymm'),'dd-mm-yyyy')


And scrap your design. Storing dates as strings sooner or later will backfire with something like 37th month of year ABCD.

SY.
Re: construct full date based on value yyyymm [message #632081 is a reply to message #632073] Sat, 24 January 2015 05:05 Go to previous messageGo to next message
cplusplus1
Messages: 58
Registered: October 2012
Location: usa
Member
Thank you very much Solomon,will let dba know. please teach the other two how to be atleast better.

Both of them arrogant.
Re: construct full date based on value yyyymm [message #632082 is a reply to message #632081] Sat, 24 January 2015 05:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You are borderline now, close to banishment.

[Updated on: Sat, 24 January 2015 07:02]

Report message to a moderator

Re: construct full date based on value yyyymm [message #639180 is a reply to message #632082] Thu, 02 July 2015 10:37 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Now that I see OP's trend, I think you Michel as "Account Moderator", should go ahead.
Re: construct full date based on value yyyymm [message #639185 is a reply to message #639180] Thu, 02 July 2015 10:42 Go to previous messageGo to next message
gazzag
Messages: 1118
Registered: November 2010
Location: Bedwas, UK
Senior Member
Oh, I don't know; he's kind of funny Wink

Any mods know where he is actually posting from? His profile says USA but I somehow doubt it.
Re: construct full date based on value yyyymm [message #639189 is a reply to message #639185] Thu, 02 July 2015 10:46 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

His IP is registered in Hollywood, FL, USA.

Re: construct full date based on value yyyymm [message #639196 is a reply to message #639180] Thu, 02 July 2015 11:22 Go to previous messageGo to next message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
Why are we reviving a 5-month-old thread?

-- edit .. oh, I think I see ....

[Updated on: Thu, 02 July 2015 11:24]

Report message to a moderator

Re: construct full date based on value yyyymm [message #639197 is a reply to message #639196] Thu, 02 July 2015 11:27 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Generally, I won't care. But this time it seems OP is too stubborn.


@Ed, you figured it out yourself by the time I pitched in...

[Updated on: Thu, 02 July 2015 11:29]

Report message to a moderator

Previous Topic: REGEXP_REPLACE for different name variations
Next Topic: SUM CASE date difference calculation
Goto Forum:
  


Current Time: Fri Apr 26 03:17:41 CDT 2024