Unusual result with TO_CHAR function on a date
Can anybody explain to me why I see two different results if I use the following SQL in PL/SQL Developer (Oracle Database 10g Enterprise Edition Release 10.2.0.1.0)? I'm not sure if I have a wrong setting in Oracle or PL/SQL Developer, or if I'm just misunderstanding how the TO_CHAR function works. Many thanks.
select sysdate, to_char(sysdate, 'dd/mm/yyyy hh:mm:ss') as FORMATTED_DATE from dual
Results:
SYSDATE
10/02/2009 16:52:32
FORMATTED_DATE
10/02/2009 04:02:32
select sysdate, to_char(sysdate, 'dd/mm/yyyy hh:mm:ss') as FORMATTED_DATE from dual
Results:
SYSDATE
10/02/2009 16:52:32
FORMATTED_DATE
10/02/2009 04:02:32It should not be -> mm it should be mi .
Got me?
Regards.
Satyaki De.
Similar Messages
-
Error in result of To_Char function.
Hi,
My name is Ramanujulu, I was practicing Date functions and found one error in one of the To_Char functions.
Please assume the sysdate as 19th Decmber 2006. (I used this date in example)
SQL> select to_char(sysdate-7, 'ddspth-month-syear') from dual;
TO_CHAR(SYSDATE-7,'DDSPTH-MONTH-SYEAR')
twelfth-december - two thousand six
It returns the 12th as twelfth. (Additional letter F). Who will correct this and how do i make this change in my Database.
Please let me know how to correct this.
Thanks,
Ramanujulu B.http://dictionary.reference.com/browse/twelfth
-
Formating dates with to_char function
Hi,,
Inside a pl/sql procedure Im formating a date:
v_start_date := 2011-04-01 05:00:00;
v_start_month := to_char(v_start_date,'mm');and I need that v_start_month returns = 04
but returns 4
What could I do to fix it
Many Thanks..If you define v_start_month as a number then it will strip off the leading 0 when it displays. Define v_start_month as a varchar and it will display the way you want.
SQL> DECLARE
2 v_month VARCHAR2(10);
3 BEGIN
4 v_month := to_char(SYSDATE,'mm');
5 dbms_output.put_line(v_month);
6 END;
7 /
08 -
CREATING A LIST PARTITION WITH TO_CHAR FUNCTION
i want to create a list partitions based on months like 1..12 so that data will go to its respective month partition irrespective of Month and year. i don't have a varchar2 field for month only rather i have got the insertion date column. can anybody tell me how can i create a list partitioned table by using the to_char(date_column,'MON') function.
Range partition means every month one new partition if i go for month wise partition. So, thats final right we cannot use any function to create any list partitions??
-
Help Required --- TO_CHAR function for formatting DATE
Tue, 20 Jan 2004 17:39:11 GMT.
I want the output in the above mentioned format . Can any one help me ,Please.
I tried some thing like this.......
select to_char(sysdate,'Dy, DD Mon yyyy HH24:MI:SS') from dual; and them Append GMT to it. Is this correct the way ? :D.You can append the results of the following (assuming the database timezone is GMT):
select dbtimezone from dual; -
Calendar Functionality for a date field in HTML of a ITS service
Hi
I am working with SRM EBP module we want to add date help(with calendar function) to existign date fields in Shopping cart and PO screens . I found some HTML and Javascripts in SYSTEM and BBPGLOBAL services (named as calendar)but not sure which ones to use if anyone used date functionality or even have access to Standard SAP ITS screens that already have date field with calendar fuctionality can you help???????????????
Thanks in AdvanceHi
Let me first thank you for the quick response and timely help you provided calendar popup works great but one minor issue i am not able to click on the date entry and bring the field back into the field not sure if this funcitonality is in show_calendar.
I would really appreciate if you get time to look at below i am almost there with your help......thanks again
Here are the steps I did
I have a HTML page SAPLBBP_SC_UI_ITS screen 300 in SRM module , I created a new HTML page (zcalendar.html) in the same internet service BBPSC01 as suggested and I included in my HTML page SAPLBBP_SC_UI_ITS screen 300 and also I added below code to add a icon and a href call to the show_calendar function.
Code works great I get the popup but when I double click on the date it is not selecting the date into the field back .
Any thoughts??????
<!-- Start ghantavine -->
`include (~service="bbpsc01", ~name="zcalendar.html")`
<!-- End ghantavine -->
<!-- 10/24/05 ghantavine--delivary date -->
`TR()`
`if (GS_SCR_BASIC_I-DELIV_DATE.visible)`
`TR()`
`if (gs_scr_basic_i-deliv_date.disabled)`
`TD(class="label", nowrap="x",
active="")``TXT_BASIC_I-DELIV_DATE.label`
`TD(class="label", nowrap="x", active="")``gs_scr_basic_i-deliv_date.value`
`else`
`TD(class="label", nowrap="x", active="")`<label
for="`GS_SCR_BASIC_I-DELIV_DATE.name`">`TXT_BASIC_I-DELIV_DATE.label`</label>
`TD(class="data", nowrap="x")`
<input type="text" id="GS_SCR_BASIC_I-DELIV_DATE"
name="GS_SCR_BASIC_I-DELIV_DATE" value="`GS_SCR_BASIC_I-DELIV_DATE.value`"
maxlength="010" size="008">
<a href=http://mail.yahoo.com/config/login?/"_javascript:show_calendar();">
<img id="anchor1" src="`mimeurl(~service="bbpglobal",
~name="images/button/f4.gif", ~language="", ~theme="99")`" />
</a>
`end`
`TR()` `Lines()`
`end`
<!-- 10/24/05 ghantavine--delivary date -->
below is the showcalendar code
Hi , u save this as a html file and call this show_calendar fn from Onclick button of your Calendar image .
// For generating the calendar
var weekend = [0,6];
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 2;
var gNow = new Date();
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
Calendar.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
if ((p_month == null) && (p_year == null)) return;
if (p_WinCal == null)
this.gWinCal = ggWinCal;
else
this.gWinCal = p_WinCal;
if (p_month == null) {
this.gMonthName = null;
this.gMonth = null;
this.gYearly = true;
} else {
this.gMonthName = Calendar.get_month(p_month);
this.gMonth = new Number(p_month);
this.gYearly = false;
this.gYear = p_year;
this.gFormat = p_format;
this.gBGColor = "white";
this.gFGColor = "black";
this.gTextColor = "black";
this.gHeaderColor = "black";
this.gReturnItem = p_item;
Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;
function Calendar_get_month(monthNo) {
return Calendar.Months[monthNo];
function Calendar_get_daysofmonth(monthNo, p_year) {
Check for leap year ..
1.Years evenly divisible by four are normally leap years, except for...
2.Years also evenly divisible by 100 are not leap years, except for...
3.Years also evenly divisible by 400 are leap years.
if ((p_year % 4) == 0) {
if ((p_year % 100) == 0 && (p_year % 400) != 0)
return Calendar.DOMonth[monthNo];
return Calendar.lDOMonth[monthNo];
} else
return Calendar.DOMonth[monthNo];
function Calendar_calc_month_year(p_Month, p_Year, incr) {
Will return an 1-D array with 1st element being the calculated month
and second being the calculated year
after applying the month increment/decrement as specified by 'incr' parameter.
'incr' will normally have 1/-1 to navigate thru the months.
var ret_arr = new Array();
if (incr == -1) {
// B A C K W A R D
if (p_Month == 0) {
ret_arr[0] = 11;
ret_arr[1] = parseInt(p_Year) - 1;
else {
ret_arr[0] = parseInt(p_Month) - 1;
ret_arr[1] = parseInt(p_Year);
} else if (incr == 1) {
// F O R W A R D
if (p_Month == 11) {
ret_arr[0] = 0;
ret_arr[1] = parseInt(p_Year) + 1;
else {
ret_arr[0] = parseInt(p_Month) + 1;
ret_arr[1] = parseInt(p_Year);
return ret_arr;
function Calendar_print() {
ggWinCal.print();
function Calendar_calc_month_year(p_Month, p_Year, incr) {
Will return an 1-D array with 1st element being the calculated month
and second being the calculated year
after applying the month increment/decrement as specified by 'incr' parameter.
'incr' will normally have 1/-1 to navigate thru the months.
var ret_arr = new Array();
if (incr == -1) {
// B A C K W A R D
if (p_Month == 0) {
ret_arr[0] = 11;
ret_arr[1] = parseInt(p_Year) - 1;
else {
ret_arr[0] = parseInt(p_Month) - 1;
ret_arr[1] = parseInt(p_Year);
} else if (incr == 1) {
// F O R W A R D
if (p_Month == 11) {
ret_arr[0] = 0;
ret_arr[1] = parseInt(p_Year) + 1;
else {
ret_arr[0] = parseInt(p_Month) + 1;
ret_arr[1] = parseInt(p_Year);
return ret_arr;
// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();
Calendar.prototype.getMonthlyCalendarCode = function() {
var vCode = "";
var vHeader_Code = "";
var vData_Code = "";
// Begin Table Drawing code here..
vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";
vHeader_Code = this.cal_header();
vData_Code = this.cal_data();
vCode = vCode + vHeader_Code + vData_Code;
vCode = vCode + "</TABLE>";
return vCode;
Calendar.prototype.show = function() {
var vCode = "";
this.gWinCal.document.open();
// Setup the page...
this.wwrite("<html>");
this.wwrite("<head><title>Calendar</title>");
this.wwrite("</head>");
this.wwrite("<body " +
"link=\"" + this.gLinkColor + "\" " +
"vlink=\"" + this.gLinkColor + "\" " +
"alink=\"" + this.gLinkColor + "\" " +
"text=\"" + this.gTextColor + "\">");
this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
this.wwriteA(this.gMonthName + " " + this.gYear);
this.wwriteA("</B><BR>");
// Show navigation buttons
var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
var prevMM = prevMMYYYY[0];
var prevYYYY = prevMMYYYY[1];
var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
var nextMM = nextMMYYYY[0];
var nextYYYY = nextMMYYYY[1];
this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
this.wwrite("[<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
");" +
"\"><<<\/A>]</TD><TD ALIGN=center>");
this.wwrite("[<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
");" +
"\"><<\/A>]</TD><TD ALIGN=center>");
this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
this.wwrite("[<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
");" +
"\">><\/A>]</TD><TD ALIGN=center>");
this.wwrite("[<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
");" +
"\">>><\/A>]</TD></TR></TABLE><BR>");
// Get the complete calendar code for the month..
vCode = this.getMonthlyCalendarCode();
this.wwrite(vCode);
this.wwrite("</font></body></html>");
this.gWinCal.document.close();
Calendar.prototype.showY = function() {
var vCode = "";
var i;
var vr, vc, vx, vy; // Row, Column, X-coord, Y-coord
var vxf = 285; // X-Factor
var vyf = 200; // Y-Factor
var vxm = 10; // X-margin
var vym; // Y-margin
if (isIE) vym = 75;
else if (isNav) vym = 25;
this.gWinCal.document.open();
this.wwrite("<html>");
this.wwrite("<head><title>Calendar</title>");
this.wwrite("<style type='text/css'>\n<!--");
for (i=0; i<12; i++) {
vc = i % 3;
if (i>=0 && i<= 2) vr = 0;
if (i>=3 && i<= 5) vr = 1;
if (i>=6 && i<= 8) vr = 2;
if (i>=9 && i<= 11) vr = 3;
vx = parseInt(vxf * vc) + vxm;
vy = parseInt(vyf * vr) + vym;
this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
this.wwrite("-->\n</style>");
this.wwrite("</head>");
this.wwrite("<body " +
"link=\"" + this.gLinkColor + "\" " +
"vlink=\"" + this.gLinkColor + "\" " +
"alink=\"" + this.gLinkColor + "\" " +
"text=\"" + this.gTextColor + "\">");
this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
this.wwrite("Year : " + this.gYear);
this.wwrite("</B><BR>");
// Show navigation buttons
var prevYYYY = parseInt(this.gYear) - 1;
var nextYYYY = parseInt(this.gYear) + 1;
this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
this.wwrite("[<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
");" +
"\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
this.wwrite("[<A HREF=\"javascript:window.print();\">Print</A>]</TD><TD ALIGN=center>");
this.wwrite("[<A HREF=\"" +
"javascript:window.opener.Build(" +
"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
");" +
"\">>><\/A>]</TD></TR></TABLE><BR>");
// Get the complete calendar code for each month..
var j;
for (i=11; i>=0; i--) {
if (isIE)
this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
else if (isNav)
this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
this.gMonth = i;
this.gMonthName = Calendar.get_month(this.gMonth);
vCode = this.getMonthlyCalendarCode();
this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
this.wwrite(vCode);
if (isIE)
this.wwrite("</DIV>");
else if (isNav)
this.wwrite("</LAYER>");
this.wwrite("</font><BR></body></html>");
this.gWinCal.document.close();
Calendar.prototype.wwrite = function(wtext) {
this.gWinCal.document.writeln(wtext);
Calendar.prototype.wwriteA = function(wtext) {
this.gWinCal.document.write(wtext);
Calendar.prototype.cal_header = function() {
var vCode = "";
vCode = vCode + "<TR>";
vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sat</B></FONT></TD>";
vCode = vCode + "</TR>";
return vCode;
Calendar.prototype.cal_data = function() {
var vDate = new Date();
vDate.setDate(1);
vDate.setMonth(this.gMonth);
vDate.setFullYear(this.gYear);
var vFirstDay=vDate.getDay();
var vDay=1;
var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
var vOnLastDay=0;
var vCode = "";
Get day for the 1st of the requested month/year..
Place as many blank cells before the 1st day of the month as necessary.
vCode = vCode + "<TR>";
for (i=0; i<vFirstDay; i++) {
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
// Write rest of the 1st week
for (j=vFirstDay; j<7; j++) {
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
"<A HREF='#' " +
"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
this.format_data(vDay) +
"';window.close();\">" +
this.format_day(vDay) +
"</A>" +
"</FONT></TD>";
vDay=vDay + 1;
vCode = vCode + "</TR>";
// Write the rest of the weeks
for (k=2; k<7; k++) {
vCode = vCode + "<TR>";
for (j=0; j<7; j++) {
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
"<A HREF='#' " +
"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
this.format_data(vDay) +
"';window.close();\">" +
this.format_day(vDay) +
"</A>" +
"</FONT></TD>";
vDay=vDay + 1;
if (vDay > vLastDay) {
vOnLastDay = 1;
break;
if (j == 6)
vCode = vCode + "</TR>";
if (vOnLastDay == 1)
break;
// Fill up the rest of last week with proper blanks, so that we get proper square blocks
for (m=1; m<(7-j); m++) {
if (this.gYearly)
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) +
"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
else
vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) +
"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
return vCode;
Calendar.prototype.format_day = function(vday) {
var vNowDay = gNow.getDate();
var vNowMonth = gNow.getMonth();
var vNowYear = gNow.getFullYear();
if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
else
return (vday);
Calendar.prototype.write_weekend_string = function(vday) {
var i;
// Return special formatting for the weekend day.
for (i=0; i<weekend.length; i++) {
if (vday == weekend<i>)
return (" BGCOLOR=\"" + weekendColor + "\"");
return "";
Calendar.prototype.format_data = function(p_day) {
var vData;
var vMonth = 1 + this.gMonth;
vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
var vY4 = new String(this.gYear);
var vY2 = new String(this.gYear.substr(2,2));
var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;
/* switch (this.gFormat) {
case "MM\/DD\/YYYY" :
vData = vMonth + "\/" + vDD + "\/" + vY4;
break;
case "MM\/DD\/YY" :
vData = vMonth + "\/" + vDD + "\/" + vY2;
break;
case "MM-DD-YYYY" :
vData = vMonth + "-" + vDD + "-" + vY4;
break;
case "MM-DD-YY" :
vData = vMonth + "-" + vDD + "-" + vY2;
break;
case "DD\/MON\/YYYY" :
vData = vDD + "\/" + vMon + "\/" + vY4;
break;
case "DD\/MON\/YY" :
vData = vDD + "\/" + vMon + "\/" + vY2;
break;
case "DD-MON-YYYY" :
vData = vDD + "-" + vMon + "-" + vY4;
break;
case "DD-MON-YY" :
vData = vDD + "-" + vMon + "-" + vY2;
break;
case "DD\/MONTH\/YYYY" :
vData = vDD + "\/" + vFMon + "\/" + vY4;
break;
case "DD\/MONTH\/YY" :
vData = vDD + "\/" + vFMon + "\/" + vY2;
break;
case "DD-MONTH-YYYY" :
vData = vDD + "-" + vFMon + "-" + vY4;
break;
case "DD-MONTH-YY" :
vData = vDD + "-" + vFMon + "-" + vY2;
break;
case "DD\/MM\/YYYY" :
vData = vDD + "\/" + vMonth + "\/" + vY4;
break;
case "DD\/MM\/YY" :
vData = vDD + "\/" + vMonth + "\/" + vY2;
break;
case "DD-MM-YYYY" :
vData = vDD + "-" + vMonth + "-" + vY4;
break;
case "DD-MM-YY" :
vData = vDD + "-" + vMonth + "-" + vY2;
break;
default :
vData = vMonth + "\/" + vDD + "\/" + vY4;
vData = vY4vMonthvDD ;
//vData = vDD"."vMonth"."vY4;
return vData;
function Build(p_item, p_month, p_year, p_format) {
var p_WinCal = ggWinCal;
gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);
// Customize your Calendar here..
gCal.gBGColor="white";
gCal.gLinkColor="black";
gCal.gTextColor="black";
gCal.gHeaderColor="darkgreen";
// Choose appropriate show function
if (gCal.gYearly) gCal.showY();
else gCal.show();
function show_calendar() {
p_month : 0-11 for Jan-Dec; 12 for All Months.
p_year : 4-digit year
p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
p_item : Return Item.
p_item = arguments[0];
if (arguments[1] == null)
p_month = new String(gNow.getMonth());
else
p_month = arguments[1];
if (arguments[2] == "" || arguments[2] == null)
p_year = new String(gNow.getFullYear().toString());
else
p_year = arguments[2];
if (arguments[3] == null)
p_format = "MM/DD/YYYY";
else
p_format = arguments[3];
vWinCal = window.open("", "Calendar",
"width=300,height=250,status=no,resizable=no,top=100,left=100");
vWinCal.opener = self;
ggWinCal = vWinCal;
Build(p_item, p_month, p_year, p_format);
Yearly Calendar Code Starts here
function show_yearly_calendar(p_item, p_year, p_format) {
// Load the defaults..
if (p_year == null || p_year == "")
p_year = new String(gNow.getFullYear().toString());
if (p_format == null || p_format == "")
p_format = "MM/DD/YYYY";
var vWinCal = window.open("", "Calendar", "scrollbars=yes");
vWinCal.opener = self;
ggWinCal = vWinCal;
Build(p_item, null, p_year, p_format); -
Is it a problem with To_char(date,'DAY')???
Hi All
Please see the below query
SQL> select empno,
2 hiredate,
3 to_char(hiredate,'DAY'),
4 decode(to_char(hiredate,'DAY'),'MONDAY',hiredate,next_day(hiredate-7,'MONDAY')) monday,
5 decode(to_char(hiredate,'DAY'),'SUNDAY',hiredate,next_day(hiredate,'SUNDAY')) sunday
6 from emp where empno in (7499,7521,7654,7900,7902);
EMPNO HIREDATE TO_CHAR(H MONDAY SUNDAY
7902 03-DEC-81 THURSDAY 30-NOV-81 06-DEC-81
7900 03-DEC-81 THURSDAY 30-NOV-81 06-DEC-81
7654 28-SEP-81 MONDAY 28-SEP-81 04-OCT-81
7521 22-FEB-81 SUNDAY 16-FEB-81 01-MAR-81
7499 20-FEB-81 FRIDAY 16-FEB-81 22-FEB-81 If you see the 4th row it gives incorrect result i.e. though 22-feb-1981is sunday it returns the date of next sunday.
but if i use trim as below it gives me correct result
SQL> ed
Wrote file afiedt.buf
1 select empno,
2 hiredate,
3 to_char(hiredate,'DAY'),
4 decode(to_char(hiredate,'DAY'),'MONDAY',hiredate,next_day(hiredate-7,'MONDAY')) monday,
5 decode(trim(to_char(hiredate,'DAY')),'SUNDAY',hiredate,next_day(hiredate,'SUNDAY')) sunday
6* from emp where empno in (7499,7521,7654,7900,7902)
SQL> /
EMPNO HIREDATE TO_CHAR(H MONDAY SUNDAY
7902 03-DEC-81 THURSDAY 30-NOV-81 06-DEC-81
7900 03-DEC-81 THURSDAY 30-NOV-81 06-DEC-81
7654 28-SEP-81 MONDAY 28-SEP-81 04-OCT-81
7521 22-FEB-81 SUNDAY 16-FEB-81 22-FEB-81
7499 20-FEB-81 FRIDAY 16-FEB-81 22-FEB-81 I used all inbuilt functions, there is nothing to do with data so why the trim() required here????
Where the problem lies..is it with to_char(date,'DAY')??
Regards,
SatyaAs volder said above, if i change
'next_day(hiredate-7,'MONDAY')' to
'next_day(hiredate,'MONDAY')' it does not work for
monday also.And what exactly you don't understand?
27.08.2007 = MONDAY
next_day(27.08.2007,MODAY) - will be next monday - 03.09.2007
27.08.2007-7=20.08.2007 (last monday)
next_day(20.08.2007,monday)=27.08.2007
SO next_day(27.08.2007-7,monday)=27.08.2007
when you eliminate -7 it will return next monday
everything all right - read about NEXT_DAY in the DOC
Probably you wanted to subtract 8 days, but not 7. Check out with this. -
Reg: error while converting a date datatype to the char using TO_CHAR function.
Hello all,
I'm trying to convert a date datatype to the specified format (i.e., by using vaariable using the to_char function in my sql,
SQL:
select 0 dummy,'select' from dual
union all
select a.COLUMN_ID dummy,
(case a.DATA_TYPE when 'NUMBER' then '''''' || '||' || a.COLUMN_NAME || '||'',''||'
when 'DATE' then '''"''' || '||' || TO_CHAR(a.COLUMN_NAME,'&dateformat') || '||' || '''",''' || '||'
else '''"''' || '||' || a.COLUMN_NAME || '||' || '''",''' || '||'
end)
from DBA_TAB_COLUMNS a
where a.OWNER = upper('&owner_name')
and a.TABLE_NAME = upper('&table_name')
union all
select 998 dummy,''' ''' from dual
union all
select 999 dummy,'from &owner_name..&table_name;' from dual
order by dummy
error:
when 'DATE' then '''"''' || '||' || TO_CHAR(a.COLUMN_NAME,'DD-MM-YYYY') || '||' || '''",''' || '||'
ERROR at line 5:
ORA-01722: invalid number
Please help me in resolving this, Thanks in advance.
Regards,
Konda.> ISA Server is not configured to allow SSL requests from this port. Most Web browsers use port 443 for SSL requests. (12204)
This seems to be your specific network configuration. It seems that your corporate network is blocking HTTPS requests which don't use port 443. Your ABAP system is configured to use a port other than 443. Either talk to your basis admins about changing your ABAP system configuration to use port 443 or talk to your network administrators to allow whichever port the ABAP system is running on. -
Update DSO with planning function independently from saving data in realtim
Dear all,
I have an realtime cube which will be loaded via planning function and/or data entry queries.
In order to track the entries, I store all companies with status in a DSO objects, by using a planning fuction which calls a function module and inserts entries in the DSO table. The planning function will be start by clicking a button in a web application.
For example: A company enters data. The value will be stored in the realtime cube and the DSO entry will be created with company xyz and status 1.
Sometime it is necessary to create a status entry in the DSO without entering data in the realtime cube. ( In order to provide an other department to enter data in during status 1).
In this case the planning function which calls the function module in order to insert entries in DSO is not working because there is no data exchange with the realtime cube.
How can I change DSO entries independently from writing data in a realtime cube or not.
Any help would be great.
Best regards,
Stefan from Munich/GermanyHello Marcel,
i have one planning function which copies data from one version to another within the cube and another planning function (type fox) which calls up an ABAP function module in order to update my status DSO. see below:
DATA FISCYEAR TYPE 0FISCYEAR.
DATA COMPANY TYPE ZMCOMPANY.
FISCYEAR = OBJV( ).
COMPANY = OBJV( ).
CALL FUNCTION Z_FM_SEND_FOR_APP_PLAN_C01
EXPORTING
I_COMPANY = COMPANY
I_FISCYEAR = FISCYEAR.
normal way:
User enters data via query and sends data to headquarters (1. planning functions copy from version 1 to 2 and second planning functions changes status in DSO from 1 to 2.) This works.
not normal way, but somethis necessary:
User does not malke any entries, and headquarters wants to change the status via an own web application. In this case the first planning function runs, but no data were copied because there are no entries. So far thats ok, but at least the second pölanning function should run and change the status in the DSO from 1 to 2. And exacltly this is not working. I suppose that the reason is, that there are no data in the cube.
Any ideas would be great.
Best regards,
Stefan from Munich/Germnay -
How to find the number of data items in a file written with ArryToFile function?
I have written an array of number in 2 column groups to a file using the LabWindows/CVI function ArrayToFile...Now if I want to read the file with FileToArray Function then how do I know the number of items in the file. during the write time I know how many array items to write. but suppose I want the file to read at some later time then How to find the number of items in the file,So that I can read the exact number and present it. Thanks to all
If you are young work to Learn, not to earn.
Solved!
Go to Solution.What about:
OpenFile ( your file );
cnt = 0;
while ((br = ReadLine ( ... )) != -2) {
if (br == -1) {
// I/O error: handle it!
break;
cnt++;
CloseFile ( ... );
There are some ways to improve performance of this code, but if you are not reading thousands of lines it's quite fast.
After this part you can dimension the array to pass to FileToArray... unless you want to read it yourself since you already have it open!
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
DECODE function to validate date value and sort the records
Hi Friends,
I am looking for some query which can give me the required output,
I need to do this using SQL query only and I have tried using the MIN() and MAX() functions it was working fine with limited data, now after inserting the last record(in the below table) which has date for start_range and end_range in(mm/dd/yyyy hh24:mi:ss) format.
Because the data type is VARCHAR2 if I am using the MIN() function it is sorting as a string value, hence the min date is incorrect. I tried using validating the value to date or non date and tried to using MIN() and MAX() functions using the DECODE function, I am getting this error "ORA-01840: input value not long enough for date format".
select table_name,
DECODE(substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1),'// ::',
to_char(min(to_date(start_range,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),min(start_range)) MIN_RUNS_START_RANGE,
DECODE(substr(END_RANGE,3,1)||substr(A.END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1),'// ::',
to_char(max(to_date(END_RANGE,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),max(END_RANGE)) MAX_RUNS_END_RANGE
from MY_TABLE
GROUP BY table_name,
(substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1)),
(substr(END_RANGE,3,1)||substr(END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1))
Can sombody please advise what is the best way I can query this data with the required output.
The following are the source table and records and the out put records using the sql query.
MY_TABLE
TABLE_NAME(VARCHAR2),START_RANGE(VARCHAR2),END_RANGE(VARCHAR2)
TABLE1,1000,10000
TABLE2,ABCD,EEEE
TABLE3,01/12/2010 00:00:00,12/31/2010 23:59:59
TABLE1,10001,20000
TABLE2,EEEF,GGGG
TABLE3,01/01/2011 00:00:00,01/31/2011 23:59:59
OUTPUT :
TABLE_NAME,MIN(START_RANGE),MAX(END_RANGE)
TABLE1,1000,20000
TABLE2,ABCD,GGGG
TABLE3,01/12/2010 00:00:00,01/31/2011 23:59:59
Thanks
Kalycsi also think this is a very bad table design ...
but if you are not able to change it, you could split the select (date and non-date data) and combine the result with UNION like this:
with t as
SELECT 'TABLE1' table_name,'1000' start_range,'10000' end_range FROM dual UNION
SELECT 'TABLE2','ABCD','EEEE' FROM dual UNION
SELECT 'TABLE3','01/12/2010 00:00:00','12/31/2010 23:59:59' FROM dual UNION
SELECT 'TABLE1','10001','20000' FROM dual UNION
SELECT 'TABLE2','EEEF','GGGG' FROM dual UNION
SELECT 'TABLE3','01/01/2011 00:00:00','01/31/2011 23:59:59' FROM dual
SELECT table_name,
TO_CHAR(MIN(TO_DATE(start_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS'),
TO_CHAR(MAX(TO_DATE(end_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS')
FROM t
WHERE start_range LIKE '%/%/%:%:%'
GROUP BY table_name
UNION
SELECT table_name,
MIN(start_range),
MAX(end_range)
FROM t
WHERE start_range NOT LIKE '%/%/%:%:%'
GROUP BY
table_name;
TABLE_ MIN_VALUE MAX_VALUE
TABLE1 1000 20000
TABLE2 ABCD GGGG
TABLE3 01/12/2010 00:00:00 01/31/2011 23:59:59 -
What's wrong with this function
What's wrong with this Function(PL/SQL) in this formaula column definition in Reports 6i
function currdateFormula return Date is
curr_date date;
begin
select to_char(sysdate, 'DD-MM-YYYY') into curr_date from dual;
return(curr_date);
end;
I get the following error in compiling
REP-1401. 'currdateformula'.Fatal PL/SQL error occured. ORA-01843 not a valid month.
The SQL select to_char(sysdate, 'DD-MM-YYYY') from dual; worked well in SQL Plus prompt.
I got a clean compile when i use just sysdate in the function (see below).
function currdateFormula return Date is
curr_date date;
begin
select sysdate into curr_date from dual;
return(curr_date);
end;
Appreciate your help
Raja Lakshmihello,
what you are trying to do :
fetch the current date and return it as the result of the formula-column.
what you are actually doing :
fetch the current date, convert it to text, assign this text to a date-variable which causes an implicit type-conversion.
in your case you create a date-string with the format dd-mm-yyyy. the implicit conversion then tries to convert this string back to date using the NLS settings of your session. depending on your NLS_LANG and NLS_DATE_FORMAT this might work, if your session-date-format is dd-mm-yyyy which obviously it is NOT as you get the error.
what you should do :
select sysdate into curr_date from dual;
this fetches the sysdate and stores it in your date-variable. there is no type conversion needed what so ever.
regards,
the oracle reports team -
Update of a table from a select query with aggregate functions.
Hello All,
I have problem here:
I have 2 tables A(a1, a2, a3, a4, a4....... ) and B( a1, a2, b1, b2, b3). I need to calculate the avg(a4-a3), Max(a4-a3) and Min(a4-a3) and insert it into table B. If the foreign keys a1, a2 already exist in table B, I need to do an update of the computed values into column b1, b2 and b3 respectively, for a1, a2.
Q1. Is it possible to do this with a single query ? I would prefer not to join A with B because the table A is very large. Also columns b1, b2 and b3 are non-nullable.
Q2. Also if a4 and a3 are timestamps what is the best way to find the average? A difference of timestamps yields INTERVAL DAY TO SECOND over which the avg function doesn't seem to work. The averages, max and min in my case would be less than a day and hence all I need is to get the data in the hh:mm:ss format.
As of now I'm using :
TO_CHAR(TO_DATE(ABS(MOD(TRUNC(AVG(extract(hour FROM (last_modified_date - created_date))*3600 +
extract( minute FROM (last_modified_date - created_date))*60 +
extract( second FROM (last_modified_date - created_date)))
),86400)),'sssss'),'hh24":"mi":"ss') AS avg_time,
But this is very long drawn. Something more compact and efficient would be nice.
Thanks in advance for your inputs.
Edited by: 847764 on Mar 27, 2011 5:35 PM847764 wrote:
Hi,
Thanks everyone for such fast replies. Malakshinov's example worked fine for me as far as updating the table goes. As for the timestamp computations, I'm posting additional info: Sorry, I don't understand.
If Malakshinov's example worked for updating the table, but you still have problems, does that mean you have to do something else besides update the table? If so, what?
Oracle version : Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Here are the table details :
DESC Table A
Name Null Type
ID NOT NULL NUMBER
A1 NOT NULL VARCHAR2(4)
A2 NOT NULL VARCHAR2(40)
A3 NOT NULL VARCHAR2(40)
CREATED_DATE NOT NULL TIMESTAMP(6)
LAST_MODIFIED_DATE TIMESTAMP(6) DESCribing the tables can help clarify some things, but it's no substitute for posting CREATE TABLE and INSERT statements. With only a description of the table, nobody can re-create the problem or test their ideas. Please post CREATE TABLE and INSERT statements for both tables as they exist before the MERGE. If table b doen't contain any rows before the MERGE, then just say so, but you still need to post a CREATE TABLE statement for both tables, and INSERT statements for table a.
The objective is to compute the response times : avg (LAST_MODIFIED_DATE - CREATED_DATE), max (LAST_MODIFIED_DATE - CREATED_DATE) and min (LAST_MODIFIED_DATE - CREATED_DATE) grouped by A1 and A2 and store it in table B under AVG_T, MAX_T and MIN_T. Since AVG_T, MAX_T and MIN_T are only used for reporting purposes we have kept it as Varchar (though I think keeping it as timestamp would make more sense). I think a NUMBER would make more sense (the number of minutes, for example), or perhaps an INTERVAL DAY TO SECOND. If you stored a NUMBER, it would be easy to compute averages.
In table B the times are stored in the format : hh:mm:ss. We don't need milliseconds precision. If you don;'t need milliseconds, then you should use DATE instead of TIMESTAMP. The functions for manipulating DATEs are much better.
Hence I was calculating is as follows:
-- Avg Time
TO_CHAR(TO_DATE(ABS(MOD(TRUNC(AVG(extract(hour FROM (last_modified_date - created_date))*3600 +
extract( minute FROM (last_modified_date - created_date))*60 +
extract( second FROM (last_modified_date - created_date)))
),86400)),'sssss'),'hh24":"mi":"ss') AS avg_time,
--Max Time
extract (hour FROM MAX(last_modified_date - created_date))||':'||extract (minute FROM MAX(last_modified_date - created_date))||':'||TRUNC(extract (second FROM MAX(last_modified_date - created_date))) AS max_time,
--Min Time
extract (hour FROM MIN(last_modified_date - created_date))||':'||extract (minute FROM MIN(last_modified_date - created_date))||':'||TRUNC(extract (second FROM MIN(last_modified_date - created_date))) AS min_timeIs this something that has to be done before or after the MERGE?
Post the complete statement.
Is this part of a query? Where's the SELECT keyword?
Is this part of a DML operation? Where's the INSERT, or UPDATE, or MERGE keyword?
What are the exact results you want from this? Explain how you get those results.
Is the code above getting the right results? Are you just asking if there's a better way to get the same results?
You have to explain things very carefully. None of the people who want to help you are familiar with your application, or your needs.
I just noticed that my reply is horribly formatted - apologies! I'm just getting the hang of it.Whenever you post formatted text (such as query results) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing. -
Need help in to_char function
Hi All,
I'm using below sql query to get sysdate with time stamp.
select to_char(sysdate,'YYYYMMDD HH24:MM:SS') from dual
This gives me below result: 20130816 05:08:49
Strangely, when I keep on running the same query, I notice after 60 seconds are complete, time stamp starts with 20130816 05:08:01 again.
Am i missing something here..
Thanks in advanceKarthick_Arp wrote:
Keep a simple thing in mind. Date stored in the DB does not have any format. Format need to be applied while you display. The default date format is specified by the NLS_DATE_FORMAT parameter. You have used TO_CHAR to display date in a specific format. But the problem is that you have converted DATE into string. So if its just for display purpose then set the NLS_DATE_FORMAT, do not use TO_CHAR.
With respect to your issue You need to represent Minute as MI. You have represented it as MM (Month) That's why you see 08 always.
" the problem is that you have converted DATE into string"
No, the problem was that he was explicitly using an incorrect format mask, specifying months where he should have specified minutes.
The problem inherently cannot be the result of converting a DATE into a string. Dates are always converted to strings for presentation, either implicitly by using the controlling setting of NLS_DATE_FORMAT (which can be set at several levels) or explicitly by using the to_char function. Oracle will always convert. It has to. Internally, a date is binary gibberish. But computer screens and printers can only show strings of characters, so the DATE will be converted to a character string, by hook or by crook. And the method of oracle making that conversion is exactly the same. The only thing that varies is how the user chooses to make that specification. And "not choosing" (by not using the to_char function) is still choosing ... choosing to rely on nls_date_format. -
Issue with to_char in sql
Hi,
I am trying to execute below statment which gives me error:
select
CASE
WHEN BAL < =0
THEN 0
ELSE to_char(ABS(BAL),'fm9999999999999999990.90')
END BALANCE
from ACCOUNT_TABLE
Error: inconsitent datatypes: expected NUMBER got CHAR
It works fine when I do not use to_char function. But gives value as '0' instead of '0.00'.
To get value 0.00, I am trying to_char with fm format which is giving above error. Can anyone let me know if I'm giving something wrong here.
Thanks in advanceHi,
998158 wrote:
Hi,
I am trying to execute below statment which gives me error:
select
CASE
WHEN BAL < =0
THEN 0
ELSE to_char(ABS(BAL),'fm9999999999999999990.90')
END BALANCE
from ACCOUNT_TABLE
Error: inconsitent datatypes: expected NUMBER got CHAR
It works fine when I do not use to_char function. But gives value as '0' instead of '0.00'.
To get value 0.00, I am trying to_char with fm format which is giving above error. Can anyone let me know if I'm giving something wrong here.
Thanks in advance
If it works fine when you don't use TO_CHAR, then why use TO_CHAR?
What are you trying to do? Post a little sample data (CREATE TABLE and INSERT statements for different numbers) and the exact results you want from that data.
Above, you're saying "bal <= 0", menaing "do the same thing if bal is less than 0, or if bal is exaclty 0". If you want it to do one thing when bal is less than 0, and something else when bal is exactly 0, then use "<' instead of "<=". For example:
CASE
WHEN bal < 0 -- NOT <=
THEN '0' -- This is a VARCHAR2, to match what the ELSE branch returns
ELSE TO_CHAR (bal, 'fm'fm9999999999999999990.90')
END
The 1st part of the CASE expression takes care of all negative numbers, which is the only situation in which bal <> ABS (bal). If control gets as far as the ELSE clause, then bal is the same as ABS (bal), so there's no need to call ABS.
Maybe you are looking for
-
I have been staring at this for a long time and I hope this doesn't turn out to be as much of a brain twister as the early builds of MobileMe did. However, since I guess there must be plenty of us in the same boat, I figure this might be a good place
-
[SOLVED]Copying multiple files from multiple directories to one folder
Title says it all. I have a discography folder with subfolders of the different years and albums of a band each containing music, some also have more sub folders. What I want to do is copy all of the music (.mp3's) from all the folders and sub fold
-
Download starts but then stops...
So I've read other forums and searched this website for one, but I still can't find the answer. Whenever I try to download the file it will start but then after some time get stuck on a percentage(different every time) and then stop all together. I'v
-
Page-embedded Javascript and uploaded images are not cached.
Hello All, I was reading in Wiki APEX and I found this line mentioned as cons: "Page-embedded Javascript and uploaded images are not cached". The question that I have posted many questions here how to enable the cache for Images and Javascripts but d
-
Somehow the internet and my phone crashed. Called Vonage who reset everything so both phone and internet work, but I have lost emails after 2/16/15.