CREATE PROCEDURE A(tab IN <table - what should I write here?>) AS
BEGIN
INSERT INTO tab VALUES(123);
END A;
How can I specify that the parameter tab
is a table name?
如何指定参数选项卡是表名?
1 个解决方案
#1
11
You can't. Instead you need to pass it in as a VARCHAR2 string and then use Dynamic SQL:
你不能。相反,您需要将其作为VARCHAR2字符串传递,然后使用动态SQL:
CREATE PROCEDURE A(tab IN VARCHAR2) AS
BEGIN
EXECUTE IMMEDIATE 'INSERT INTO ' || tab || 'VALUES(123)';
END A;
Read up about Dynamic SQL and be aware of the issues it can bring if used unwisely, such as poorer performance, scalability and security.
阅读有关动态SQL的信息,并了解如果不明智地使用它可能带来的问题,例如较差的性能,可伸缩性和安全性。
#1
11
You can't. Instead you need to pass it in as a VARCHAR2 string and then use Dynamic SQL:
你不能。相反,您需要将其作为VARCHAR2字符串传递,然后使用动态SQL:
CREATE PROCEDURE A(tab IN VARCHAR2) AS
BEGIN
EXECUTE IMMEDIATE 'INSERT INTO ' || tab || 'VALUES(123)';
END A;
Read up about Dynamic SQL and be aware of the issues it can bring if used unwisely, such as poorer performance, scalability and security.
阅读有关动态SQL的信息,并了解如果不明智地使用它可能带来的问题,例如较差的性能,可伸缩性和安全性。