In a PL / SQL procedure, how do I pass a table name as a parameter?

CREATE PROCEDURE A(tab IN <table - what should I write here?>) AS
BEGIN
   INSERT INTO tab VALUES(123);
END A;

How can I indicate that a parameter tabis a table name?

+3
source share
1 answer

You can not. Instead, you need to pass it as a VARCHAR2 string, and then use Dynamic SQL:

CREATE PROCEDURE A(tab IN VARCHAR2) AS
BEGIN
   EXECUTE IMMEDIATE 'INSERT INTO ' || tab || 'VALUES(123)';
END A;

Read Dynamic SQL and keep abreast of the problems that it can bring if they are unreasonable to use, such as lower performance, scalability and security.

+11
source

Source: https://habr.com/ru/post/1758702/


All Articles