to-char

How can I format a number as xxx-xx-xxxx?

你说的曾经没有我的故事 提交于 2020-01-01 09:04:19
问题 I am querying social security number data from a stored procedure and I would like to format it as a social security number in my stored procedure. How can I format xxxxxxxxx like xxx-xx-xxxx in Oracle? 回答1: SSN formatting with TO_CHAR SELECT TO_CHAR(012345678, '000g00g0000','nls_numeric_characters=.-') ssn from dual; SSN ----------- 012-34-5678 update: thanks to Gary for pointing out that the '0' format character should be used rather than the '9' to preserve leading zeroes. 回答2: you could

Understanding TO_CHAR to convert dates in oracle

为君一笑 提交于 2019-12-13 09:11:35
问题 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 TO_CHAR(SYSDATE,'MM/DD/YYYY') FROM DUAL; -- 12/19/2017 My question is what kind of date format does the to_char method expecting as the first parameter ? is there a default date format we need to pass? So i tried this below query as well which throws

Oracle to_char subquery in Trigger

拈花ヽ惹草 提交于 2019-12-13 03:35:33
问题 I have a table (Meeting) with date type attribute (MeetDate) and another varchar2 type attribute (WorkWeek). I'm trying to do an After trigger to fill in the WorkWeek field based on the MeetDate value using the to_char function. Tried the following codes separately and they compile without errors but when I try to insert a row with Null for WorkWeek, it gives me a 'mutating trigger/function may not see it' error. What am I doing wrong here? thanks in advance to any help. --Code 1 Create or

Oracle To_Char function V in format string

馋奶兔 提交于 2019-12-13 03:34:20
问题 I was given Oracle code and I'm trying to figure out what it is doing. Specifically it's converting a number to a string and I don't understand it. The code is: TO_CHAR(QTY_DISPENSED,'0000000V000') What does the V do? Jeff 回答1: It's a "Format Model" for converting numbers to strings: https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm Returns a value multiplied by 10n (and if necessary, round it up), where n is the number of 9's after the V. So basically it's taking

Oracle Time Comparisons

 ̄綄美尐妖づ 提交于 2019-12-12 16:19:04
问题 Is Oracle (10g) doing a proper TIME comparison here, or do I need to convert to decimal time and then compare? E.g., IF (SELECT TO_CHAR(sysdate,'HH24:MI:SS') from dual) <= '15:00' THEN (...) Thanks. 回答1: IF (sysdate <= trunc(sysdate)+15/24) THEN (...) should do the trick... 回答2: You can't do a select in an if statement, but you can do a direct comparison to sysdate. If you're doing it like this it would probably be better to use a number rather than relying on implicit conversion. You also

TO_CHAR and TO_DATE giving different results.How to achieve the TO_CHAR functionality using TO_DATE?

浪子不回头ぞ 提交于 2019-12-12 13:25:10
问题 SELECT TO_CHAR((select logical_date -1 from logical_date where logical_date_type='B'),'DD/MM/YYYY HH24:MI:SS') FROM DUAL; This Query returns 23/04/2016 00:00:00 o/p of select logical_date -1 from logical_date where logical_date_type='B' :4/23/2016 SELECT TO_DATE((select logical_date -1 from logical_date where logical_date_type='B'),'DD/MM/YYYY HH24:MI:SS') FROM DUAL; This Query returns 4/23/0016 . How do I get the format given by TO_CHAR using TO_DATE ?? 回答1: Dates do not have any intrinsic

Oracle number and varchar join

青春壹個敷衍的年華 提交于 2019-12-12 08:22:54
问题 I have a query that joins two tables. One table has a column that is of type varchar, and the other table has type of number. I have executed my query on 3 oracle databases, and am seeing some strange results I hope can be explained. On two of the databases something like the following works. select a.col1, b.somecol from tableA a inner join tableB b on b.col2=a.col1; In this query tableA.col1 is of type number and tableB.col2 is of type varchar. This works fine in two of the databases but

Adding month and date values to an attribute containing only year psql

人走茶凉 提交于 2019-12-12 03:43:49
问题 Right now I have dates that look like this format(datecreated from table2) +1999 +1999 -0700 -0480 And I want them to look like (inserted into creationdate in table) 1999/12/31 1999/12/31 -700/12/31 -480/12/31 This is my best attempt so far (the numid and accnum are just to find where the records match) update table set creationdate = to_date('1231'||(to_char((select datecreated from table2 m, table n where m.accnum = n.numid), 'sg9999')),'MMDDSGYYYY'); 来源: https://stackoverflow.com/questions

to_char and to_date are returning different output

旧街凉风 提交于 2019-12-12 02:55:46
问题 I am using below queries. select sysdate from dual where to_char(sysdate,'DD-MM-YY')='28-MAY-13'; and the output is null. But for below query, output is current date. select sysdate from dual where to_date(sysdate,'DD-MM-YY')= to_date('28-MAY-13','DD-MM-YY'); Why the to_char function can not return the sysdate? Shouln't we use to_char to compare date? 回答1: Try 'DD-MON-YY' format to map to '28-MAY-13' 'MM' maps to the month number. EDIT: SQL can figure out to use the correct format in to_date;

Oracle To_Char function How to handle if it's already a string

我怕爱的太早我们不能终老 提交于 2019-12-10 19:26:02
问题 Scenario: I am calling a function that returns a field that the user enters in. The field usually returns a number like '120000' which I then use to_char to convert into '120,000'. Problem: Some users enter in values such as '120,000' which gives me an error when trying to use to_char. Also the function will return a space ' ' if no value is found. I tried something with to_number earlier and it has a problem with the ' ' I believe. Question: What would be the best way to handle this problem?