Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to escape non-format characters in Oracle's to_char?

I am trying to print a date in a select statement, but I need to add a letter to the output:

to_char(date_updated, 'YYYY-MM-DDTHH:mm:ss') 

Oracle does not like the T. I just want the T to be output like the colons and the dashes. Can I escape it with a backslash or something?

like image 762
Sixty4Bit Avatar asked Feb 25 '09 23:02

Sixty4Bit


People also ask

How do I escape special characters in Oracle?

Use braces to escape a string of characters or symbols. Everything within a set of braces in considered part of the escape sequence. When you use braces to escape a single character, the escaped character becomes a separate token in the query. Use the backslash character to escape a single character or symbol.

What can we use instead of TO_CHAR in SQL?

SQL Server has separate functions for YEAR() , MONTH() , and DAY() . Oracle uses TO_CHAR() ; SQL Server uses CONVERT() . One option is to define the functions YEAR() , MONTH() , and DAY() in Oracle and then use string concatenation (via the CONCAT() ) function to combine the data.

How do I add an escape character in Oracle?

You can include the actual characters % or _ in the pattern by using the ESCAPE clause, which identifies the escape character. If the escape character precedes the character % or _ in the pattern, then Oracle interprets this character literally in the pattern rather than as a special pattern-matching character.

What does TO_CHAR mean in Oracle?

The Oracle TO_CHAR() function converts a DATE or INTERVAL value to a string in a specified date format. The Oracle TO_CHAR() function is very useful for formatting the internal date data returned by a query in a specific date format.


1 Answers

You just need double-quotes around it:

to_char(date_updated, 'YYYY-MM-DD"T"HH:mm:ss') 
like image 106
Chad Birch Avatar answered Sep 28 '22 08:09

Chad Birch