In Oracle Database, the ROWIDTOCHAR()
function converts a ROWID
value to VARCHAR2
data type.
Syntax
The syntax goes like this:
ROWIDTOCHAR(rowid)
Example
Here’s an example:
SELECT ROWIDTOCHAR('AAATiBAAMAAAAIDAAE')
FROM DUAL;
Result:
AAATiBAAMAAAAIDAAE
The result of the conversion is always 18 characters long.
And here’s a dump of the result when compared to the CHARTOROWID()
function (which returns a ROWID
value from character data):
SELECT
DUMP(CHARTOROWID('AAATiBAAMAAAAIDAAE'), 17, 1, 4) AS "CHARTOROWID",
DUMP(ROWIDTOCHAR('AAATiBAAMAAAAIDAAE'), 17, 1, 4) AS "ROWIDTOCHAR"
FROM DUAL;
Result:
CHARTOROWID ROWIDTOCHAR ____________________________ ________________________ Typ=69 Len=10: ^@,^A,8,81 Typ=1 Len=18: A,A,A,T
A type ID of 69
means that it’s of ROWID
data type, and a type ID of 1
means that it’s either VARCHAR2
or NVARCHARCHAR2
.
A Database Example
Here’s an example that returns a row in a database table, based on a given ROWID
:
SELECT
ROWID,
FIRST_NAME,
LAST_NAME
FROM EMPLOYEES
WHERE ROWIDTOCHAR(ROWID) LIKE '%KzABa';
Result:
ROWID FIRST_NAME LAST_NAME _____________________ _____________ ____________ AAATiDAAMAAALKzABa Timothy Gates
Null Argument
If the argument is null
, the result is null
:
SET NULL 'null';
SELECT ROWIDTOCHAR(null)
FROM DUAL;
Result:
null
By default, SQLcl and SQL*Plus return a blank space whenever a null value occurs as a result of a SQL SELECT
statement.
However, you can use SET NULL
to specify a different string to be returned. Here I specified that the string null
should be returned.
Invalid Argument Count
Calling ROWIDTOCHAR()
without any arguments results in an error:
SELECT ROWIDTOCHAR()
FROM DUAL;
Result:
SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments"
And passing too many arguments also results in an error:
SELECT ROWIDTOCHAR('a', 'b')
FROM DUAL;
Result:
SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments"