Oracle replaces £ with ?? on INSERT - oracle

I have an Oracle 12c database that is replacing £ with ?? on INSERT. The insert is coming from a 11.2 instant client SQL*Plus session. Both boxes are running Linux.
The same also happens from SQL*Plus on the DB host itself.
The DB host has the following settings:
$LANG: en_GB.UTF8
NLS_CHARACTERSET: AL32UTF8
The Client has:
$LANG: en_GB.UTF-8
$NLS_LANG is not set for either DB or Client hosts.
select dump('£', 1017) from dual;
DUMP('??',1017)
-----------------------------------------------------
Typ=96 Len=6 CharacterSet=AL32UTF8: ef,bf,bd,ef,bf,bd
EDIT: Correction. Only £ is being replaced, but is being replaced with ??

You are seeing the Unicode replacement character. It looks like your Linux environment setting for the Oracle NLS_LANG variable is not appropriate:
$ export NLS_LANG="ENGLISH_UNITED KINGDOM.US7ASCII"
$ sqlplus ...
SQL> select dump('£', 1017) from dual;
DUMP('??',1017)
-----------------------------------------------------
Typ=96 Len=6 CharacterSet=AL32UTF8: ef,bf,bd,ef,bf,bd
With a setting that matches your LANG it works as expected:
$ export NLS_LANG="ENGLISH_UNITED KINGDOM.AL32UTF8"
$ sqlplus ...
SQL> select dump('£', 1017) from dual;
DUMP('£',1017)
-----------------------------------------
Typ=96 Len=2 CharacterSet=AL32UTF8: c2,a3
which is the Unicode pound sign.

Related

what is Oracle command 'o;'

I am using the oracle version.
Oracle Database 11g Release 11.2.0.1.0
I accidentally ran the command o; in oracle delveloper.
The result is as below.
The PL/SQL procedure completed successfully.
not spooling currently
The sqlcl_int_runme alias has been removed.
I don't know what I did....
First of all, there seems to be no problem with basic table CRUD.
Has anyone had this experience?
I need an explanation of what happened...
It's an alias.
We copied over some popular commands from postgresql to SQLcl, one of those was 'o'
From the post docs
\o or \out [ filename ] \o or \out [ |command ] Arranges to save
future query results to the file filename or pipe future results to
the shell command command. If no argument is specified, the query
output is reset to the standard output.
If the argument begins with |, then the entire remainder of the line
is taken to be the command to execute, and neither variable
interpolation nor backquote expansion are performed in it. The rest of
the line is simply passed literally to the shell.
“Query results” includes all tables, command responses, and notices
obtained from the database server, as well as output of various
backslash commands that query the database (such as \d); but not error
messages.
SQL> alias
\! \? \c \cd \d \dp \dt \dt+ \e \echo \encoding \i
\o \p \prompt \q \qecho \r \save \timing \w \z clear cls
cpu fuzzy gglag locks sessions tables tables2 topsql
SQL> alias list \o
\o NULLDEFAULTS psql - desc \o [FILE_NAME] - turn spool log file on (or off if no FILE_NAME given)
--------------------------------------------------------------------------------------------------
Declare
maxpos number:=null;
BEGIN
if (:sqlcl_int_first is null) then
:sqlcl_int_runme:='spool off';
else
:sqlcl_int_runme:='spool '||:sqlcl_int_first||' ';
end if;
end;
/
alias NULLDEFAULTS sqlcl_int_runme=:sqlcl_int_runme;
sqlcl_int_runme
alias drop sqlcl_int_runme
To see it in action...
SQL> set sqlformat csv
SQL> o stackoverflow.csv
PL/SQL procedure successfully completed.
Alias sqlcl_int_runme dropped
SQL> select * from regions;
"REGION_ID","REGION_NAME"
1,"Europe"
2,"Americas"
3,"Asia"
4,"Middle East and Africa"
SQL> o
PL/SQL procedure successfully completed.
Alias sqlcl_int_runme dropped
SQL> !dir stackoverflow.csv
Volume in drive C is System
Volume Serial Number is F897-6A6F
Directory of c:\sqlcl\22.2.1\sqlcl\bin
08/30/2022 08:09 AM 170 stackoverflow.csv
1 File(s) 170 bytes
0 Dir(s) 190,156,173,312 bytes free
SQL> !type stackoverflow.csv
Alias sqlcl_int_runme dropped
"REGION_ID","REGION_NAME"
1,"Europe"
2,"Americas"
3,"Asia"
4,"Middle East and Africa"
PL/SQL procedure successfully completed.

How to determine what characters these are being stored in the Oracle Database so I can properly configure my Putty session?

