Oracle
 sql >> Database >  >> RDS >> Oracle

Come eseguire una procedura memorizzata in Oracle che contiene due istruzioni di inserimento?

Come dice l'errore, stai passando il numero o il tipo di parametri sbagliato.

Consiglio vivamente di utilizzare la sintassi dei parametri denominati se si sta tentando di chiamare una procedura con così tanti parametri. Altrimenti, gli esseri umani tendono ad avere difficoltà a notare quando omettono un parametro o passano i parametri nell'ordine sbagliato se stanno cercando di capire cosa stanno passando per il 20° parametro a una procedura. Personalmente, tenderei a rifattorizzare una procedura molto prima di provare a passare 20 parametri. Qualcosa di semplice come passare uno o due tipi di record potrebbe rendere il codice molto più facile da leggere e capire.

Ho modificato la tua chiamata per utilizzare parametri denominati e aggiunto commenti per i punti in cui hai commesso errori.

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 => '[email protected]', 
  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
);