to-char

Oracle “Invalid Number” caused by to_char function

一世执手 提交于 2019-12-04 06:33:19
问题 I have the following SQL query which is looking for duplicate values in a table (two values being null must be classed as a duplicate, hence the use of nvl): select * from PersonLinkTable personLink where personLink.RefPerson = 100 and nvl(to_char(personLink.PersonLinkType), '###') = nvl(to_char(PersonLinkTable.PersonLinkType), '###') // Repeats for required columns The third line repeats for the required columns, and is generated automatically in case any new columns are added in the future.

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

做~自己de王妃 提交于 2019-12-04 05:08:28
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? 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. you could also use the concat operator || , which might be more readable. SUBSTR(data, 1, 3) ||'-'||SUBSTR(data, 4, 2)||'-'|

string to char array, showing silly characters

∥☆過路亽.° 提交于 2019-12-04 05:01:09
问题 It is a really simple question but I need an another eye to look at my code: String strtr = "iNo:"; char[] queryNo = strtr.toCharArray(); System.out.println(queryNo + " =this is no"); and the output is: [C@177b4d3 =this is no What are these characters, do you have any idea ? 回答1: That's how toString() is implemented for arrays. The [C denotes that is a char array, 177b4d3 is its hashcode. You may want to look at System.out.println(Arrays.toString(queryNo) + " =this is no"); if you want to see

Oracle number and varchar join

一世执手 提交于 2019-12-04 00:13:46
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 not in the third. In the third I get (ORA-01722) error. In the third I need to do something like...

Oracle “Invalid Number” caused by to_char function

久未见 提交于 2019-12-02 07:50:26
I have the following SQL query which is looking for duplicate values in a table (two values being null must be classed as a duplicate, hence the use of nvl): select * from PersonLinkTable personLink where personLink.RefPerson = 100 and nvl(to_char(personLink.PersonLinkType), '###') = nvl(to_char(PersonLinkTable.PersonLinkType), '###') // Repeats for required columns The third line repeats for the required columns, and is generated automatically in case any new columns are added in the future. The problem is that when I added to_char, this was tested and caused an "Invalid Number" Oracle error.

string to char array, showing silly characters

最后都变了- 提交于 2019-12-02 04:39:29
It is a really simple question but I need an another eye to look at my code: String strtr = "iNo:"; char[] queryNo = strtr.toCharArray(); System.out.println(queryNo + " =this is no"); and the output is: [C@177b4d3 =this is no What are these characters, do you have any idea ? That's how toString() is implemented for arrays. The [C denotes that is a char array, 177b4d3 is its hashcode. You may want to look at System.out.println(Arrays.toString(queryNo) + " =this is no"); if you want to see your original String again, you need this: System.out.println((new String(queryNo)) + " =this is no");

TO_char returning slash value after converting a number to String

∥☆過路亽.° 提交于 2019-12-02 00:34:16
问题 I am having a database column amount [Data type Number(32,12)] .When i use to_char on the amount field i get a slash value appended in the output. When i directly used the value stored in the amount field ,i am getting the correct value select TO_Char(0.000000000099,'FM99999999999999999999999999999990.099999999999') from dual; Output:- 0.000000000099 回答1: It looks like you have corrupted data in your table. Which leads to a few questions including how did it get there, and what can you do

Selecting floating point numbers in decimal form

天涯浪子 提交于 2019-12-01 23:58:13
问题 I've a small number in a PostgreSQL table: test=# CREATE TABLE test (r real); CREATE TABLE test=# INSERT INTO test VALUES (0.00000000000000000000000000000000000000000009); INSERT 0 1 When I run the following query it returns the number as 8.96831e-44 : test=# SELECT * FROM test; r ------------- 8.96831e-44 (1 row) How can I show the value in psql in its decimal form ( 0.00000000000000000000000000000000000000000009 ) instead of the scientific notation? I'd be happy with 0

Selecting floating point numbers in decimal form

心已入冬 提交于 2019-12-01 21:40:36
I've a small number in a PostgreSQL table: test=# CREATE TABLE test (r real); CREATE TABLE test=# INSERT INTO test VALUES (0.00000000000000000000000000000000000000000009); INSERT 0 1 When I run the following query it returns the number as 8.96831e-44 : test=# SELECT * FROM test; r ------------- 8.96831e-44 (1 row) How can I show the value in psql in its decimal form ( 0.00000000000000000000000000000000000000000009 ) instead of the scientific notation? I'd be happy with 0.0000000000000000000000000000000000000000000896831 too. Unfortunately I can't change the table and I don't really care about

Why is Oracle's DECODE giving me a different value than NVL?

无人久伴 提交于 2019-11-29 11:18:37
This query: select nvl(0.75,0) from dual gives me 0.75 (numeric) but this query: select decode(1,0,null,0.75) from dual gives me '.75' (string). Why? I tried to fix this by changing the second query to: select decode(1,0,null,to_char(0.75,'0.99')) from dual but in my actual code the 0.75 will be a field (NUMBER) that may have a different number of decimal places and I'm not suppose to add/remove anything from that value. Any ideas on how to fix the missing zero issue but still support all possible decimal lengths? It's because the 3 rd parameter of your decode statement is NULL; as per the