Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Function

Status
Not open for further replies.

kwil38

Programmer
Jan 20, 2005
49
US
I have a field in a view called 'cr_dr' which contains 'CR' (for credit) and 'DR' (for debit).

I'm attempting to create another view that references the first view and would like it to contain '+' instead of 'CR' and '-' instead of 'DR'. I've tried to do this via the Replace and Translate functions.

The problem is that I have only been able to change one or the other, not both. I this possible to do with Replace or Translate, or is there another function that would be more appropriate?
 
How about DECODE?
Code:
CREATE VIEW whatever AS
SELECT acct_number, transaction_date, 
       DECODE(the_column,'CR','+','DR','-') my_col, 
       amount
FROM cr_dr;
 
Here are some test data:
Code:
SQL> select cr_dr from kwil38;

CR
--
DR
CR
DR
CR
Here is code to do what you want:
Code:
select translate(cr_dr,'DCR','-+') from kwil38;

TR
--
-
+
-
+
The logic behind the code is, "Scan the 'cr_dr' column. If you encounter a 'D', translate it to '-'; if you encounter 'C', translate it to '+', if you encounter 'R' translate it to NULL."

Let us know if this satisfies your need.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)

Do you use Oracle and live or work in Utah, USA?
Then click here to join Utah Oracle Users Group on Tek-Tips.
 
Perfect - That's exactly what I need! Thanks Carp!
 
Nice to have a reprieve! This conversion is killing me, and I needed the break!
 
Kwil38 said:
That's exactly what I need! Thanks Carp!
...as such, don't you think Carp deserves a Purple Star ("Thank carp for this valuable post")?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)

Do you use Oracle and live or work in Utah, USA?
Then click here to join Utah Oracle Users Group on Tek-Tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top