ORA-00913: too many values分析

  今天晚上旁边的同事在调试代码时出现了下面的bug:

 ORA-00913: too many values

 。。。。(后面的具体的就不写了)

第一次碰到这样的情况,上网一查才知道:原来同事的sql语句写错了:具体就不说了,主要是一个INSERT语句:结果

VALUES后面的插入的数据比前面的字段名多了一个,所以才出现了所谓的“too many values”错误。

---------------------------------------

我参考的1个帖子如下:感觉写得不错(虽然是e文写的):

http://www.techonthenet.com/oracle/errors/ora00913.php

Oracle/PLSQL: ORA-00913 Error


Error:

ORA-00913: too many values

Cause:

You tried to execute an SQL statement that required two sets of equal values, but you entered more items in the second set than was in the first set.

Action:

The options to resolve this Oracle error are:
  1. This error often occurs when you are performing an INSERT statement and enter more values in the VALUES clause than the number of columns that you listed.

For example, if you executed the following INSERT statement:

INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(1000, 'Microsoft', 'Bill Gates');

In this example, you've chosen to insert values into 2 columns (supplier_id and supplier_name), but you've entered 3 values (1000, Microsoft, and Bill Gates).

You need to modify your INSERT statement so there are the same number of columns as there are values. For example:

INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(1000, 'Microsoft');


  1. This error can also occur when your subquery in the WHERE clause returns too many columns.

For example, if you executed the following SQL statement:

SELECT * FROM suppliers
WHERE supplier_id > 5000
AND supplier_id IN(SELECT * FROM products
  WHERE product_name LIKE 'H%);

In this example, the subquery returns all columns from the products table. You need to modify the subquery to return only one column as follows:

SELECT * FROM suppliers
WHERE supplier_id > 5000
AND supplier_id IN(SELECT product_id FROM products
 

 WHERE product_name LIKE 'H%);

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值