Difference between N'String' vs U'String' literals in Oracle

前端 未结 3 1859
傲寒
傲寒 2020-12-09 16:35

What is the meaning and difference between these queries?

SELECT U\'String\' FROM dual;

and

SELECT N\'String\' FROM dual;
<         


        
3条回答
  •  旧巷少年郎
    2020-12-09 16:58

    • N'string' just returns the string as NCHAR type.

    • U'string' returns also NCHAR type, however it does additional processing to the string: it replaces \\ with \ and \xxxx with Unicode code point U+xxxx, where xxxx are 4 hexadecimal digits. This is similar to UNISTR('string'), the difference is that the latter returns NVARCHAR2.

    U' literals are useful when you want to have a Unicode string independent from encoding and NLS settings.

    Example:

    select n'\€', u'\\\20ac', n'\\\20ac' from dual;
    
    N'\€' U'\\\20AC' N'\\\20AC'
    ----- ---------- ----------
    \€    \€         \\\20ac
    

提交回复
热议问题