SQL 错误:ORA-12899:值对于列来说太大
我创建了下表
CREATE TABLE Customers(
CustomerID varchar2(9) PRIMARY KEY,
Customer_Contact varchar2(40) NOT NULL,
Address varchar2(20) NOT NULL,
Post_Code varchar2(7) NOT NULL,
Telephone_Number varchar2(11) NOT NULL)
,目前我正在尝试使用 INSERT VALUES 语句。我编写了以下语句
INSERT INTO Customers VALUES(
501623129,
'John Petterson',
'-- Singleton Close London',
'--- ---', 02082860222)
当我尝试运行该语句时,它给出了以下错误消息。
命令中从第 4 行开始出错: 插入客户 值(501623129,“大卫·帕特森”, “伦敦辛格尔顿街 30 号”、“SW17” 9JY', 02082860642) 错误报告:SQL 错误:ORA-12899:值太大 列“DJ”.“客户”.“地址” (实际:25,最大:20) 12899. 00000 - “值对于列 %s 来说太大(实际值:%s,最大值:%s)”
I have created the following table
CREATE TABLE Customers(
CustomerID varchar2(9) PRIMARY KEY,
Customer_Contact varchar2(40) NOT NULL,
Address varchar2(20) NOT NULL,
Post_Code varchar2(7) NOT NULL,
Telephone_Number varchar2(11) NOT NULL)
And I am currently trying to use the INSERT VALUES statement. I have written the following statement
INSERT INTO Customers VALUES(
501623129,
'John Petterson',
'-- Singleton Close London',
'--- ---', 02082860222)
When I try to run the statement it gives me the following error message.
Error starting at line 4 in command:
INSERT INTO Customers
VALUES(501623129, 'David Patterson',
'30 Singleton Close London', 'SW17
9JY', 02082860642) Error report: SQL
Error: ORA-12899: value too large for
column "DJ"."CUSTOMERS"."ADDRESS"
(actual: 25, maximum: 20)
12899. 00000 - "value too large for column %s (actual: %s, maximum: %s)"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
告诉你错误是什么。地址最多可容纳 20 个字符,您将传递 25 个字符。
Tells you what the error is. Address can hold maximum of 20 characters, you are passing 25 characters.
如前所述,错误消息向您显示了确切的问题:您正在将 25 个字符传递到设置为容纳 20 个字符的字段中。您可能还需要考虑更精确地定义列。您可以定义 VARCHAR2 列是否存储一定数量的字节或字符。您将来可能会遇到问题,尝试在字段中插入多字节字符,例如长度为 5 个字符,但它无法容纳 5 个字节: 'ÀÈÌÕÛ'
下面是一个示例:
或
As mentioned, the error message shows you the exact problem: you are passing 25 characters into a field set up to hold 20. You might also want to consider defining the columns a little more precisely. You can define whether the VARCHAR2 column will store a certain number of bytes or characters. You may encounter a problem in the future where you try to insert a multi byte character into the field, for example this is 5 characters in length but it won't fit into 5 bytes: 'ÀÈÌÕÛ'
Here is an example:
or
这个答案仍然在 ORA-12899 的列表中排名靠前,并且上面有很多无用的评论,即使它们已经过时了。对于任何试图找出加载数据时出现此问题的专业人士来说,最有帮助的评论是#4。
有些字符的长度超过 1 个字节,在 SQL Server 上尤其如此。适合 SQLServer 中 varchar(20) 的内容不适合 Oracle 中类似的 varchar2(20)。
昨天,我在使用 Attunity 驱动程序加载 Oracle 数据库的 SSIS 中遇到了这个错误,我想我可以节省人们一些时间。
This answer still comes up high in the list for ORA-12899 and lot of non helpful comments above, even if they are old. The most helpful comment was #4 for any professional trying to find out why they are getting this when loading data.
Some characters are more than 1 byte in length, especially true on SQL Server. And what might fit in a varchar(20) in SQLServer won't fit into a similar varchar2(20) in Oracle.
I ran across this error yesterday with SSIS loading an Oracle database with the Attunity drivers and thought I would save folks some time.
就我而言,我使用
C# OracleCommand
和OracleParameter
,并将所有参数Size
属性设置为每列的最大长度,然后错误已解决。In my case I'm using
C# OracleCommand
withOracleParameter
, and I set all the the parametersSize
property to max length of each column, then the error solved.我只是想在这里分享来自 Google 的最佳结果...
我试图添加这样的虚拟列
,而 Oracle 抱怨:
问题是,我的
code
列是varchar2(120 )
因此substr
最多 120 个字符。可以发现,在创建临时表时:
一旦我意识到,
desc
返回,解决方案是使用
export_code varchar2(120 char)
或进行强制转换:I just wanted to share here as the top result from Google...
I was trying to add virtual column like this
and oracle complained:
The problem is, that my
code
column isvarchar2(120)
sosubstr
is up to 120 characters.One can find, when creating a temporary table:
and
desc
returnsonce I realized, the solution is to use
export_code varchar2(120 char)
or do the cast:示例:1和2表可用
1表删除条目并选择nor 2表记录并插入到no 1表。当删除时,没有 1 个表没有第二个表记录示例 emp id 不可用意味着出现此错误
example : 1 and 2 table is available
1 table delete entry and select nor 2 table records and insert to no 1 table . when delete time no 1 table dont have second table records example emp id not available means this errors appeared
试试这个:
Try this: