All the examples in this series have been tested only with Oracle 10g (V10.2). I didn’t really test any of the examples in any of the previous versions. If you have any problems during the execution of these examples, please post in the discussion area. How to insert a row into a table using a PL/SQL stored procedure The following is the stored procedure which deals with inserting a particular row into a table. create or replace procedure p_emp_insert (p_empno emp.empno%type, The above is a stored procedure named “p_emp_insert” which accepts four parameters. Once all the parameters are passed in, it executes an INSERT statement to insert (or add) those values in the form of a row. The following is the code available in the error handling (or exception handling) section, which mainly deals with errors/exceptions raised at run-time: when dup_val_on_index then I mainly worked with two of the pre-defined exceptions, namely “dup_val_on_index” and “others.” The “dup_val_on_index” is mainly raised when the runtime tries to insert a row with a repeated value in a unique or primary column. The “others” exception is raised when the runtime come across any other errors (apart from “dup_val_on_index,” as it is already handled). The SQLERRM is a built-in item which mainly contains the error message for the error or exception raised. To execute the above stored procedure, you can issue the following command at the SQL prompt: SQL> EXEC p_emp_insert(1001, 'Jag', 3400, 30)
blog comments powered by Disqus |