Please tell me what is the use of using EXECUTE IMMEDIATE statement ??
As per the docs it says that :
The EXECUTE IMMEDIATE statement prepares (parses) and immediately executes a dynamic SQL statement .
The EXECUTE IMMEDIATE statement parses the SQL string command and executes the statement. An example of the EXECUTE IMMEDIATE in a block :
Here , i am having a query , what is the use of using EXECUTE IMMEDIATE , i mean if i dont use EXECUTE IMMEDIATE will my statement will not be created ?? For example :The below will also work where , i am not using any EXECUTE IMMEDIATE to process a statement , please explain , thanks in advance .
SELECT statement can also be dynamic,
but you cannot use SELECT in a PL/SQL procedure in the same way as in a gui tool like SqlPlus, Toad or SQL-Developer.
Interactive GUI tools accept ordinary SQL syntax like SELECT xx FROM yyy, they execute queries entered interactively by the user
and display results of queries on the screen to the user.
But PL/SQL is not a gui tool, it doesn't display results of the query on the screen and it doesn't accept simple SELECT syntax.
You must use SELECT column_list INTO variable_list syntax to collect query results into PL/SQL variables (if your query returns only one row)
or SELECT column_list BULK COLLECT INTO collection_variable_list to collect many values into collections,
or open a cursor (cursors can be used also with dynamic SQL) and fetch row by row from returned resultset.