Monday, May 31, 2010

Change Negative (-) Value to Positive (+) Value in Oracle

Description:
We can use the below method to change the records into Negative to Positive.
Solution:
SQL>create table tmp (col1 number)
SQL>SET DEFINE OFF;
SQL>Insert into TMP(COL1) Values(-1);
SQL>Insert into TMP(COL1)Values(-2);
SQL>Insert into TMP(COL1) Values(-20);
SQL>Insert into TMP(COL1)Values(300);
SQL>COMMIT;
SQL>select col1,case when sign(col1)=-1 then '('||(col1)*(-1)||')' else to_char(col1) end col1 from tmp;

No comments: