1 select
Use the SELECT statement to retrieve values from a database or from an SPL. Rows or values that satisfy the specified search criteria of the query are called qualifying rows or values. What the query retrieves to its calling context, after applying any additional logical conditions, is called the result set of the query. This result set can be empty.
<select
prefix='prefix'
struct='struct'
required='true|false'
intotemp='intotemp'
type='type'
cache='true|false'
prepare='true|false'
prepare-cache='true|false'
secure='true|false'
oracle='ansi'
iwa-accelerat='on|off'
iwa-fallback='on|off'
config='true|false'
>
<columns> !
<cols /> +
</columns>
<from table='table'> !
<join
table='table'
type='left'
alias='alias'
> ?
<on> +
<join_tables_condition /> +
</on>
</join>
</from>
<where> !
<where /> !
</where>
<group> !
<groupby /> !
</group>
<having> !
<having /> !
</having>
<order> !
<orderby /> !
</order>
</select>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aprefix | string | Prefix of the variables. | |||
Astruct | string |
Name of the structure to create with the content of the selected columns. If the attribute struct is used, you can not use the attribute prefix. The name of the elements of the structure is determined by the name of the columns selected in the SQL. |
|||
Arequired | boolean | Yes to provoke an exception when the query does not return registers. | |||
Aintotemp | string | Name of the temporal table. | |||
Atype | string | ||||
Acache | boolean | True to store in memory the result. Itshould only be activated when the select conditions does not change. | |||
Aprepare | boolean | False to omit the prepare of a select. More information. | |||
Aprepare-cache | boolean | False so that the statement prepare is not stored in cache. More information. | |||
Asecure | boolean | True to inherit the security of the rol of the BD connection group ti which the user belongs. This flag is always true if the select is being executed from dbconmgr or soap call when embebed xsql code (non-cataloged). More information. | |||
Aoracle | string | Ansi to indicate if you want Oracle to generate the syntax in Ansi format instead of Oracle grammar. It is used when in Oracle grammar in a SELECT exists a table in a LEFT JOIN that, at the same time is attached to another table of the FROM. This situation is not allowed in Oracle with its grammar. | |||
Aiwa-accelerat | boolean |
On to indicate that this sentence and the followings of the session are tried to execute in the IWA accelerator. The operation affects to the session, so you should indicate the same parameter with off in the following select sentence if you want to activate the accelerator. Off to disable the acceleration attempt through IWA for this sentence ans the followings in the session. |
|||
Aiwa-fallback | string | Off indicates that the select sentence should be obligatorily executed in an IWA accelerator and for this the parameter iwa-accelerate must have the value on. If the sentence can not be accelerated, it returns an error. With this mode, it tries to accelerate the active sentence, deactivating the acceleration for the rest of the following sentences. | |||
Aconfig | string | Indicates that the sentence should be executed on the configuration BD wic_conf. So that the operation can be performed is necessary that the BD connection group has the table or the tables used in the sentence in the list of authorized tables to perform SELECT in the wic_conf database. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Ecolumns | string | Name of selected columns. | |||
Ecols | string | ||||
Efrom | string | Name of the main table of the query. | |||
Atable | string | ||||
Ejoin | string | ||||
Atable | string | ||||
Atype | string | ||||
Aalias | string | ||||
Eon | string | ||||
Ejoin_tables_condition | string | ||||
Ewhere | string | ||||
Ewhere | string | ||||
Egroup | string | ||||
Egroupby | string | ||||
Ehaving | string | ||||
Ehaving | string | ||||
Eorder | string | ||||
Eorderby | string |
Returns | |
---|---|
Type | Description |
integer | Number of selected registers. |
Exceptions
database required
You need to specify the database.
The specified table is not in the database.
The table does not exists.
not found [required attribute]
A required attribute has not been informed.
a subquery has returned more than one row
The subquery returns more than one register.
intotemp select, can not return data
Remarks
To execute a query is necessary that the user will be identified and that a database will be selected. This is informed through the options -user and -dbms of the command ws-dbscript.
The querys in XSQL-Script offers several advantages. For this cases in whose that the result of the SELECT sentence is composed of a single register and in which each value of the tupla is required to be asigned to a variable, you can use the attribute prefix to get automatically the following:
Creation of as many variables as there are fields on the label <columns>. The name of each variable is formed by the concatenation of the prefix (value of the attribute prefix) with the name of the column. For those cases in which the resulting column will be an adittion function (COUNT, SUM...), you should specify an alias. The type of each variable is adopted in function of the data type of each value resulting of the query. Each variable is assigned the corresponding value of the recordset.
The default value of the attribute cache is false. Through this attribute is possible to store in memory a query for a fix variable values. In this way, when a query is executed again, in which those variables contains the same value than the cached query, the query is reused, obtaining the immediate result (the same which was obtained in the stored query). When you perform a query in XSQL-Script, it is converted to the SQL syntax native og the database agent (option -dbms)
Remarks
If then the user execute a query whose content of variables was identical to the variables of the image query, he will obtain the result immediately because this query is stored in memory (cache).
The default value of the attribute prepare is true. Through this attribute is possible to prepare a query in which the variables are replaced by '?'. If in addition it has not been indicated prepare-cache='false', the prepare is stored in cache, in this way, when a query is executed again with the same structure than the 'prepared' query, the question marks are replaced by the corresponding value in the variables of the current query, getting a streamlining of the selection process.
Remarks
It exists an exception to 'prepare' the query. If this query has the tag <nvl> and also has informed the attribute prepare (by default true), an execution error is produced.
Remarks
To avoid this exception is necessary to inform the attribute prepare-cache with value false.
Select registers of a table through search condition.
<xsql-script name='select_sample1'> <body> <print.sql> <select> <columns>linid, cabid, codean, codart, varstk</columns> <from table='garticul' /> <where>linid = '0'</where> </select> </print.sql> </body> </xsql-script>
The content of the columns linid, cabid, codean, codart and varstk of the table garticul are shown on screen for all the registers which accomplish linid = 0.
Select registers of a table through search condition and group.
<xsql-script name='select_sample2'> <body> <print.sql> <select> <columns>linid, cabid, codean, codart, varstk</columns> <from table='garticul' /> <where>linid = '0'</where> <group>cabid</group> </select> </print.sql> </body> </xsql-script>
The content of the columns linid, cabid, codean, codart and varstk of the table garticul are shown on screen for all the registers which accomplish linid = 0. The registers are grouped by the column cabid.
Select registers of a table through search condition, group and group condition.
<xsql-script name='select_sample3'> <body> <print.sql> <select> <columns>linid, cabid, codean, codart, varstk</columns> <from table='garticul' /> <where>linid = '0'</where> <group>cabid</group> <having>count(cabid) > 3</having> </select> </print.sql> </body> </xsql-script>
The content of the columns linid, cabid, codean, codart and varstk of the table garticul are shown on screen for all the registers which contains linid = 0. The registers which accomplish the group condition (having) are shown grouped by the column cabid.
Select registers of a table through search condition, group, group condition and order.
<xsql-script name='select_sample4'> <body> <print.sql> <select> <columns> linid, cabid, codean, codart, varstk </columns> <from table='garticul' /> <where>linid = '0'</where> <group>cabid</group> <having>count(cabid) > 3</having> <order>2</order> </select> </print.sql> </body> </xsql-script>
The content of the columns linid, cabid, codean, codart and varstk of the table garticul are shown on screen for all the registers which contains linid = 0. The registers which accomplish the group condition are shown grouped by the column cabid. The registers appears ordered by the field cabid.
Select registers of a table and put it in a variable of struct type.
<xsql-script name='select_sample5'> <body> <foreach> <select struct='s_garticul> <columns> code, name </columns> <from table='garticul' /> <where>codart = 'A1'</where> </select> <do> <println><string>Codigo. <s_garticul.code/> Name: <s_garticul.name/></string></println> </do> </foreach> </body> </xsql-script>
Create a selection cursor which deposit the selected data in a variables of struct type created automatically through the types and column names of the selected data.
Info
When a SQL query is estimated that it will be executed many times, invariably and during differents script executions, it is recommended to indicate to the interpret to store it in memory (cache). In this way, you get that the script will be more efficient in execution time.
Info
The attribute columns and the argument <columns> are excluding.