4D v13.4

EXECUTE IMMEDIATE

Home

 
4D v13.4
EXECUTE IMMEDIATE

EXECUTE IMMEDIATE  


 

 

 EXECUTE IMMEDIATE <<sql_name>> | <<$sql_name>> | :sql_name | :$sql_name

The EXECUTE IMMEDIATE command is used to execute a dynamic SQL statement. The sql_name passed represents a variable containing a set of SQL statements that will be executed as a whole.

Notes:

  • This command cannot be used within a connection to an external data source (SQL pass-through) established using the USE EXTERNAL DATABASE 4D command.
  • In compiled mode, it is not possible to use local 4D variables (beginning with the $ character) in the query string passed to the EXECUTE IMMEDIATE command.

Example  

This example recovers the number of movies in the database that were released in 1960 or more recently:

 C_LONGINT(NumMovies)
 C_TEXT(tQueryTxt)
 NumMovies:=0
 
 tQueryTxt:="SELECT COUNT(*) FROM MOVIES WHERE Year_of_Movie >= 1960 INTO :NumMovies;"
 Begin SQL
    EXECUTE IMMEDIATE :tQueryTxt;
 End SQL
 
 ALERT("The Video Library contains "+String(NumMovies)+" movies more recent or equal to 1960")

 
PROPERTIES 

Product: 4D
Theme: SQL Commands

 
INDEX

Alphabetical list of commands