Stored procedure with ROW instead of a list of parameters

insertoracleplsqlstored-procedures

I have a table with 15 columns, and trying to create a stored procedure in PL SQL that will only insert a row in a table using the INSERT statement.

I would like to know if it is possible to declare the list of IN parameters of the stored procedure as a RECORD structure instead of 15 parameter, so when calling this stored procedure, I will only pass a RECORD structure instead of 15 single variables.

Is that possible in PL SQL? If no, is there any shorthand for doing this kind of declarations? Thanks

Best Answer

Sure. You can even use the predefined %rowtype record.

CREATE OR REPLACE PROCEDURE insert_row( p_rec IN table_name%rowtype )
AS
BEGIN
  INSERT INTO table_name
    VALUES p_rec;
END;