format of the 'TEXT' in OCINumberFromText in C code - sql

I want to insert values like B194YV into an array and ultimately to OCINumber to use in Oracle statement.
I tried to insert like this
rc = OCINumberFromText(errhp, (text*)new_value, strlen(new_value),
(text*)"99G999D99", 9, (text *)"NLS_NUMERIC_CHARACTERS='.''", 27, &num_val);
Here new_value has value B194YV, but it doesnt work. i get error
OCI-22062: invalid input string [B194YV]
I know 99G999D99 is not the correct format, so can anyone please tell me what format should i write?
Thank you

You are trying to convert a string "B194YV" to a number. This is simply not possible. It's not a number.

Related

Getting: INVALID_FUNCTION_ARGUMENT: Invalid format: "" when trying to date_parse a string formatted date

Query:
SELECT date_parse(start_date, '%Y/%m/%d')
FROM sql_question_five_2 ;
date format looks like this in csv: 20210531
being read into table as string.
Have tried a few different things to get it to convert to a date YYYY-MM-DD
date_parse expects all inputs to look like the format string, if they don't it will throw an error. You can do something like this to avoid the problem:
SELECT IF(start_date = '', NULL, date_parse(start_date, '%Y/%m/%d'))
FROM sql_question_five_2
This guards against the case where the string is empty, which is the case when you get the error. If you have other strings that don't conform to the format you would have to guard against those too.
If that is the case you can use the TRY function which captures errors and returns NULL:
SELECT TRY(date_parse(start_date, '%Y/%m/%d'))
FROM sql_question_five_2
Your format string needs to match the source value. Your source doesn’t have /‘s in it so your format string shouldn’t either

SQL ORACLE : Is it possible to convert NUMBER with CHAR (varchar2 datatype) to NUMBER datatype

I have a big problem right now and I really need your help, because I can't find the right answer.
I am currently writing a script that triggers a migration process from a table with raw data (data we received from an excel file) to a new normalized schema.
My problem is that there is a column PRICE (varchar2 datatype) with a bunch of traps. For example: 540S, 25oo , I200 , S000 .
And I need to convert it to the correct NUMBER(9,2) format so I can get: 5405, 2500, 1200, 5000 as NUMBER for the previous examples and INSERT INTO my_new_table.
Is there any way I can parse every CHAR of these strings that verify certain conditions?
Or others better way?
Thank you :)!
One of the wonderful things about Oracle that some other DBs lack, is the TRANSLATE function:
SELECT TRANSLATE(number, 'SsIilOoxyz', '5511100') FROM t
This will convert:
S, s to 5
I, i and l to 1
O, o to 0
Remove any x, y or z from the number
The second and third arguments to translate define what characters are to be mapped. If the first string is longer than the second then anything over the length of the second is deleted from the resulting string. Mapping is direct based on position:
'SsIilOoxyz',
'5511100'
Look at the columns of the characters; the character above is mapped to the character below:
S->5,
s->5,
I->1,
i->1,
l->1,
O->0,
o->0,
x->removed,
y->removed,
z->removed`
You can use translate() and along with to_number(). Your rules are not exactly clear, but something like this:
select to_number(translate(price, '0123456789IoS', '012345678910'))
from t;
This replaces I with 1, o with 0, and removes S.

Repeat characters based on a number

I'm supposed to convert a certain integer value to an asterisk for the exact value of that integer.
Example: Given value = 10, I have to have 10 asterisk **********.
Is it possible by using the REPLACE function?
This should help you..
SELECT RPAD('*',10,'*') from dual;

SQL converting float to varchar

I've 2 columns which I want to use a condition on. But I get this error message and my query is correct I'll come to that soon.
Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to float.
So this is the problem, I have a temp-table in which ID-number looks like this 9001011234 we can call it A, in the other one that I want to check with it looks like this 900101-1234 and this one for B this is the swedish format for Id-numbers.
So in my condition I want to check this to get the right amount and the correct result.
where A = B
The rest of the query is fine, when I remove this condition it gives me a result. It's just this one bit that is incorrect.
You have a VARCHAR format that can't be trivially transformed to a number. I'd use REPLACE(b,'-','') = a to fix the format, and let SQL Server take care of the rest.
Say:
where A = CAST(REPLACE(B, '-', '') AS float)
You are trying to compare values that are not the same datatype. eg Where 'one' = 1
You will need to convert one of the values to the same datatype as the other.

I just do not understand why this query does not pull results

Okay, this is the most simple query in the world, and it is somehow failing.
SELECT * FROM kal_auth.dbo.Login WHERE ID = 'Zen' AND PWD = CONVERT(varchar,'0x9248FEFE237DB009')
0x9248FEFE237DB009 is not hex, although it looks like it. but it converts to "Password"
I know this row exists, and its only the password field which is not returning results, this was learned by isolating them and testing.
The PWD field is varchar(16).
I do not understand this.
Use
SELECT CONVERT(VARCHAR,0x9248FEFE237DB009) -- returns ’Hþþ#}°
Not
SELECT CONVERT(varchar,'0x9248FEFE237DB009') -- returns 0x9248FEFE237DB009
By encasing it in quotes it gets treated as a string not as binary data meaning the conversion to varchar doesn't do anything!
I may be missing something here...
The result of CONVERT(varchar,'0x9248FEFE237DB009') is the same '0x9248FEFE237DB009' with 18 chars, isn't it? So how could it be equal to a 16 char password?