Oracle to_number(1234.567)? - sql

I am trying to convert a number of type varchar(e.g 1234.456) in to floating point number using oracle function to_number(). In my PC (Locale German) the Oracle SQLDeveloper returning number in the fromat 1234,567 instead of 1234.567 and inturn it is causing the oracle error ORA-01722-invalid number. I cahnged my system locale to en_usa but no use. How can i change the behavior of oracle ?
Help will be greatly appriciated

Try it like this:
SELECT to_number('1234.5678', '9999D9999', 'NLS_NUMERIC_CHARACTERS=.,')
FROM dual;
Here is a fiddle

Related

Oracle convert blob to string

I would like to convert a blob of an oracle db to an readable string.
I have tried some functions, but none of them worked for me.
In the end I tried to convert the string via sql statement like:
SELECT CONVERT(CAST(blob as BINARY) USING utf8) as blob FROM tablewithblob
Can anyone tell me, what I am doing wrong? The error of the sqldeveloper is "missing right paranthesis. Thanks in advance!
The CONVERT(value USING charset) function is a mysql function, not Oracle
https://www.w3schools.com/sql/func_mysql_convert.asp
Take a look at this instead
https://docs.oracle.com/cd/B28359_01/server.111/b28286/functions027.htm
But it looks like DBMS_LOB is a better way to do what you're doing in Oracle. Go check out How do I get textual contents from BLOB in Oracle SQL

colon(:) and dot(.) as millisecond separator in datetime2

I have migrated a Sybase database to SQL server 2008.
The main application that using the database trying to set some of dateTime2 column with data like 1986-12-24 16:56:57:81000 which is giving this error:
Conversion failed when converting date and/or time from character string.
Running the same query using dot(.) instead of colon(:) as millisecond separator like 1986-12-24 16:56:57.81000 or limiting the milliseconds to 3 digits like 1986-12-24 16:56:57:810 will solve the problem.
NOTE:
1- I don't have access to the source of application to fix this issue and there are lots of table with the same problem.
2. Application connect to database using ODBC connection.
Is there any fast forwarding solution or should i write lots of triggers on all tables to fix it using the above solutions?
Thanks in advance
AS Gordon Linoff said
A trigger on the current table is not going to help because the type
conversion happens before the trigger is called. Think of how the
trigger works: the data is available in a "protorow".
But There is a simple answer!
Using SQL Server Native Client Connection instead of basic SQL Server ODBC connection handle everything.
Note:
1. As i used SQL Server 2008 version 10 of SQL server native client works fine but not the version 11 (it's for SQL Server 2012).
2. Use Regional Settings make some other conversion problem so don't use it if you don't need it.
Select REPLACE(getdate(), ':', '.')
But it will Give String Formate to datetime Which is not covert into DateTime formate
Why would you need triggers? You can use update to change the last ':' to '.':
update t
set col = stuff(col, 20, 1, '.');
You also mistakenly describe the column as datetime2. That uses an internal date/time format. Your column is clearly a string.
EDIT:
I think I misinterpreted the question (assuming the data is already in a table). Bring the data into staging tables and do the conversion in another step.
A trigger on the current table is not going to help because the type conversion happens before the trigger is called. Think of how the trigger works: the data is available in a "protorow".
You could get a trigger to work by creating views and building a trigger on a view, but that is even worse. Perhaps the simplest solution would be:
Change the name and data type of the column so it contains a string.
Add a computed column that converts the value to datetime2.

Convert ORA_HASH to SQL Server

I am trying to convert an Oracle query to a SQL Server and facing an issue. Can you please help me ?
Oracle Query:
select ORA_HASH(SYS_GUID()) as SEGMENTID from my_Table
I am looking for a function which is equivalent to ORA_HASH() function in SQL Server. I was searching in google and found that HASHBYTES() function is the one which works as ORA_HASH in SQL Server. But when I tried to use, the return value of this is Hexa decimal and on the other hand, ORA_HASH is returning an integer.
Can you please help me in proving the equivalent function to ORA_HASH in SQL Server which works same as ORA_HASH ?
You shall try CHECKSUM which as per doc is intended for use in building hash indexes. https://learn.microsoft.com/en-us/sql/t-sql/functions/checksum-transact-sql

Functions not working in Table Adapter Query bulider

I'm using Visual Studio 2013, I try to use some function (like "cast" and Year ) in Table Adapter Query Builder (in DataSet.XSD ). I get erroe messgae every time. I run the sql statement on other sql programs and it's work fine. did anyone face this problem?
Is your dataSource SQL Server or SQLite. If you are using SqLite then functions such as Year(),Cast() are not allowed.
If you are using SQLite then please find below link for date time function reference,
https://www.sqlite.org/lang_datefunc.html
As you have asked for Cast function, there is SO post describing the cast function, which is similar to that of SQL Server
SQLite supports CAST and:
Casting an INTEGER or REAL value into TEXT renders the value as if via sqlite3_snprintf() except that the resulting TEXT uses the
encoding of the database connection.
So you can do things like this:
select cast(some_integer_column as text) from some_table;
Or, depending on what you're trying to do, you could just treat the
numbers as strings and let SQLite coerce the types as it sees fit:
select some_int || ' pancakes' from some_table; select some_int || ''
from some_table;
SQLite does not have this function YEAR(...). Try strftime('%Y', degrees.ExamDate) = '2017' instead.

error that i get in Oracle 11.2

1.0.6 my program works excellent
but in Oracle 11.2 i get error ORA-01830
what can be the problem ? is there any Difference between 11.1 and 11.2 ?
thanks in advance
There is a parameter called NLS_DATE_FORMAT, which defines how your dates are converted to characters as default. You are probably treating a string as date, and Oracle tries to automatically convert it to date but fails. You may want to set that parameter to the one you used in 11.1;
ALTER SYSTEM SET NLS_DATE_FORMAT='<Your Date Format In 11.1 Here>';
The error is:
ORA-01830: date format picture ends
before converting entire input string
So it could be cause by different default date format masks (NLS_DATE_FORMAT parameter) in the 2 environments.