楼主: bisal

[讨论] 一张表有多个VARCHAR2类型

[复制链接]
论坛徽章:
7
茶鸡蛋
日期:2013-06-14 13:16:17优秀写手
日期:2013-12-18 09:29:112014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:022015年新春福章
日期:2015-03-04 14:51:122015年新春福章
日期:2015-03-06 11:57:31ITPUB社区OCM联盟徽章
日期:2016-07-13 18:10:08
11#
 楼主| 发表于 2014-8-20 08:09 | 只看该作者
Yong Huang 发表于 2014-8-12 21:37
chwp,

Are you saying PLSQL Developer (I think you mean SQL Developer?) is not using OCI? When I i ...

我又试了下:
分别使用9i和10g创建以下表:
create table tbl_varchar(a varchar2(4000), b varchar2(4000), c varchar2(4000));

使用proc相同的程序,执行INSERT操作,结论是9i就是会报ORA-01461: can bind a LONG value only for insert into a LONG column的错误,10g正常插入。

请问这是因为版本特性?proc是使用的SQLLIB方式。

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
12#
发表于 2014-8-21 00:16 | 只看该作者
Parameter nls_length_semantics is byte for both databases?

Sorry I don't have enough experience with Pro*C. You may want to open an SR with Oracle. I searched on the Internet and found these

http://bytes.com/topic/oracle/an ... ough-pro-c-utf-8-db
http://www.databaseskill.com/682006/
http://www.itpub.net/thread-1828787-1-1.html

It's hard to come up with good keywords to search. MyOracleSupport is malfunctioning when it comes to a keyword with * in the middle.

使用道具 举报

回复
论坛徽章:
7
茶鸡蛋
日期:2013-06-14 13:16:17优秀写手
日期:2013-12-18 09:29:112014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:022015年新春福章
日期:2015-03-04 14:51:122015年新春福章
日期:2015-03-06 11:57:31ITPUB社区OCM联盟徽章
日期:2016-07-13 18:10:08
13#
 楼主| 发表于 2014-8-22 20:59 | 只看该作者
Yong Huang 发表于 2014-8-21 00:16
Parameter nls_length_semantics is byte for both databases?

Sorry I don't have enough experience w ...

谢谢您,我也在查找这个问题,看看有没有解

使用道具 举报

回复
论坛徽章:
7
茶鸡蛋
日期:2013-06-14 13:16:17优秀写手
日期:2013-12-18 09:29:112014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:022015年新春福章
日期:2015-03-04 14:51:122015年新春福章
日期:2015-03-06 11:57:31ITPUB社区OCM联盟徽章
日期:2016-07-13 18:10:08
14#
 楼主| 发表于 2014-8-25 18:22 | 只看该作者
Yong Huang 发表于 2014-8-21 00:16
Parameter nls_length_semantics is byte for both databases?

Sorry I don't have enough experience w ...

我提了一个问题到社区:
https://community.oracle.com/message/12599901
得到回复,可能由于9i的bug:241358.1

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
15#
发表于 2014-8-26 05:42 | 只看该作者
Excellent! Thanks for this feedback.

使用道具 举报

回复
论坛徽章:
7
茶鸡蛋
日期:2013-06-14 13:16:17优秀写手
日期:2013-12-18 09:29:112014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:022015年新春福章
日期:2015-03-04 14:51:122015年新春福章
日期:2015-03-06 11:57:31ITPUB社区OCM联盟徽章
日期:2016-07-13 18:10:08
16#
 楼主| 发表于 2014-9-6 22:30 | 只看该作者
Yong Huang 发表于 2014-8-26 05:42
Excellent! Thanks for this feedback.

但是黄老师,其中有句话:
“During run-time no check is made for the actual content of the columns. Even if a VARCHAR2(2000) column only contains 1 character, this is treated as if you're using a LONG (just like a LONG that contains only 1 character). If you have 1 of these columns plus a LONG, or simply 2 or more of these columns, effectively the database believes that you are binding 2 long columns. Since that is not allowed you receive this error.”
包含仅仅1个字符的VARCHAR2(>2000)类型,也会按照LONG类型操作,因为一张表只允许一个LONG类型字段,所以如果仅有这样一个的VARCHAR2(>2000)做INSERT不会报错,但若大于1个,则会报这种错误。不理解这为什么“包含仅仅1个字符的VARCHAR2(>2000)类型,也会按照LONG类型操作”?感觉这是我上面proc程序中报错的根本原因。

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
17#
发表于 2014-9-8 23:04 | 只看该作者
You must be reading

Workarounds for bug 1400539: GETTING ORA-1461 INSERTING INTO A VARCHAR (Doc ID 241358.1)

The bug is fixed in 10.1.0.1. So there's really not much need to make it a big deal. But this document about the bug is indeed confusing. At the beginning, it says "A character from the client character set (for example WE8ISO8859P1), can take up to 3 bytes of storage in the database character set UTF8". Note the word "up to". That's correct. Then it says "when you try to use this table from the client, the conversion ratio is set to 1:3... When connecting to a UTF8 server, then all character lengths are multiplied by 3". Note that there's no mention of "up to". Then "Even if a VARCHAR2(2000) column only contains 1 character, this is treated as if you're using a LONG". That's hard to believe. Can you test this in Oracle 9i? One table with two columns, one LONG and one VARCHAR2(2000). Use Pro*C to insert one single character to the varchar2 column. Will you get ORA-1461? I think you'll get the error only if you insert a string longer than a certain length (1333 maybe?).

使用道具 举报

回复
论坛徽章:
7
茶鸡蛋
日期:2013-06-14 13:16:17优秀写手
日期:2013-12-18 09:29:112014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:022015年新春福章
日期:2015-03-04 14:51:122015年新春福章
日期:2015-03-06 11:57:31ITPUB社区OCM联盟徽章
日期:2016-07-13 18:10:08
18#
 楼主| 发表于 2014-9-22 18:29 | 只看该作者
Yong Huang 发表于 2014-9-8 23:04
You must be reading

Workarounds for bug 1400539: GETTING ORA-1461 INSERTING INTO A VARCHAR (Doc I ...

黄老师,我尝试了:
CREATE TABLE tbl_lv (a LONG, b VARCHAR2(2000));
当用PROC插入B字段时,无论多长,即使大于1333,也是可以正常操作的。

但如果向A和B同时插入,则会报这个错误。

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
19#
发表于 2014-9-22 23:46 | 只看该作者
> 但如果向A和B同时插入,则会报这个错误。

So, even if column b takes a single character, it won't work if column a is also being inserted int? I mean,

insert into tbl_lv values ('x','x');

will report ORA-1461?

使用道具 举报

回复
论坛徽章:
7
茶鸡蛋
日期:2013-06-14 13:16:17优秀写手
日期:2013-12-18 09:29:112014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:022015年新春福章
日期:2015-03-04 14:51:122015年新春福章
日期:2015-03-06 11:57:31ITPUB社区OCM联盟徽章
日期:2016-07-13 18:10:08
20#
 楼主| 发表于 2014-9-23 13:08 | 只看该作者
Yong Huang 发表于 2014-9-22 23:46
> 但如果向A和B同时插入,则会报这个错误。

So, even if column b takes a single character, it won't  ...

没错,即使是proc中插入a和b字段都只有一个字符,就会报-1461, ORA-01461: can bind a LONG value only for insert into a LONG column。
用SQLPLUS命令行插入两个字段则可以。

使用道具 举报

回复

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

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表