Im new to cursors in Oracle. I have a piece of SQL that is contained in a variable. I want to open a cursor with this sql. How do I do this? Seems simple but all the examples I find just have the sql typed directly below the "open cursor_name for" statement.
Here is what I would like to run (assume I have variable v_sql with my sql query):
open my_cursor for v_sql;
Oracle doesnt like this though. I also tried
open my_cursor for
execute immediate v_sql;
Help please.
v_sql. It is perfectly safe to assemble a SQL query inside a procedure.open my_cursor for v_sql;is the correct usage, so the problem must lie with the surrounding code context, or the statement you're executing.