Oracle:PL/SQL中用SQL语句添加数据 中文出现乱码问题?[有图]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle:PL/SQL中用SQL语句添加数据 中文出现乱码问题?[有图]相关的知识,希望对你有一定的参考价值。
类型是VARCHAR2(20),如图所示,求人解答?
说明数据库不支持中文,修改为GBK或者Utf-8就可以了。
ALTER SYSTEM DISABLE RESTRICTED SESSION;改完编码后执行sql> conn / as sysdba;
sql> shutdown immediate;
database closed.
database dismounted.
oracle instance shut down.
sql> startup mount;
oracle instance started.
total system global area 135337420 bytes
fixed size 452044 bytes
variable size 109051904 bytes
database buffers 25165824 bytes
redo buffers 667648 bytes
database mounted.
sql> alter system enable restricted session;
system altered.
sql> alter system set job_queue_processes=0;
system altered.
sql> alter system set aq_tm_processes=0;
system altered.
sql> alter database open;
database altered.
sql> alter database character set internal_use UTF-8;
sql> shutdown immediate;
sql> startup;
查看数据库编码格式:select userenv('language') from dual;
如果数据库格式支持中文,那么就要看下执行的sql是不是本身就有乱码了。
参考技术A 不加N?insert into table
values(.....,N'中文',...)这种模式,而且列必须为nvarchar格式才能存储中文不乱码追问
经试验、无用,仍没解决... 有劳看看 附图在下!
就是那个列必须要nvarchar格式,不然会存储中文乱码
参考技术B 用这个查询ORACLE的编码类型,看与你插入的是否一致select * from nls_database_parameters where parameter ='NLS_CHARACTERSET';追问
以查、看不懂,如何设置? 附图在下! 望解答...
按照图片把你的字符集设置成跟你的所查询的字符编码一致试下看。ZHS16GBK
SQL Plus 无法识别 Oracle PL/SQL 语句
【中文标题】SQL Plus 无法识别 Oracle PL/SQL 语句【英文标题】:Oracle PL/SQL statements not being recognised by SQL Plus 【发布时间】:2014-04-20 17:10:57 【问题描述】:我在 64 位笔记本电脑上安装了 11g 32 位 Oracle Express。 sql plus 将任何 pl/sql 语句/语法视为错误,并且仅识别 sql 代码。
一定是某个地方的 Oracle 配置问题。这是在上一次安装遇到相同问题后全新安装的 Oracle Express。
其他人有这个问题吗?我已经在谷歌上搜索死了,但没有提出解决方案。
Set serveroutput on
Set echo off
Remark *** Set up the SQL*Plus environment ***
Set Pagesize 24
Set Feedback Off
Remark *** Format the Columns ***
Column ctype Format A5 Heading Car|Type
Column A Format A3 Heading A
Column B Format A3 Heading B
Column C Format A3 Heading C
Column D Format A3 Heading D
Column E Format A3 Heading E
Column F Format A3 Heading F
Column G Format A3 Heading G
break on ctype
Remark *** The Query ***
DECLARE
v_cid VARCHAR2(3);
v_grade CHAR(1);
BEGIN
FOR ct IN (SELECT c_type# as ct FROM consultant)
LOOP
v_cid := ct;
SELECT c_type# as ctype,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'A')) as A,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'B')) as B,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'C')) as C,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'D')) as D,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'E')) as E,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'F')) as F,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'G')) as G
FROM consultant
WHERE consultant.c_type# = v_cid
GROUP BY c_type#
ORDER BY ctype;
END LOOP;
END;
/
SELECT car_type.c_type# as ctype,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'A')) as A,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'B')) as B,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'C')) as C,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'D')) as D,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'E')) as E,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'F')) as F,
TO_CHAR((SELECT count(grade) FROM consultant WHERE grade = 'G')) as G
FROM consultant
INNER JOIN grade
ON consultant.grade = grade.grade
INNER JOIN car_type
ON consultant.c_type# = car_type.c_type#
GROUP BY car_type.c_type#
ORDER BY ctype
/
Remark *** Reset the environment ***
Clear columns
Ttitle Off
Btitle Off
Set Feedback on
Set Pagesize 20
Set Echo on
Error code : ERROR at line 1:
ORA-00922: missing or invalid option
【问题讨论】:
发布声明和确切错误消息。 编辑了我的原始帖子以反映代码。 和任何 pl sql 代码(如 DECLARE、BEGIN)都会引发错误。虽然没有 sql 错误。 如何在 SQLplus 中运行这些语句?我猜你不会每次尝试时都输入它们。 '任何 PL/SQL 语句/语法' - 引发 ORA-00922 的最少代码是什么?除了 jonearles 指出的不正确的光标引用之外,您在循环中的选择没有选择 into 任何东西。 【参考方案1】:替换
v_cid := ct;
与
v_cid := ct.ct;
代码必须引用cursor_name.column_name
,即使游标和列名相同。此外,它总是有助于将问题减少到尽可能小的规模。
【讨论】:
谢谢你,但是在错误上没有区别。 SQL Plus 似乎对 PL SQL 产生了厌恶,并拒绝承认它的存在。自从移到新机器上,代码一切正常。 在 SQL*Plus 中即使是像这样的微不足道的 PL/SQL 块也会失败:exec null;
【参考方案2】:
免费的 Oracle Express 不支持 PlSql
【讨论】:
以上是关于Oracle:PL/SQL中用SQL语句添加数据 中文出现乱码问题?[有图]的主要内容,如果未能解决你的问题,请参考以下文章
pl/sql连接Oracle不管执行啥语句都会重复执行这条语句,永不停止,怎么办呀
oracle pl/sql insert 语句同时插入了重复数据问题