How to create a function that can Insert in table1, table2, Table3. It has to be called from some other procedure and values will be coming from that procedure.
Asked
Active
Viewed 65 times
-2
-
1`Want to create a function..` so what's stopping you? – Nick Krasnov Sep 29 '16 at 11:58
-
Do some search, try something and then, if you have a problem with your code, feel free to post it here to have some help. – Aleksej Sep 29 '16 at 12:00
-
Do you mean the same values into different tables? – Wernfried Domscheit Sep 29 '16 at 14:07
1 Answers
0
The question is not clear. In general you can create a function which accepts as parameters the values you want to insert in the 3 tables and which will have 3 insert statements (one for each table), assuming no dependencies like FKs between the 3 tables.
create FUNCTION my_function (p_value_11 NUMBER ,p_value_12 varchar2 ,p_value_21 NUMBER ,p_value_31 NUMBER)
RETURN NUMBER
AS
v_result number := 0;
BEGIN
INSERT into my_table_1(col_11,col_12) values (p_value_11,p_value12);
INSERT into my_table_2(col_21) values (p_value_21);
INSERT into my_table_3(col_31) values (p_value_31);
RETURN v_result;
exception
when others then
v_result := -1;
RETURN v_result;
END;
Why does it need to be a function and not a procedure?

E. Ninis
- 36
- 4
-
1
-
-
@E.Ninis- Thank you for sharing the example. I am not sure if it should be a function or procedure. Can you please share an example of procedure as well? – CodERORR Sep 29 '16 at 12:45
-
Search is your friend! http://stackoverflow.com/questions/771949/what-is-the-difference-between-function-and-procedure-in-pl-sql – E. Ninis Sep 29 '16 at 13:44
-
-
@E.Ninis - a procedure example would look the same but it would say `create procedure` and there would be no `return` clause. – William Robertson Sep 29 '16 at 15:18