Skip to main content

Other Ways of Executing SQL

Other Ways of Executing SQL

You can execute a single line of SQL code from the Terminal command line without invoking the SQL Shell by using the $SYSTEM.SQL.Execute()Opens in a new tab method. The following examples show how this method is used from the Terminal prompt:

USER>SET result=$SYSTEM.SQL.Execute("SELECT TOP 5 name,dob,ssn FROM Sample.Person")

USER>DO result.%Display()
USER>SET result=$SYSTEM.SQL.Execute("CALL Sample.PersonSets('M','MA')")

USER>DO result.%Display()

If the SQL statement contains an error, the Execute() method completes successfully; the %Display() method returns the error information, such as the following:

USER>DO result.%Display()

[SQLCODE: <-29>:<Field not found in the applicable tables>]
[%msg: < Field 'GAME' not found in the applicable tables^ SELECT TOP ? game ,>]
0 Rows Affected
USER>

The Execute() method also provides optional SelectMode, Dialect, and ObjectSelectMode parameters.

InterSystems IRIS supports numerous other ways to write and execute SQL code:

FeedbackOpens in a new tab