This question already has answers here:
SQL to find first non-numeric character in a string
(3 answers)
Closed 7 years ago.
How to find last non-numeric character in a string such as "10jnklgm51". In order to find 'm' in the example what is the best simple way?
The last non-numeric character is the first non-numeric character in the reverse string. So, something like this:
select substring(reverse(str),
patindex('%[^0-9]%', reverse(str)),
1)
Related
This question already has answers here:
How to count the number of occurrences of a character in an Oracle varchar value?
(9 answers)
Closed last month.
How can i count the number of 'a' in the string 'rajarajeshwari'
I want count of 'a' in that string
You can try like this
select length('rajarajeshwari') - length(replace('rajarajeshwari','a',null))
from dual;
DEMO
or you can also use the REGEXP_COUNT function
select REGEXP_COUNT('rajarajeshwari', 'a') from dual;
DEMO
This question already has answers here:
How to convert Roman numerals into decimal numbers?
(4 answers)
Closed 4 months ago.
I want to convert some Roman numerals into numbers. There are some quite complex methods, but I wonder whether it's possible to use TO_NUMBER fuction.
There's a 'RN' format, it works well other way round, say:
SELECT
TO_CHAR('1998', 'RN')
FROM DUAL;
However this won't work:
SELECT
TO_NUMBER('MCMXCVIII', 'RN')
FROM DUAL;
Any ideas?
thanks,
You can't use the function "TO_NUMBER" o "TO_CHAR" for convert a roman number to decimal, but today there is a algorithm for do it.
This algorithm use CTE / recursive subquery.
For each character, starting from the RIGHT (lowest value Roman numeral):
1.- Convert the character into the value it represents
2.- If the character’s value is greater than or equal to the previous one, add the value to the running total
3.- If character’s value is less than the previous one, subtract the value from the running total
Below, I leave you the url the documentation and the script.
References:
http://rdbms-insight.com/wp/2015/roman-numerals-to-decimal-in-sql/
https://livesql.oracle.com/apex/livesql/file/content_CESOH7H2D4O88XLW60330Q3L9.html
I hope to help you :)
This question already has answers here:
Convert pyspark string to date format
(6 answers)
Closed 2 years ago.
I have a string containing date in it.
It looks like:
01JAN2020
02FEB2020
I use the following code to parse it to date format but didn't succeed:
a= a.withColumn('dt_one', to_date(unix_timestamp(col('dt_one'), 'dLy').cast("timestamp")))
Do you know the right syntax to do this?
Thanks!
I think this should work:
a= a.withColumn('dt_one', to_date(unix_timestamp(col('dt_one'), 'dMMMy').cast("timestamp")))
This question already has answers here:
Want to convert from character format to number format with decimal
(2 answers)
Closed 6 years ago.
I have character string as '00000625710' I want it as number 6257.10 how can I do that . I tried as follow
select to_number('00000002511','999999999.99')from dual;
But didn't work . can any one help me in this . Thank you.
If you know that the least 2 characters are always decimal (more generally, that the structure of your input strings is fixed), you can simply divide:
select to_number('00000002511') / 100 from dual;
This question already has answers here:
How to convert float to varchar in SQL Server
(15 answers)
Closed 8 years ago.
I am trying a number column to varchar in SQL select statement. It is returning in exponential value. How can I get as it is in string
Select CAST([Loan Number] as nVARCHAR(50)) as strLoanNumber
From
[tbl_DS] Where [Loan] like '%CWALT_2006%'
Actual value is 127160640
Returning value is 1.27161e+008
Try using
convert(nvarchar(50),[loan number])