PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 13, 2022

[FIXED] How to preserve leading zeros when converting to a decimal in oracle

 August 13, 2022     decimal, oracle, sql     No comments   

Issue

I am running the below query in oracle.

WITH
ta AS (
     SELECT account_coid
        ,txn_id
        ,cbdev.cbzdt(effective_date) AS effective_date
        ,cbdev.cbchr(utl_raw.substr(txn_data, 113, 20)) AS CESG_amt
     FROM bs_transaction
     WHERE sub_type = 127469880)
SELECT
cast(ta.CESG_amt as DECIMAL (20,2)) AS cesg_amt
from ta 
inner join ....

Here, i m getting the result (cesg_amt) as -156.57. But i need the result as -0000000000156.57.
I need the leading zeros with - retained (leading 0's and also the two digits after the decimal).

I have tried as to_char(ta.CESG_amt, '0000000000000.00') AS cesg_amt in the query but of no use.

Can you please help me what needs to be done in the DECIMAL field to get the result as below.


Solution

You may use such a formatting :

select to_char(-156.57,'fm0000000000000D00','NLS_NUMERIC_CHARACTERS = ''.,''')
       as Result
  from dual;

RESULT
-----------------
-0000000000156.57


Answered By - Barbaros Özhan
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing