Plsql 如何在oracle中执行包含两个insert语句的存储过程?

Plsql 如何在oracle中执行包含两个insert语句的存储过程?,plsql,oracle11g,Plsql,Oracle11g,我正在尝试执行一个包含两个insert语句的存储过程,但是我不确定如何执行,或者是否有更好的方法来执行。存储过程有两个insert语句,它们将数据插入到两个不同的表中 我尝试了执行新订单()请参见下文,然后传入值,但在第1行:ORA-06550:line 1,column 7:PLS-00306:调用“new_order”ORA-06550:line 1,column 7:PL/SQL:语句忽略时出现此错误非常感谢您的帮助 execute new_order( '4', 'O223PS562

我正在尝试执行一个包含两个insert语句的存储过程,但是我不确定如何执行,或者是否有更好的方法来执行。存储过程有两个insert语句,它们将数据插入到两个不同的表中

我尝试了执行新订单()请参见下文,然后传入值,但在第1行:ORA-06550:line 1,column 7:PLS-00306:调用“new_order”ORA-06550:line 1,column 7:PL/SQL:语句忽略时出现此错误
非常感谢您的帮助

 execute new_order(
'4', 
'O223PS562', 
'Test Test', 
'test@test.co.uk', 
'123 Test Street', 
'Newcastle Upon Tyne', 
'Tyne and Wear', 
'NE98 4TN', 
'123456789', 
'7.97', 
'11-apr-2021',
'5', 
'4', 
'2', 
'2', 
'3073748221',
'2', 
'Brand new',
'1.99', 
'2.00');

正如错误所说,您传递了错误的参数数量或类型

如果您试图用这么多参数调用过程,我强烈建议您使用命名参数语法。否则,如果人们试图弄清楚第20个参数传递给过程的是什么,那么当他们忽略一个参数或以错误的顺序传递参数时,往往很难注意到。就我个人而言,在我试图传入20个参数之前,我倾向于重构一个过程。传递一两种记录类型这样简单的东西可能会使代码更易于阅读和理解

我已将您的调用更改为使用命名参数,并为您犯错误的地方添加了注释

execute new_order(
  p_order_id => 4, -- Pass in a number rather than using implicit conversion
  p_order_num => 'O223PS562', 
  p_name => 'Test Test', 
  p_email => 'test@test.co.uk', 
  p_address => '123 Test Street', 
  p_city => 'Newcastle Upon Tyne', 
  p_province => 'Tyne and Wear', 
  p_postcode => 'NE98 4TN', 
  p_telephone => '123456789', 
  p_total => 7.97, -- Pass in a number rather than using implicit conversion
  p_order_date => to_date('11-apr-2021', 'DD-mon-YYYY'), -- Pass in a date rather than using implicit conversion
  p_order_item_id => 5, -- Pass in a number rather than using implicit conversion
  p_product_id => 4, -- Pass in a number rather than using implicit conversion
  p_seller_id => 2, -- Pass in a number rather than using implicit conversion 
  p_sub_order_number => 2, -- Pass in a number rather than using implicit conversion 
  p_quantity => 3073748221, -- Do you really want the quantity to be in the billions?  That seems unlikely.  
                            -- Perhaps there was supposed to be a phone number parameter
  p_condition => '2', -- That doesn't look like a condition.  Probably meant to be a unit price
  p_unit_price => 'Brand new', -- Here we have a definite error.  p_unit_price is a number but you can't connvert
                               -- the string 'Brand new' to a number.  I assume that was really supposed to be the
                               -- condition
  p_cost_charge => 1.99, -- Pass in a number rather than using implicit conversion
  '2.00' -- And here we have a value being passed in but no equivalent parameter
);    

该错误表示用于调用此过程的代码(您没有包括在内)传入了错误数量的参数或错误的数据类型。由于您没有包含用于调用该过程的代码,因此除了错误消息之外,任何人都无法提供更多信息。当我删除其中一个insert查询时,它执行得很好,因为它传递了正确数量的参数,但我希望该过程同时执行这两个查询。您不能用两个insert查询执行一个过程,还是有办法合并它们?在一个过程中,您可以有任意多个SQL语句。删除其中一条insert语句时,是否正在删除过程中的某些参数,因为这些参数没有被使用?添加第二条insert语句时,是否正在更改调用此过程以传入新参数的方法?是的,我删除了order_项的变量,但是
p_order_id
参数用于两个查询。我不这么认为,我只是在第一个查询下面添加了另一个insert查询。你能给我举个例子@JustinCave吗?举个什么的例子?如果在过程生成错误时发布用于调用该过程的代码,我们可能会告诉您调用者出了什么问题。该过程成功执行,但由于某种原因,第一次插入查询的数据没有填充到表中。@Jal-这可能是另一个问题。发布可复制的测试用例。理想情况下,在dbfiddle.uk上设置一个链接,向我们显示问题所在。我的猜测是发生了异常,除非调用方碰巧启用了
dbms\u输出
,否则您的异常处理程序正在吞咽异常,并且有关错误的信息正在丢失。我更希望没有异常处理程序,而不是你问题中的异常处理程序。好的,谢谢你,我将尝试从这里调试它。
execute new_order(
  p_order_id => 4, -- Pass in a number rather than using implicit conversion
  p_order_num => 'O223PS562', 
  p_name => 'Test Test', 
  p_email => 'test@test.co.uk', 
  p_address => '123 Test Street', 
  p_city => 'Newcastle Upon Tyne', 
  p_province => 'Tyne and Wear', 
  p_postcode => 'NE98 4TN', 
  p_telephone => '123456789', 
  p_total => 7.97, -- Pass in a number rather than using implicit conversion
  p_order_date => to_date('11-apr-2021', 'DD-mon-YYYY'), -- Pass in a date rather than using implicit conversion
  p_order_item_id => 5, -- Pass in a number rather than using implicit conversion
  p_product_id => 4, -- Pass in a number rather than using implicit conversion
  p_seller_id => 2, -- Pass in a number rather than using implicit conversion 
  p_sub_order_number => 2, -- Pass in a number rather than using implicit conversion 
  p_quantity => 3073748221, -- Do you really want the quantity to be in the billions?  That seems unlikely.  
                            -- Perhaps there was supposed to be a phone number parameter
  p_condition => '2', -- That doesn't look like a condition.  Probably meant to be a unit price
  p_unit_price => 'Brand new', -- Here we have a definite error.  p_unit_price is a number but you can't connvert
                               -- the string 'Brand new' to a number.  I assume that was really supposed to be the
                               -- condition
  p_cost_charge => 1.99, -- Pass in a number rather than using implicit conversion
  '2.00' -- And here we have a value being passed in but no equivalent parameter
);