For column-level encryption using the ENCRYPT_TDES built-in function, all encrypted
values in a column are encrypted with the same password.
Procedure
To define column-level encryption:
- Create the EMP table with the EMPNO column. The EMPNO column must be defined with the
VARCHAR data type, must be defined FOR BIT DATA, and must be long enough to hold the encrypted data.
The following statement creates the EMP table:

CREATE TABLE EMP (EMPNO VARCHAR(32) FOR BIT DATA);

- Set the encryption password. The following statement sets the encryption password to the
host variable :hv_pass:

SET ENCRYPTION PASSWORD = :hv_pass;

-
Use the ENCRYPT_TDES built-in function to insert encrypted data into the EMP table by issuing
the following statements:

INSERT INTO EMP (EMPNO) VALUES(ENCRYPT_TDES('47138'));
INSERT INTO EMP (EMPNO) VALUES(ENCRYPT_TDES('99514'));
INSERT INTO EMP (EMPNO) VALUES(ENCRYPT_TDES('67391'));

- Select the employee ID numbers in decrypted format:

SELECT DECRYPT_CHAR(EMPNO) FROM EMP;
If you provide the correct password, Db2
returns the employee ID numbers in decrypted format.