How do I do this in Oracle Query? this is saying that we want the records which has ‘1’ inleft most position in that column.
AND substring(convert(varchar,TR.MENU_ID_VALUE), 1, 1) = '1'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
convertfunction function transforms a string from one character set into another. The syntax isconvert(<string>, <to character set>, <from character set>)Also,
substringisn’t an Oracle function, it’ssubstr.If you don’t need to convert the string then
and substr(tr.menu_id_value,1,1)will get you the leftmost character.If you do want to convert the character set then the full list is available in the documentation, alternatively you can query
v$nls_valid_values. For instance if you’re converting from WE8MSWIN1252 (Windows code-page 1252) to AL32UTF8 (UTF-8) then your condition would become:From your comment I’m guessing that
convert()is the SQL-Server function to convert between data-types. The Oracle equivalent, in this case, would beto_char. Though Oracle will implicitly do the conversion it is always best to useto_charand convert explicitly; giving you:Incidentally the exact Oracle equivalent is
cast(). Strictly speaking,to_char()should be used if you want to use a format model, thussubstr(cast tr.menu_id_value as varchar2(10)),1,1)would also give you what you’re after assuming the length oftr.menu_id_valuewas less than or equal to 10.