The ROWIDTOCHAR function in Oracle SQL / PLSQL is used to cionvert the ROWID to VARCHAR2 datatype, the result is always 18 characters long.
Syntax for using the ROWIDTOCHAR function Oracle SQL / PLSQL is;
SELECT ROWIDTOCHAR (ROWID)
FROM table_name;
Example:
Using ROWIDTOCHAR function
Suppose we have a table named ‘employee’ as shown below:
Employee_ID | Employee_Name | Salary | Department | Commission |
101 | Emp A | 10000 | Sales | 10 |
102 | Emp B | 20000 | IT | 20 |
103 | Emp C | 28000 | IT | 20 |
104 | Emp D | 30000 | Support | 5 |
105 | Emp E | 32000 | Sales | 10 |
106 | Emp F | 40000 | Sales | 10 |
107 | Emp G | 12000 | Sales | 10 |
108 | Emp H | 12000 | Sales | 10 |
If we write our query as:
SELECT ROWIDTOCHAR(ROWID) FROM employee;
We may get the following result:
ROWIDTOCHAR(ROWID) |
AAAPD2AABAAAS2aAAA |
AAAPD2AABAAAS2aAAB |
AAAPD2AABAAAS2aAAC |
AAAPD2AABAAAS2aAAD |
AAAPD2AABAAAS2aAAE |
AAAPD2AABAAAS2aAAF |
AAAPD2AABAAAS2aAAG |
AAAPD2AABAAAS2aAAH |
Here we can see that we have converted all the “rowids” into varchar2 data type and all the records are 18 characters long.