The ROWIDTONCHAR function in Oracle SQL / PLSQL is used to cionvert the ROWID to NVARCHAR2 data type, the result is always in National Character Set and 18 characters long.
Syntax for using the ROWIDTONCHAR function Oracle SQL / PLSQL is;
SELECT ROWIDTONCHAR (ROWID)
FROM table_name;
Example:
Using ROWIDTONCHAR 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 ROWIDTONCHAR(ROWID) FROM employee;
We may get the following result:
ROWIDTONCHAR(ROWID) |
AAAPD2AABAAAS2aAAA |
AAAPD2AABAAAS2aAAB |
AAAPD2AABAAAS2aAAC |
AAAPD2AABAAAS2aAAD |
AAAPD2AABAAAS2aAAE |
AAAPD2AABAAAS2aAAF |
AAAPD2AABAAAS2aAAG |
AAAPD2AABAAAS2aAAH |
Here we can see that we have converted all the “rowids” into NVARCHAR2 data type and all the records are 18 characters long.