Reputation: 3
What is the syntax for decode() function of oracle to encrypt string in Example :- if i want to encrypt 'suvendu' with'***' and 'mohan' with '$$$' for column fname of samples table
desc samples
Name Null Type
------ -------- ------------
EMP_ID VARCHAR2(20)
LNAME CHAR(10)
FNAME CHAR(20)
DEPT CHAR(20)
SAL NOT NULL NUMBER(12,2)
H_DATE DATE
EMAIL VARCHAR2(20)
DESG VARCHAR2(25)
Upvotes: 0
Views: 1498
Reputation: 984
Updated(try this):
SELECT
DECODE(fname,'suvendu', '***', 'mohan", '$$$') AS F_NAME
--add other columns/column-list here if needed
FROM
samples
The line starting with -- is a commented line
Upvotes: 0
Reputation: 50017
While you can use DECODE
to handle this, as in:
SELECT DECODE(FNAME,
'suvendu', '***',
'mohan', '$$$',
FNAME) AS DERIVED_COL
FROM SAMPLES
IMO using a CASE expression is a better choice
SELECT CASE FNAME
WHEN 'suvendu' THEN '***'
WHEN 'mohan' THEN '$$$'
ELSE FNAME
END AS DERIVED_COL
FROM SAMPLES
as it makes it clearer what's going on and is easier to read.
Best of luck.
Upvotes: 1