I am working with PL/SQL. I am sending some parameters to my procedure. One of these parameters should be a column name. Initially it’s a varchar2, but I want to use this in my cursor to reference a column name. How is this possible?
This is what my code looks something like:
PROCEDURE proc_name( x IN VARCHAR2, y IN VARCHAR2 ) IS
cursor csr IS
SELECT *
FROM table
SORT BY x y
BEGIN
for y in csr loop
------
end loop;
END proc_name;
I’ve tried to research this for the last couple of days with no luck. I looked into dynamic SQL, is this the right direction? Doesn’t seem to be working for me.
Thanks in advance for any help
Try this: