Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim
When a string goes into a RAW column or through HEXTORAW, Oracle reads it as hexadecimal: two characters per byte, only 0-9 and A-F. Any other character, including a dash, stops the statement with ORA-01465.
The usual cases are plain text written into a RAW column, a GUID pasted with its dashes, and a VARCHAR2 column that holds some non-hex values. All three were run on Oracle 26ai Free.
01Inserting plain text into a RAW column
key_raw is RAW(16). INSERT INTO api_keys VALUES (1, 'secret-key') fails because Oracle tries to read 'secret-key' as hex, and s is not a hex digit.
To store the bytes of the text, convert it with UTL_RAW.CAST_TO_RAW('secret-key'). The row went in as 7365637265742D6B6579, and UTL_RAW.CAST_TO_VARCHAR2(key_raw) read it back as secret-key.
Setup
CREATE TABLE api_keys (id NUMBER PRIMARY KEY, key_raw RAW(16));Table created.INSERT INTO api_keys VALUES (1, 'secret-key');INSERT INTO api_keys VALUES (1, 'secret-key')
*
ERROR at line 1:
ORA-01465: invalid hex number
Help: https://docs.oracle.com/error-help/db/ora-01465/COLUMN column_name FORMAT A10
COLUMN data_type FORMAT A10
SELECT column_name, data_type, data_length FROM user_tab_columns WHERE table_name = 'API_KEYS';COLUMN_NAM DATA_TYPE DATA_LENGTH
---------- ---------- -----------
ID NUMBER 22
KEY_RAW RAW 16
2 rows selected.If the column should hold readable text, a VARCHAR2 column is the better choice than RAW.
INSERT INTO api_keys VALUES (1, UTL_RAW.CAST_TO_RAW('secret-key'));
COLUMN key_raw FORMAT A24
COLUMN key_text FORMAT A12
SELECT id, key_raw, UTL_RAW.CAST_TO_VARCHAR2(key_raw) AS key_text FROM api_keys;
ROLLBACK;1 row created.
ID KEY_RAW KEY_TEXT
---------- ------------------------ ------------
1 7365637265742D6B6579 secret-key
1 row selected.
Rollback complete.02Inserting a GUID with dashes into a RAW(16) column
A GUID like 6F9619FF-8B86-D011-B42D-00C04FC964FF is hex, but the dashes are not. Inserting it as is into RAW(16) fails with ORA-01465.
The string is 36 characters with dashes and 32 without, which is exactly 16 bytes. HEXTORAW(REPLACE(guid, '-', '')) inserted the row, stored as 6F9619FF8B86D011B42D00C04FC964FF.
Setup
CREATE TABLE orders (order_id RAW(16) PRIMARY KEY, amount NUMBER);Table created.INSERT INTO orders VALUES ('6F9619FF-8B86-D011-B42D-00C04FC964FF', 1000);INSERT INTO orders VALUES ('6F9619FF-8B86-D011-B42D-00C04FC964FF', 1000)
*
ERROR at line 1:
ORA-01465: invalid hex number
Help: https://docs.oracle.com/error-help/db/ora-01465/SELECT LENGTH('6F9619FF-8B86-D011-B42D-00C04FC964FF') AS with_dash, LENGTH(REPLACE('6F9619FF-8B86-D011-B42D-00C04FC964FF', '-', '')) AS no_dash FROM dual; WITH_DASH NO_DASH
---------- ----------
36 32
1 row selected.INSERT INTO orders VALUES (HEXTORAW(REPLACE('6F9619FF-8B86-D011-B42D-00C04FC964FF', '-', '')), 1000);
COLUMN order_id FORMAT A34
SELECT order_id, amount FROM orders;
ROLLBACK;1 row created.
ORDER_ID AMOUNT
---------------------------------- ----------
6F9619FF8B86D011B42D00C04FC964FF 1000
1 row selected.
Rollback complete.03HEXTORAW on a column that contains non-hex values
The token_hex column has A1B2C3D4 and TOKEN-XYZ. SELECT HEXTORAW(token_hex) FROM tokens fails with ORA-01465 because of the second row, and no rows were returned.
Find the bad rows with NOT REGEXP_LIKE(token_hex, '^[0-9A-Fa-f]+$'); here that returned id 2. Filtering with the same pattern let the query return A1B2C3D4 for id 1. Fix or remove the bad data if it should be hex.
Setup
CREATE TABLE tokens (id NUMBER PRIMARY KEY, token_hex VARCHAR2(40));
INSERT INTO tokens VALUES (1, 'A1B2C3D4');
INSERT INTO tokens VALUES (2, 'TOKEN-XYZ');
COMMIT;Table created.
1 row created.
1 row created.
Commit complete.SELECT id, HEXTORAW(token_hex) AS token_raw FROM tokens;ERROR:
ORA-01465: invalid hex number
Help: https://docs.oracle.com/error-help/db/ora-01465/
no rows selectedCOLUMN token_hex FORMAT A12
SELECT id, token_hex FROM tokens WHERE NOT REGEXP_LIKE(token_hex, '^[0-9A-Fa-f]+$'); ID TOKEN_HEX
---------- ------------
2 TOKEN-XYZ
1 row selected.COLUMN token_raw FORMAT A20
SELECT id, HEXTORAW(token_hex) AS token_raw FROM tokens WHERE REGEXP_LIKE(token_hex, '^[0-9A-Fa-f]+$'); ID TOKEN_RAW
---------- --------------------
1 A1B2C3D4
1 row selected.FAQ
Why does inserting a string into a RAW column give ORA-01465?
Oracle converts the string with hex rules. Plain text like 'secret-key' is not hex, so it fails. Use UTL_RAW.CAST_TO_RAW to store the text as bytes.
How do I store a GUID in a RAW(16) column?
Remove the dashes and convert: HEXTORAW(REPLACE(guid, '-', '')). The 32 hex characters become 16 bytes.
How do I find rows that are not valid hex?
WHERE NOT REGEXP_LIKE(col, '^[0-9A-Fa-f]+$') lists values with characters other than 0-9 and A-F.
How do I convert RAW back to readable text?
UTL_RAW.CAST_TO_VARCHAR2(col). On this page it turned 7365637265742D6B6579 back into secret-key.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0