Using Oracle and within SQL*Plus I execute a SQL command using the DUMP function.
SQL> select DUMP(Field1, 16) from MY_TABLE;
It prints out the following :
Typ=1 Len=10 CharacterSet=AL32UTF8: c3,83,e2,82,ac,c3,83,e2,82,ac
The SQL*Plus session is run within my Putty session and when the "Remote character set :" configuration is changed to various settings (UTF-8, ISO-8859-1:1998 (Latin-1, West Europe), ....) , different characters appear.
Using UTF-8 conversion (assuming it is done correctly) with the above info it almost seems like it should be the same 2 characters.
c3 83
11000011 10000011
11000011
C3
e2 82 ac
11100010 10000010 10101100
10000010101100
20AC
How can I tell exactly what characters (whether it is 1,2 or more characters) it should be then I know that my Putty session is configured correctly?

Using dollar sign in sqlplus spool file

How to use file name with dollar sign (ie, '$') in unix like below
SQL> spool DIR$work.sql
SP2-0332: Cannot create spool file.
and i tried like below
SQL> spool DIR\$work.sql
SP2-0332: Cannot create spool file.
SQL> spool 'DIR\$work.sql'
SP2-0332: Cannot create spool file.
SQL> spool 'DIR$work.sql'
SP2-0332: Cannot create spool file.
I couldn't succeed in any way to create such file in oracle.
I have oracle 11g version.
In windows sqlplus it works fine.
You can use the set escchar setting to stop Oracle interpreting the dollar sign:
SQL> show escchar
escchar OFF
SQL> spool /tmp/$work.sql
SP2-0332: Cannot create spool file.
SQL> set escchar $
SQL> spool /tmp/$work.sql
SQL>
You are now spooling to that file name.
SQL> select * from dual;
D
-
X
1 row selected.
SQL> spool off
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
...
$ cat /tmp/\$work.sql
SQL> select * from dual;
D
-
X
1 row selected.
SQL> spool off
Also see My Oracle Support document 761384.1 for more information.

Why isn't hextoraw() functioning, Am I misunderstanding it?

I'm running Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production, and I'm trying to convert a few hex characters to a string:
SQL> select hextoraw('414243') from dual;
HEXTOR
------
414243
But it seems nothing has been done here, am I miss understanding this macro?
Because the tools displays the result as string, so it seems nothing changed. Actually the datatypes are different, please use below SQL to check:
SQL> SELECT DUMP('414243'),DUMP(HEXTORAW('414243')) from dual
A B
-------------------------------- --------------------------------------
Typ=96 Len=6: 52,49,52,50,52,51 Typ=23 Len=3: 65,66,67
I believe SQL*Plus is just formatting the RAW to a format convenient for display.
HEXTORAW('414243') converts your string to the RAW(3) consisting of [0x41 0x42 0x43]. Then, when sqlplus tries to display that value back to the user, it converts it to something it can print to the terminal.
Here is a SQL Fiddle, but it looks like it displays the RAW value in base-10 format rather than hex. I'm not sure if there is a format command for sqlplus to change this behavior.
select hextoraw( '414243' ) as col1,
utl_raw.cast_to_varchar2( hextoraw( '414243' )) as col2
from dual;
| COL1 | COL2 |
|----------|------|
| 65,66,67 | ABC |

gibberish on oracle 12.1 db sqlplus errors

I am getting gebbrish on my sqlplus ORA errors. Example:
SQL> conn ur#mydb
Enter password:
ERROR:
ORA-01017: ┐┐┐┐┐ ┐┐┐┐┐/┐┐┐┐┐ ┐┐ ┐┐┐┐┐; ┐┐┐┐┐┐┐┐ ┐┐┐┐┐
this is my nls_lang on the registry:
AMERICAN_AMERICA.WE8MSWIN1252
I have windows 8 64 bit. Oracle db 12.1.0.1.
Tried everything.
Thank you for the help.
Try: I had the same problem, solved when I changed the NLS_VALUE to AMERICAN_AMERICA.WE8MSWIN1252
Procedure
Run the following queries to get the corresponding values:
SELECT VALUE as Language FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER='NLS_LANGUAGE';
SELECT VALUE as Territory FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER='NLS_TERRITORY';
SELECT VALUE as Characterset FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER='NLS_CHARACTERSET';
The NLS_LANG parameter is set as: <Language>_<Territory>.<Characterset> (for example, set NLS_LANG = AMERICAN_AMERICA.UTF8)
To set the value of the NLS_LANG parameter in Windows, verify the HKEY_LOCAL_MACHINE/SOFTWARE/ORACLE/NLS_LANG entry in the registry.
To set the value of the NLS_LANG parameter in UNIX, NLS_LANG is set as a local environment variable
source: http://pic.dhe.ibm.com/infocenter/ssfs/v9r2/index.jsp?topic=%2Fcom.ibm.help.install.doc%2Ft_ConfiguringTheNLS_LANGParameterForAnOracleClient.html

Resources