Oracle数据库数据恢复、性能优化

找回密码
注册
搜索
热搜: 活动 交友 discuz
发新帖

16

积分

0

好友

0

主题
1#
发表于 2012-3-12 10:24:59 | 查看: 14543| 回复: 15
应用连接oracle时中文出现问号,但是在oracle直接查询时中文显示正常!

问题.png (7.62 KB, 下载次数: 389)

问题.png

oracle字符集.png (15.43 KB, 下载次数: 412)

oracle字符集.png

2#
发表于 2012-3-12 10:45:37
"应用连接oracle时中文出现问号"

你的应用 未必和你的SQLPLUS 使用了一样的NLS参数。

本机的NLS参数优先级比 instance parameter 高 , 在Windows 上NLS参数被写入到注册表的键值中
  1. SQLPLUS :

  2. SQL> col parameter for a35
  3. SQL> col value for a40
  4. SQL> SELECT Parameter, Value FROM NLS_SESSION_PARAMETERS  ORDER BY 1
  5.   2  /

  6. PARAMETER                           VALUE
  7. ----------------------------------- ----------------------------------------
  8. NLS_CALENDAR                        GREGORIAN
  9. NLS_COMP                            BINARY
  10. NLS_CURRENCY                        $
  11. NLS_DATE_FORMAT                     DD-MON-RR
  12. NLS_DATE_LANGUAGE                   AMERICAN
  13. NLS_DUAL_CURRENCY                   $
  14. NLS_ISO_CURRENCY                    AMERICA
  15. NLS_LANGUAGE                        AMERICAN
  16. NLS_LENGTH_SEMANTICS                BYTE
  17. NLS_NCHAR_CONV_EXCP                 FALSE
  18. NLS_NUMERIC_CHARACTERS              .,
  19. NLS_SORT                            BINARY
  20. NLS_TERRITORY                       AMERICA
  21. NLS_TIMESTAMP_FORMAT                DD-MON-RR HH.MI.SSXFF AM
  22. NLS_TIMESTAMP_TZ_FORMAT             DD-MON-RR HH.MI.SSXFF AM TZR
  23. NLS_TIME_FORMAT                     HH.MI.SSXFF AM
  24. NLS_TIME_TZ_FORMAT                  HH.MI.SSXFF AM TZR

  25. 17 rows selected.


  26. PLSQL DEVELOPER:

  27. SQL>  SELECT Parameter, Value FROM NLS_SESSION_PARAMETERS  ORDER BY 1
  28.   2  /

  29. PARAMETER                           VALUE
  30. ----------------------------------- ----------------------------------------
  31. NLS_CALENDAR                        GREGORIAN
  32. NLS_COMP                            BINARY
  33. NLS_CURRENCY                        ¥
  34. NLS_DATE_FORMAT                     DD-MON-RR
  35. NLS_DATE_LANGUAGE                   SIMPLIFIED CHINESE
  36. NLS_DUAL_CURRENCY                   ¥
  37. NLS_ISO_CURRENCY                    CHINA
  38. NLS_LANGUAGE                        SIMPLIFIED CHINESE
  39. NLS_LENGTH_SEMANTICS                BYTE
  40. NLS_NCHAR_CONV_EXCP                 FALSE
  41. NLS_NUMERIC_CHARACTERS              .,
  42. NLS_SORT                            BINARY
  43. NLS_TERRITORY                       CHINA
  44. NLS_TIMESTAMP_FORMAT                DD-MON-RR HH.MI.SSXFF AM
  45. NLS_TIMESTAMP_TZ_FORMAT             DD-MON-RR HH.MI.SSXFF AM TZR
  46. NLS_TIME_FORMAT                     HH.MI.SSXFF AM
  47. NLS_TIME_TZ_FORMAT                  HH.MI.SSXFF AM TZR

  48. 17 rows selected
复制代码

回复 只看该作者 道具 举报

3#
发表于 2012-3-12 10:52:47

应用连接oracle时中文出现问号

应用时php写的代码在A服务器,oracle数据库在B服务器,两台服务器的NLS_LANG都是american_america.AL32UTF8
两台linux服务器语言环境都是
[root@oracle /]# local
local      locale     localedef  
[root@oracle /]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_M
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

回复 只看该作者 道具 举报

