execute immediate statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kannan1983
    New Member
    • Aug 2007
    • 10

    execute immediate statement

    what is the difference between

    TRUNCATE TABLE table_name

    and

    EXECUTE IMMEDIATE'TRUNC ATE TABLE table_name'

    is there any performance issue between this two?
    which is best to use in procedures?
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    TRUNCATE TABLE <table_name> is a DDL statement.
    You cannot use this directly in the PLSQL blocks.
    So in order to use TRUNCATE TABLE <Table_Name> u need to execute this using EXECUTE IMMEDIATE 'TRUNCATE TABLE <Table_Name>' else the PLSQL bolck will throw an error.

    EXECUTE IMMEDIATE clause is mainly used to execute dynamic SQL statements and DDL statements within PLSQL block.

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      EXECUTE IMMEDIATE you can frame the sql statment dynamically ,where u can also pass the table name dynamically to TRUNCATE .

      EXECUTE IMMEDIATE uses late binding so performance might be faster.

      Comment

      Working...