how to pass a table name as parameter to stored procedure?

我的未来我决定 提交于 2019-12-02 04:28:34

You can't create a %ROWTYPE variable for an unknown table and you can't statically refer to column names when you don't know the table name at compile time.

You can use the dbms_sql package to deal with completely dynamic SQL statements. You'll need to prepare the SQL statement, describe the columns to find out the number of columns and their data types, bind appropriate variables, and then fetch the data. It's a much more cumbersome way of writing code than the example you posted but it gives you extreme flexibility.

There are a number of examples of using the dbms_sql package in the documentation I linked to. You may also want to check out Tom Kyte's dump_csv function which writes the result of an arbitrary query to a CSV file using UTL_FILE. If you really want to write the data to DBMS_OUTPUT, you could simply replace the UTL_FILE calls with DBMS_OUTPUT. But I'm pretty sure you want to do something more useful than just writing the data to the DBMS_OUTPUT buffer so Tom's procedure is probably closer to what you're really trying to accomplish.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!