Appending trailing zeros to a oracle number in Oracle - oracle

I need to format the NUMBER data type in Oracle as follows:
Problem Statement:
-> Append trailing zeros to the ATM_CARD-NUMBER whose length is 14
My Attempt:
SELECT to_char(atm_card_nbr,'9999999999999900')as new_atm_nbr,atm_card_key from atm_card_dm where LENGTH(TRANSLATE(TO_CHAR(atm_card_nbr),'1234567890.-','1234567890'))=14;
Result:
I've gone through several Oracle related online sites but could not find the correct result. So, how can get the correct result?
Thanks in advance!

SELECT rpad(to_char(atm_card_nbr),16,'0') as new_atm_nbr,
atm_card_key
from atm_card_dm
where LENGTH(TRANSLATE(TO_CHAR(atm_card_nbr),'1234567890.-','1234567890'))=14;

Related

How to limit the amount of characters returned in Oracle query

I have a value in my query pulling too many characters so when i try to put the report into an Excel i am hitting 32767 characters error for excel, i am using SSRS to generate the report and it must be in excel format so that can't change. I need to be able to some how set return 32760 characters only to the select
I tried Trim but that didn't solve my issue.
If I understood what you are saying, SUBSTR returns only a portion of some string, so that would be
select substr(your_string, 1, 32760)
from ...

Oracle APEX - no leading zero

I have an app build in Oracle APEX 18.2. Every number field in app have missing leading zero. For example when the number is 0.5, APEX displays it as .5. The problem occurs also in SQL Workshop. In SQL Developer numbers with leading zeros are formatted well, so I think this is problem with Oracle APEX, not with Oracle DB. Is there any global setting for number formatting in APEX?
As far as I can tell, there's no such a global setting, which means that you'd have to apply some format mask either
directly (in SELECT statement, within the TO_CHAR function call), or
in column's (item's) property
Format mask you might consider is FM999G990D00 as
FM will remove leading spaces and superfluous trailing zeros
instead of using explicit , and . grouping & decimal characters, use G and D instead
I had an issue adding zeros to numbers, but it was fixed using Function with Oracle Developer
select LPAD((max(ID))+1, 6, '0') from Yourtable
and call it as a function.
Probably you could use PL/SQL expressions to fix it
I had the same issue recently. i fixed it using to_char(xxx,'FM999G990D00')
SELECT mont.period_name AS PERIOD
, to_char(ivo.total_overtime,'FM999G990D00')
, to_char(emho.ACTUAL_TRANSFERRED_HOURS,'FM999G990D00')
, to_char(emho.actual_recup_days,'FM999G990D00')
FROM .....
worked like a charm
I'll assume you have a Classic or Interactive Report, in such case:
Go to page designer and select the column
Go to the format mask option
Select the numeric format you wish to have.
You'll probably get something like 999G999G999G999G990D00
if it has a 9D00 at the end, change the 9 to a 0

OBIEE 11g: white space character

The problem: Direct SQL based OBIEE analysis ignores whitespace character.
For example:
Oracle: select chr(9)||'New volume' from dual
Oracle result: " New volume"
OBIEE result: "New volume" (ignores chr(9))
Why OBIEE ignores chr(9) code showing result?
Should I use some specific HTML codes?
Thanks in advance.
i tested your statement in obiee 12c , it also ignores statement with leading whitespaces. but when you execute this. it does include it on the answers and export file ...
select 'test'|| chr(9)||'New volume' as c1 from dual
Do you need to add whitespace to the start always ? Whats the total goal , so maybe we can find alternative workaround for your problem ...
OBI trims leading spaces and trailing spaces from strings. What's the goal of this? If you're using Direct DB requests then that points to a questionable usage of the tool already.

How MAX of a concatenated column in oracle works?

In Oracle, while trying to concatenate two columns of both Number type and then trying to take MAX of it, I am having a question.
i.e column A column B of Number data type,
Select MAX(A||B) from table
Table data
A B
20150501 95906
20150501 161938
when I’m running the query Select MAX(A||B) from table
O/P - 2015050195906
Ideally 20150501161938 should be the output????
I am trying to format column B like TO_CHAR(B,'FM000000') and execute i'm getting the expected output.
Select MAX(A || TO_CHAR(B,'FM000000')) FROM table
O/P - 2015011161938
Why is 2015050195906 is considered as MAX in first case.
Presumably, column A is a date and column B is a time.
If that's true, treat them as such:
select max(to_date(to_char(a)||to_char(b,'FM000000'),'YYYYMMDDHH24MISS')) from your_table;
That will add a leading space for the time component (if necessary) then concatenate the columns into a string, which is then passed to the to_date function, and then the max function will treat as a DATE datatype, which is presumably what you want.
PS: The real solution here, is to fix your data model. Don't store dates and times as numbers. In addition to sorting issues like this, the optimizer can get confused. (If you store a date as a number, how can the optimizer know that '20141231' will immediately be followed by '20150101'?)
You should convert to number;
select MAX(TO_NUMBER(A||B)) from table
Concatenation will result in a character/text output. As such, it sorts alphabetically, so 9 appears after 16.
In the second case, you are specifiying a format to pad the number to six digits. That works well, because 095906 will now appear before 161938.

Hive Length outputs more than seen

I am trying to run a hive query which should join two table with matching records. However, it never matches but i have the record in the other table. When i do length of a given string it outputs 27, but it should be just 12.
When i download the output file from s3 then i see weird row like
U S 3 F F 1 2 1 4 9 3 3
but in hive console it see it as
US3FF1214933
Also i cannot query the row with
select * from table where item like "US3FF1214933";
It is totally a mess right now and trimming also does not work for me.
I am in need of help.
Thanks in advance,
Thanks to legato for giving me an idea to investigate this by doing
od -c and seeing actual characters between the string.
And after in hive query using regexp_replace(ExString,'\0',"") to replace the weird characters with empty string solved my issue.

Resources