Single quotes in strings – oracle SQL query
Apostrophe/single quote in a concatenated string
If you were to concatenate an apostrophe/single quote in a string, you need to enter 4 single quotes for Oracle to display a quote symbol. For example:
SELECT 'Today' || '''' || 's Date: ' || sysdate FROM dual;
Today’s Date: 09-DEC-20
select 'PDB Name is : ' || name || ':' from v$pdbs;
PDB Name is : ABC:
SELECT 'Hello' || '''' || 's World' FROM dual;
Hello’s World
Apostrophe/single quote at start of string
When the apostrophe/single quote is at the start of the string, you need to enter 3 single quotes for Oracle to display a quote symbol. For example:
SELECT '''Hello World' FROM dual;
would return
'Hello World
Apostrophe/single quote in the middle of a string
When the apostrophe/single quote is in the middle of the string, you need to enter 2 single quotes for Oracle to display a quote symbol. For example:
SELECT 'She''s Here' FROM dual;
would return
She's Here
Apostrophe/single quote at the end of a string
When the apostrophe/single quote is at the end of a string, you need to enter 3 single quotes for Oracle to display a quote symbol. For example:
SELECT 'Worlds''' FROM dual;
would return
Worlds'
No comments yet