Questions tagged [to-char]

The TO_CHAR function converts another data type (e.g. NUMBER, DATE) to a text. Use for questions about the use of this function.

The TO_CHAR function converts another data type (e.g. NUMBER, DATE) to text. It is usually used to format output data.


Sources:

215 questions
0
votes
2 answers

Case statement when extracting day from date

I have this code to select the day for April 23, 2012. It's supposed to return the letter 'A' but instead returns the letter 'G'. SELECT case to_char( (select pp.datestart from adempiere.pp_order pp where pp.datestart = '2012-04-23' limit 1) ,…
user1353252
  • 39
  • 1
  • 6
-1
votes
3 answers

Oracle TO_CHAR Format Module 'FM099999999V99MI' equivalent in SQL Server

I am moving data from Oracle to an MS SQL server. I'm using a TO_CHAR Format module for the amount field to change the amount to the desired format using FM. I'm looking for an equivalent function in the SQL server to get the same…
Sampath
  • 21
  • 2
-1
votes
2 answers

Convert a VARCHAR value to a formatted date, ignoring errors

I have a column containing dates in the format yyyy-mm-dd. Now I'm running a SELECT query that converts that date to dd/mm/yyyy using TO_CHAR(dob :: DATE, 'dd/mm/yyyy') AS dob which works just fine. Now the problem I've encountered is that there are…
Clint_A
  • 518
  • 2
  • 11
  • 35
-1
votes
2 answers

SQL : how to find max time where its type is varchar2

I have a question in which I have to find details of the store from a store table which opens the latest during the weekend. in store table, I have an attribute named weekendHours with the type varchar2 and the example is : (10:00 am - 5:00pm). I…
-1
votes
3 answers

Understanding TO_CHAR to convert dates in oracle

I have an oracle data problem which i would like to understand. So below are some queries which i executed and on comments are the outputs. SELECT SYSDATE FROM DUAL; --19-DEC-17 SELECT TO_CHAR(SYSDATE,'DD/MM/YYYY') FROM DUAL; -- 19/12/2017 SELECT…
Hudhaifa Yoosuf
  • 869
  • 2
  • 12
  • 28
-1
votes
2 answers

change DD-MMM-YYYY to YYYYMMDD in oracle

i have a date 07-OCT-2017, I have to get it converted as 20171007 in oracle. Below code doesn't work for me select To_date(to_char('07-OCT-2017','DD-MMM-YYYY'), 'yyyymmdd') from dual;
user2814847
  • 35
  • 1
  • 7
-1
votes
2 answers

Formatting date when using CAST

I would like to use CAST to convert a DATE type to a VARCHAR2 type. DBUSER >SELECT CAST(CURRENT_DATE AS VARCHAR2(20)) THE_DATE from DUAL; THE_DATE -------------------- 09-AUG-17 However, I need the VARCHAR2 result to be formatted as 'YYYYMM'. I…
lit
  • 14,456
  • 10
  • 65
  • 119
-1
votes
4 answers

How can I show the counts of each group in my query as percentages?

I have a column in mytable(Movies), Actors. I am trying to get percentage of times each actor shows up. CREATE TABLE movies AS SELECT * FROM ( VALUES ('Robert DeSouza'), ('Tony Wagner'), ('Sean Cortese'), ('Robert DeSouza'), ('Robert…
-1
votes
2 answers

char array stores null values

I am currently doing some code challenges and i have run into a problem which i cant find a solution to. public static bool SelfDescribing(string num) { char[] digit = num.ToArray(); int bound = digit.Count(); for (int i = 0;…
Claudi
  • 125
  • 1
  • 1
  • 9
-1
votes
1 answer

To_CHAR(SYSDATE, ...) ----> TO_DATE

So i have this code : create or replace TRIGGER tr_after_logon AFTER LOGON ON SCHEMA DECLARE var_date VARCHAR(20); BEGIN SELECT TO_CHAR(SYSDATE, 'DD:MM:YYYY HH24:MI:SS') INTO var_date FROM DUAL ; INSERT INTO activity_log (numero,…
-1
votes
1 answer

PostgreSQL , to_char function

I have this number 0101110 but i need only 5 digits. for exemple (01110) i used this select to_char(trim('0101110')::int,'99999V') but PG returns ##### if someone can help me , thanks a lot.
-1
votes
1 answer

Wrong Years in SQL

I have been trying to work this problem out for hours. My numbers are about a year off. Can someone please tell me what I am doing wrong? Here is the question and expected results: Create a list of student names from area code 203 along with the…
-1
votes
1 answer

to_char returning wrong date postgresql

So in my database i have a table with startimestamp that is "Timestamp with time zone" type but what i want to display the timestamp without the time zone so i thought this would work Select to_char("StartTimestamp",'YYYY/MM/DD HH24:MM:SS')from…
Ubaldo Quintero
  • 169
  • 3
  • 15
-2
votes
1 answer

Convert functions with joins

SELECT D.DATEVAL, D.DAY, D.MONVAL, D.YEARVAL, E.HIREDATE FROM DATE1 D, EMP E WHERE TO_DATE('D.DATEVAL-D.MONVAL-D.YEARVAL','DD-MON-YYYY') = E.HIREDATE; Is this subquery correct or not? My requirement is…
GOVINDREDDY
  • 23
  • 1
  • 7
-2
votes
1 answer

Formatting a '$' dollar sign to an SQL Selection Statement with SUM() in it?

I'm trying to format a '$' dollar sign to column "c" which is the SUM of all rows of two other columns multiplied together. I first turn it into a character as follows: SELECT TO_CHAR(SUM(a * b)) AS "c" FROM table1; which works fine, but…
5120bee
  • 689
  • 1
  • 14
  • 36
1 2 3
14
15