4#
发表于 2012-3-12 11:01:34
用你的PHP 查一下 这个语句

:SELECT Parameter, Value FROM NLS_SESSION_PARAMETERS  ORDER BY 1


直接贴结果就可以, 不要截图

回复 只看该作者 道具 举报

5#
发表于 2012-3-12 11:09:02
NLS_LANG and webservers explained.
  1. NLS_LANG and web servers explained.
  2. ----------------------------------

  3. When using a web based infrastructure there is (compared to a "normal"
  4. Windows or UNIX application) one layer more that can provoke problems
  5. when dealing with character sets. And that's the browser...

  6. This guide will try to give a generic overview of how this works but is not
  7. intended to replace web server or application manuals.
  8. If any doubt please consult the vendor of the application language / web server.

  9. What happens when you type data in a field in a web environment?

  10. I'm assuming here that you are using Firefox on a Unix X-windows system
  11. or IE / Firefox on a windows client.

  12. a) The Client operating system character set.

  13.    The text you type is in the native character set of the operating system
  14.    and passed to the browser who "knows" what character set the GUI is running in.
  15.    Most X-windows environments are Unicode (UTF-8).
  16.    Input in windows from a keyboard is typically the ANSI (ACP) character set
  17.    like 1252 for a west european windows installation.
  18.    Copy paste from MS Word or a other Unicode source will place data in
  19.    UCS2 (= the Unicode encoding used by Windows)on the clipboard
  20.   
  21. b) The browser tries to find out the character set of the website.

  22.    Then the browser checks what character set encoding the website uses.

  23.    This can be:
  24.   
  25.    b1) defined by the HTTP header returned by the web server.

  26.        like: Content-Type: text/html; charset=UTF-8

  27.        If the web server returns no charset definition in the HTTP header
  28.        then the character set is assumed to be in ISO-8859-1 or (!) the
  29.        "default character set" which can be set by the user in the browser.
  30.        Which basically means when you don't specify the HTTP header you
  31.        never know what the client (=browser) will take.
  32.        So this is a very good thing to define.

  33.        How to make a server send this header depends on the particular server,
  34.        check your server documentation if necessary.
  35.        Info for the most popular HTTP servers like Apache and IIS is found on
  36.      
  37.        http://www.w3.org/International/O-HTTP-charset


  38.     b2) defined in the html itself by the charset meta tag in the head of the html document.

  39.         like: <META http-equiv="Content-Type" content="text/html; charset=UTF-8">

  40.         see the http://www.w3.org/International/O-charset.html website

  41.         Please do NOT rely only on the HTML Meta Tag to define a character set.
  42.         Depending on the used programming language or html/xml parser you might
  43.         get unexpected results when mixing or not including charset declaration.
  44.         To avoid problems we recommend to:
  45.       
  46.         * use Unicode (UTF-8) where possible as this is the best option.
  47.         * declare always the HTTP header.
  48.         * do not declare a Meta tag different from the HTTP header.
  49.         * certainly do NOT mix html documents with different or
  50.           missing encoding definitions in one page using applets,
  51.           frames or iframes.
  52.         * if html pages are cachable then it's a good idea to include the meta tag
  53.           seen the http header is not there when fetched from the cache

  54. c) The Browser knows now enough to do the conversion.

  55.    Once the browser knows the native character set of the operating system
  56.    and the character set defined by the web environment, the browser  will do
  57.    the translation from the OS character set to the character set used by the
  58.     web pages.
  59.    As you might have noticed, up to this point the data is even not yet
  60.    at the web server.
  61.   
  62.    We cannot stress enough the importance of this first conversion step.
  63.   
  64.    Assume you have a windows client who passes the euro symbol to the browser
  65.    (= 1252 character set). If the browser gets a webpage without declared character set
  66.    then it will use "charset=ISO-8859-1".
  67.    "charset=ISO-8859-1" does not know the euro symbol and the euro is already lost
  68.    at this stage. The character set of the Oracle database later on is irrelevant
  69.    seen we already lost the character before it even left the client (=browser).

  70.    This first step need to be right or you run into troubles.
  71.    If this is not correct then it's useless to go further.

  72.    So what can you do?
  73.   
  74.    * When deploying a web application we strongly recommend using Unicode (UTF-8)
  75.      as character set for the Web server and Application side.
  76.      With a Unicode web environment you can process any language you want and
  77.      you never need to worry about the client side conversion(=browser)
  78.      any more.
  79.      The browser will always be able to convert the Operating system
  80.      character set to Unicode (UTF-8) and back.
  81.   
  82.   How to check that you http header is correctly picked up by the browser:
  83.   
  84.   * for IE 5 or 6: in view-encoding menu the "autoselect" flagged and that
  85.     IE then chooses the character set you have defined in your http server
  86.     (utf8 normally)

  87.   * for Firefox: in view-character coding that it's the character set you
  88.     have defined in your http server (utf8 normally).

  89.     Please do NOT change this manually to "see things correctly".
  90.     If you browser is not choosing automatically the correct characterset
  91.     then your application / web server setup has a problem and you
  92.     need to correct this first.

  93.   Where to define the character set of the http header?
  94.    
  95.     http://www.w3.org/International/O-HTTP-charset or contact your
  96.    (application) vendor.

  97.   Where to define the character set of the html (Meta tag) ?

  98.   * For the popular PHP language you can set the character set declaration globally
  99.     in the php.ini by defining a "default_charset". See your PHP manual for more info.

  100.     A guide to Globalize PHP applications:
  101.     http://www.oracle.com/technology/tech/php/pdf/globalizing_oracle_php_applications.pdf

  102.     (note that we do not provide direct support for PHP development)

  103.   * When using mod_plsql more information can be found in:

  104.     Note 244544.1 An NLS Character Set Primer for mod_plsql

  105.   * When using ASP you might want to have a look at
  106.     http://support.microsoft.com/?id=893663
  107.     (Globalization issues in ASP and ASP.NET)
  108.     Please contact Microsoft if you have questions about ASP.

  109.   * For other programming environments please consult the manual or the vendor.


  110. d) The web server has the data and connects to the database.

  111.    Then the web server connects to oracle, here you can consider the web server
  112.    as a normal Oracle (!) client, and you know what kind of character set you
  113.    are using from the previous points (the "web server character set").

  114.    You need to set the NLS_LANG to that character set used in the html/http
  115.    header in the environment of the operating user that runs the process
  116.    that connects to oracle.

  117.    On UNIX this is normally the user environment that starts the web server,
  118.    On windows you need to put it in the registry of the oracle home of the used
  119.    oracle client libraries (!).

  120.    Note that on windows the Apache is NOT picking up a NLS_LANG if defined as an environment
  121.    variable, so you NEED to set it in the registry.

  122.    The only exception is a "Thin Jdbc" connection, this is a direct TCP/IP
  123.    connection from the java environment (which is Unicode based) on the client
  124.    running the java program and you cannot set any NLS_LANG (or need to).
  125.   
  126.    If the conversion in the browser is correct, you won't get any troubles from
  127.    that.

  128.    see Note 115001.1 NLS_LANG Client Settings and JDBC Drivers
  129.    for more info on jdbc and NLS.

  130.    Common IANA character set Name      vs.     Oracle character set name
  131.    (Http header & html meta tag)               (NLS_LANG character set part)

  132.     UTF-8                                       UTF8
  133.     windows-1250                                EE8MSWIN1250
  134.     windows-1251                                CL8MSWIN1251
  135.     windows-1252                                WE8MSWIN1252
  136.     windows-1253                                EL8MSWIN1253
  137.     windows-1254                                TR8MSWIN1254
  138.     windows-1255                                IW8MSWIN1255
  139.     windows-1256                                AR8MSWIN1256
  140.     windows-1257                                BLT8MSWIN1257
  141.     windows-1258                                VN8MSWIN1258
  142.     windows-936 or GBK                          ZHS16GBK
  143.     Big5                                        ZHT16MSWIN950
  144.     Big5-HKSCS                                  ZHT16HKSCS - Hong Kong extension of big5
  145.     TIS-620                                     TH8TISASCII
  146.     Shift_JIS                                   JA16SJIS
  147.     korean or KS_C_5601-1989                    KO16MSWIN949
  148.    
  149.     To know what language each character set supports have a look at
  150.     Note:179133.1 The correct NLS_LANG in a Windows Environment
  151.     UTF8 is a Unicode character set and supports (almost)
  152.     any spoken language in the world.

  153. e) The data arrives at the database.

  154.    The final thing to check is that your Oracle database can store the data
  155.    coming from the web server.
  156.    Again, the best solution is to use (AL32)UTF8 as NLS_CHARACTERSET otherwise
  157.    if you have for example 2 web servers , one configured to handle Arabic and
  158.    one for Russian then you would need 2 databases seen, besides UTF8,
  159.    there is no character set that supports both Arabic and Russian languages.
  160.   
  161.    More information about using a AL32UTF8 database is found here
  162.    Note:788156.1 AL32UTF8 / UTF8 (Unicode) Database Character Set Implications
  163.    Note:144808.1 Examples and limits of BYTE and CHAR semantics usage
  164.    Note:260893.1 Unicode character sets in the Oracle database

  165.    your current NLS_CHARACTERSET can be found using this select:
  166.   
  167.    select value from NLS_DATABASE_PARAMETERS where parameter='NLS_CHARACTERSET';

  168.    This should be the same as the one used in your website or a superset like (AL32)UTF8.

  169. some additional information:
  170. ----------------------------

  171. * When using webforms please see
  172.   Note 314074.1Understanding and Troubleshooting NLS Issues in Web Deployed Oracle Forms
  173.   Webforms is a Java/OC4J environment, not a html environment and does not use
  174.   the webserver HTTP encoding for transporting data.
  175.   The actual connection to the database is made by a C runtime process on
  176.   the forms server.

  177. * When dealing with UTF8 it's a good idea to set up iSqlPlus
  178.   (that's the web-based Unicode version of sqlplus) please see:

  179.   Note 231231.1 Quick setup of iSQL*Plus 9.2 as Unicode client on windows.

  180.   iSQLplus is in 10g and up by default a UTF8 client, no need to configure anything.
  181.   Note 281847.1 How do I configure or test iSQL*Plus 10i?

  182.   If you have troubles inserting / fetching data correctly trough your
  183.   web application then simply update a few rows trough iSqlplus.
  184.   That way you know the data is good in the database and you can "work back"
  185.   from there until you see the data correct in your application.

  186. * If you notice that "extended" / non US7ASCII characters are store like
  187.   " & # 1 6 3 ; " (-> here are spaces added to avoid your browser to display a £ sign)
  188.   then have a look at Note 296376.1 Data in database is stored with & and # symbols


  189. RELATED DOCUMENTS
  190. -----------------
  191. Note 115001.1 NLS_LANG Client Settings and JDBC Drivers
  192. Note 179133.1 The correct NLS_LANG in a Windows Environment
  193. Note 158577.1 NLS_LANG Explained (How does Client-Server Character Conversion Work?)
  194. Note 231231.1 Quick setup of iSQL*Plus 9.2 as Unicode client on windows.
  195. Note 281847.1 How do I configure or test iSQL*Plus 10i?
  196. Note 244544.1 An NLS Character Set Primer for mod_plsql
  197. Note 296376.1 Data in database is stored with & and # symbols


  198. More info about the standards using in a web based environment:

  199.      Hypertext Transfer Protocol -- HTTP/1.1
  200.      http://www.w3.org/Protocols/rfc2068/rfc2068.txt

  201.      The HTML 3.2 (Wilbur) recommendation
  202.      [This includes all character entities listed in HTML 2.0 plus new named entities covering the ISO 8859-1 120-191 range.]
  203.      http://www.w3.org/MarkUp/Wilbur/

  204.      The HTML 4.0 Recommendation
  205.      [Includes new Unicode character entities]
  206.      http://www.w3.org/TR/REC-html40/
  207.    
  208.      The W3C HTML Internationalization area
  209.      http://www.w3.org/International/O-HTML.html
  210.    
  211.      RFC 1866: The HTML 2.0 specification (plain text.) Appendix contains Character Entity table.   
  212.      http://www.rfc-editor.org/rfc/rfc1866.txt

  213.      The web version of the HTML 2.0 (RFC 1866) Character Entity table
  214.      http://www.w3.org/MarkUp/html-spec/html-spec_13.html

  215. For further NLS / Globalization information you may start here:
  216. Note 267942.1 Globalization Technology (NLS) Knowledge Browser
复制代码

回复 只看该作者 道具 举报

6#
发表于 2012-3-12 11:09:20
Where to define the character set of the html (Meta tag) ?

  * For the popular PHP language you can set the character set declaration globally
    in the php.ini by defining a "default_charset". See your PHP manual for more info.

    A guide to Globalize PHP applications:
    http://www.oracle.com/technology ... hp_applications.pdf

    (note that we do not provide direct support for PHP development)

回复 只看该作者 道具 举报

7#
发表于 2012-3-12 11:10:41
NLS_CALENDAR---GREGORIAN
NLS_COMP---BINARY
NLS_CURRENCY---$
NLS_DATE_FORMAT---DD-MON-RR
NLS_DATE_LANGUAGE---AMERICAN
NLS_DUAL_CURRENCY---$
NLS_ISO_CURRENCY---AMERICA
NLS_LANGUAGE---AMERICAN
NLS_LENGTH_SEMANTICS---BYTE
NLS_NCHAR_CONV_EXCP---FALSE
NLS_NUMERIC_CHARACTERS---.,
NLS_SORT---BINARY
NLS_TERRITORY---AMERICA
NLS_TIMESTAMP_FORMAT---DD-MON-RR HH.MI.SSXFF AM
NLS_TIMESTAMP_TZ_FORMAT---DD-MON-RR HH.MI.SSXFF AM TZR
NLS_TIME_FORMAT---HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT---HH.MI.SSXFF AM TZR

回复 只看该作者 道具 举报

8#
发表于 2012-3-12 11:18:40
有一点是A服务器上有其他的网站程序,连接的是mysql,中文显示正常,就是在连接oracle的程序部分,中文显示乱码

回复 只看该作者 道具 举报

9#
发表于 2012-3-12 11:23:18
PHP 连接oracle 的源码 oci_connect 是如何调用的?

回复 只看该作者 道具 举报

10#
发表于 2012-3-12 11:31:21

程序员是用pdo连接ORACLE的

$serviceHost = array(
        //'dsn' => 'oci:dbname=orcl;host='.$_setting['oracledbhost'].';charset=utf8',
        'dsn' => "oci:dbname=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ".$_setting['oracledbhost'].")(PORT = 1521)) (CONNECT_DATA =(SERVER = orcl)(SERVICE_NAME = orcl)))",
        'username' => $_setting['oracledbuser'],
        'passwd' => $_setting['oracledbpw']
);

$serviceDb = new PDO($serviceHost['dsn'], $serviceHost['username'], $serviceHost['passwd']);

回复 只看该作者 道具 举报

11#
发表于 2012-3-12 11:34:16
//'dsn' => 'oci:dbname=orcl;host='.$_setting['oracledbhost'].';charset=utf8',
  'dsn' => "oci:dbname=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ".$_setting['oracledbhost'].")(PORT = 1521)) (CONNECT_DATA =(SERVER = orcl)(SERVICE_NAME = orcl)))",

这个实体的DSN里没有加charset=utf8啊

回复 只看该作者 道具 举报

12#
发表于 2012-3-12 22:03:10
加了,但是不起作用啊,问题依旧

回复 只看该作者 道具 举报

13#
发表于 2012-3-12 22:05:03
刚开始的时候,是用pdo链接的,但是这种方式没没有办法设置字符集,后来用你上面的方式链接,也设置了charset=utf8还是一样;但是跟程序员沟通,说是用JS调用数据库的时候,查询出的数据却是正常的!越来越不摸着头脑了

回复 只看该作者 道具 举报

14#
发表于 2012-3-12 22:17:30
export NLS_LANG="SIMPLIFIED CHINESE.AL32UTF8"

修改以上 NLS_LANG 变量

再试一下

DSN 和 PDO 是如何修改的?

回复 只看该作者 道具 举报

15#
发表于 2012-3-12 22:25:45
需要 coder 对 character set 的调试有所了解, 确保你这个页面本身的 字符集是 UTF8的。

回复 只看该作者 道具 举报

16#
发表于 2012-3-12 23:05:46
谢谢maclean的帮助,明天回公司在解决,现在登录不到服务器!

回复 只看该作者 道具 举报

您需要登录后才可以回帖 登录 | 注册

QQ|手机版|Archiver|Oracle数据库数据恢复、性能优化

GMT+8, 2024-11-15 10:36 , Processed in 0.061039 second(s), 24 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部
TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569