Newbie Question about dynamic table name references

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kalyson
    New Member
    • Mar 2008
    • 11

    Newbie Question about dynamic table name references

    Hello,
    I realize that using the TYPE declaration for variables makes their definitions more dynamic, like this:

    myField tablename.name% TYPE;
    myRow tablename%ROWTY PE;


    But I also want to be able to change the name of the table in the code.

    So I want to have "tablename" above refer to a VARIABLE that contains the name of a table, so I don't have to go changing the tablename throughout the code if the table name changes.

    Is there a way to do this with PL/SQL?

    Thanks,
    Kalyson
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    For late binding you need to use dynamic SQL.

    Try to use EXECUTE IMMEDIATE.

    But it is better to use ref cursor or sys ref cursor for the purpose.

    Comment

    Working...