# QueryBuilder

> QueryBuilder is the query builder for Oracle databases (version 12.1 and above).

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › [oci](/docs/api/yii/db/oci/index.md) › QueryBuilder

| class | `yii\db\oci\QueryBuilder` |
| --- | --- |
| Extends | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/db/oci/QueryBuilder.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/oci/QueryBuilder.php#L44) |

QueryBuilder is the query builder for Oracle databases (version 12.1 and above).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-db"></span>[`$db`](/docs/api/yii/db/querybuilder/index.md#property-db) | [`yii\db\Connection`](/docs/api/yii/db/connection/index.md) | The database connection. Default: `null`. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="property-separator"></span>[`$separator`](/docs/api/yii/db/querybuilder/index.md#property-separator) | `string` | The separator between different fragments of a SQL statement. Default: `' '`. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="property-typeMap"></span>`$typeMap` | `array` | Mapping from abstract column types (keys) to physical column types (values). Default: `[\yii\db\oci\Schema::TYPE_PK => 'NUMBER(10) GENERATED BY DEFAULT ON NULL AS IDENTITY NOT NULL PRIMARY KEY', \yii\db\oci\Schema::TYPE_UPK => 'NUMBER(10) GENERATED BY DEFAULT ON NULL AS IDENTITY NOT NULL PRIMARY KEY', \yii\db\oci\Schema::TYPE_BIGPK => 'NUMBER(20) GENERATED BY DEFAULT ON NULL AS IDENTITY NOT NULL PRIMARY KEY', \yii\db\oci\Schema::TYPE_UBIGPK => 'NUMBER(20) GENERATED BY DEFAULT ON NULL AS IDENTITY NOT NULL PRIMARY KEY', \yii\db\oci\Schema::TYPE_CHAR => 'CHAR(1)', \yii\db\oci\Schema::TYPE_STRING => 'VARCHAR2(255)', \yii\db\oci\Schema::TYPE_TEXT => 'CLOB', \yii\db\oci\Schema::TYPE_TINYINT => 'NUMBER(3)', \yii\db\oci\Schema::TYPE_SMALLINT => 'NUMBER(5)', \yii\db\oci\Schema::TYPE_INTEGER => 'NUMBER(10)', \yii\db\oci\Schema::TYPE_BIGINT => 'NUMBER(20)', \yii\db\oci\Schema::TYPE_FLOAT => 'NUMBER', \yii\db\oci\Schema::TYPE_DOUBLE => 'NUMBER', \yii\db\oci\Schema::TYPE_DECIMAL => 'NUMBER', \yii\db\oci\Schema::TYPE_DATETIME => 'TIMESTAMP', \yii\db\oci\Schema::TYPE_TIMESTAMP => 'TIMESTAMP', \yii\db\oci\Schema::TYPE_TIME => 'TIMESTAMP', \yii\db\oci\Schema::TYPE_DATE => 'DATE', \yii\db\oci\Schema::TYPE_BINARY => 'BLOB', \yii\db\oci\Schema::TYPE_BOOLEAN => 'NUMBER(1)', \yii\db\oci\Schema::TYPE_MONEY => 'NUMBER(19,4)']`. | `QueryBuilder` |
| <span id="property-conditionClasses"></span>[`$conditionClasses`](/docs/api/yii/db/querybuilder/index.md#property-conditionClasses) protected | `array` | Map of condition aliases to condition classes. Default: `[]`. Available since 2.0.14. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="property-expressionBuilders"></span>[`$expressionBuilders`](/docs/api/yii/db/querybuilder/index.md#property-expressionBuilders) protected | `string[]\|`[`yii\db\ExpressionBuilderInterface`](/docs/api/yii/db/expressionbuilderinterface/index.md)`[]` | Maps expression class to expression builder class. Default: `[]`. Available since 2.0.14. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/db/querybuilder/index.md#method-__construct) | Constructor. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-addCheck"></span>[`addCheck()`](/docs/api/yii/db/querybuilder/index.md#method-addCheck) | Creates a SQL command for adding a check constraint to an existing table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-addColumn"></span>[`addColumn()`](/docs/api/yii/db/querybuilder/index.md#method-addColumn) | Builds a SQL statement for adding a new DB column. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-addCommentOnColumn"></span>[`addCommentOnColumn()`](/docs/api/yii/db/querybuilder/index.md#method-addCommentOnColumn) | Builds a SQL command for adding comment to column. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-addCommentOnTable"></span>[`addCommentOnTable()`](/docs/api/yii/db/querybuilder/index.md#method-addCommentOnTable) | Builds a SQL command for adding comment to table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-addDefaultValue"></span>[`addDefaultValue()`](/docs/api/yii/db/querybuilder/index.md#method-addDefaultValue) | Creates a SQL command for adding a default value constraint to an existing table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`addForeignKey()`](#method-addForeignKey) | Builds a SQL statement for adding a foreign key constraint to an existing table. | `QueryBuilder` |
| <span id="method-addPrimaryKey"></span>[`addPrimaryKey()`](/docs/api/yii/db/querybuilder/index.md#method-addPrimaryKey) | Builds a SQL statement for adding a primary key constraint to an existing table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-addUnique"></span>[`addUnique()`](/docs/api/yii/db/querybuilder/index.md#method-addUnique) | Creates a SQL command for adding an unique constraint to an existing table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`alterColumn()`](#method-alterColumn) | Builds a SQL statement for changing the definition of a column. | `QueryBuilder` |
| [`batchInsert()`](#method-batchInsert) | Generates a batch INSERT SQL statement. | `QueryBuilder` |
| <span id="method-bindParam"></span>[`bindParam()`](/docs/api/yii/db/querybuilder/index.md#method-bindParam) | Helper method to add $value to $params array using [`PARAM_PREFIX`](/docs/api/yii/db/querybuilder/index.md#const-PARAM_PREFIX). | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-build"></span>[`build()`](/docs/api/yii/db/querybuilder/index.md#method-build) | Generates a SELECT SQL statement from a [`Query`](/docs/api/yii/db/query/index.md) object. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildColumns"></span>[`buildColumns()`](/docs/api/yii/db/querybuilder/index.md#method-buildColumns) | Processes columns and properly quotes them if necessary. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildCondition"></span>[`buildCondition()`](/docs/api/yii/db/querybuilder/index.md#method-buildCondition) | Parses the condition specification and generates the corresponding SQL expression. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildExpression"></span>[`buildExpression()`](/docs/api/yii/db/querybuilder/index.md#method-buildExpression) | Builds given $expression | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildFrom"></span>[`buildFrom()`](/docs/api/yii/db/querybuilder/index.md#method-buildFrom) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildGroupBy"></span>[`buildGroupBy()`](/docs/api/yii/db/querybuilder/index.md#method-buildGroupBy) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildHaving"></span>[`buildHaving()`](/docs/api/yii/db/querybuilder/index.md#method-buildHaving) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildJoin"></span>[`buildJoin()`](/docs/api/yii/db/querybuilder/index.md#method-buildJoin) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildLimit"></span>[`buildLimit()`](/docs/api/yii/db/querybuilder/index.md#method-buildLimit) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildOrderBy"></span>[`buildOrderBy()`](/docs/api/yii/db/querybuilder/index.md#method-buildOrderBy) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`buildOrderByAndLimit()`](#method-buildOrderByAndLimit) | Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL. | `QueryBuilder` |
| <span id="method-buildSelect"></span>[`buildSelect()`](/docs/api/yii/db/querybuilder/index.md#method-buildSelect) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildUnion"></span>[`buildUnion()`](/docs/api/yii/db/querybuilder/index.md#method-buildUnion) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildUnionOrderByAndLimit"></span>[`buildUnionOrderByAndLimit()`](/docs/api/yii/db/querybuilder/index.md#method-buildUnionOrderByAndLimit) | Builds the global ORDER BY and LIMIT/OFFSET clauses for a UNION query. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildWhere"></span>[`buildWhere()`](/docs/api/yii/db/querybuilder/index.md#method-buildWhere) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`buildWithQueries()`](#method-buildWithQueries) |  | `QueryBuilder` |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-checkIntegrity"></span>[`checkIntegrity()`](/docs/api/yii/db/querybuilder/index.md#method-checkIntegrity) | Builds a SQL statement for enabling or disabling integrity check. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-createConditionFromArray"></span>[`createConditionFromArray()`](/docs/api/yii/db/querybuilder/index.md#method-createConditionFromArray) | Transforms $condition defined in array format (as described in [`Query::where()`](/docs/api/yii/db/query/index.md#method-where) to instance of ConditionInterface according to [`$conditionClasses`](/docs/api/yii/db/querybuilder/index.md#property-conditionClasses) map. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-createIndex"></span>[`createIndex()`](/docs/api/yii/db/querybuilder/index.md#method-createIndex) | Builds a SQL statement for creating a new index. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-createTable"></span>[`createTable()`](/docs/api/yii/db/querybuilder/index.md#method-createTable) | Builds a SQL statement for creating a new DB table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-createView"></span>[`createView()`](/docs/api/yii/db/querybuilder/index.md#method-createView) | Creates a SQL View. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-delete"></span>[`delete()`](/docs/api/yii/db/querybuilder/index.md#method-delete) | Creates a DELETE SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-dropCheck"></span>[`dropCheck()`](/docs/api/yii/db/querybuilder/index.md#method-dropCheck) | Creates a SQL command for dropping a check constraint. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-dropColumn"></span>[`dropColumn()`](/docs/api/yii/db/querybuilder/index.md#method-dropColumn) | Builds a SQL statement for dropping a DB column. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`dropCommentFromColumn()`](#method-dropCommentFromColumn) | Builds a SQL command for adding comment to column. | `QueryBuilder` |
| [`dropCommentFromTable()`](#method-dropCommentFromTable) | Builds a SQL command for adding comment to table. | `QueryBuilder` |
| <span id="method-dropDefaultValue"></span>[`dropDefaultValue()`](/docs/api/yii/db/querybuilder/index.md#method-dropDefaultValue) | Creates a SQL command for dropping a default value constraint. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-dropForeignKey"></span>[`dropForeignKey()`](/docs/api/yii/db/querybuilder/index.md#method-dropForeignKey) | Builds a SQL statement for dropping a foreign key constraint. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`dropIndex()`](#method-dropIndex) | Builds a SQL statement for dropping an index. | `QueryBuilder` |
| <span id="method-dropPrimaryKey"></span>[`dropPrimaryKey()`](/docs/api/yii/db/querybuilder/index.md#method-dropPrimaryKey) | Builds a SQL statement for removing a primary key constraint to an existing table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-dropTable"></span>[`dropTable()`](/docs/api/yii/db/querybuilder/index.md#method-dropTable) | Builds a SQL statement for dropping a DB table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-dropUnique"></span>[`dropUnique()`](/docs/api/yii/db/querybuilder/index.md#method-dropUnique) | Creates a SQL command for dropping an unique constraint. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-dropView"></span>[`dropView()`](/docs/api/yii/db/querybuilder/index.md#method-dropView) | Drops a SQL View. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`executeResetSequence()`](#method-executeResetSequence) | Execute a SQL statement for resetting the sequence value of a table's primary key. | `QueryBuilder` |
| <span id="method-getColumnType"></span>[`getColumnType()`](/docs/api/yii/db/querybuilder/index.md#method-getColumnType) | Converts an abstract column type into a physical column type. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-getExpressionBuilder"></span>[`getExpressionBuilder()`](/docs/api/yii/db/querybuilder/index.md#method-getExpressionBuilder) | Gets object of [`ExpressionBuilderInterface`](/docs/api/yii/db/expressionbuilderinterface/index.md) that is suitable for $expression. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/db/querybuilder/index.md#method-init) | Initializes the object. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`insert()`](#method-insert) | Creates an INSERT SQL statement. | `QueryBuilder` |
| [`mergeReturning()`](#method-mergeReturning) | Appends a `RETURNING` clause for the given OUT placeholders, merging any locator clause already present. | `QueryBuilder` |
| <span id="method-renameColumn"></span>[`renameColumn()`](/docs/api/yii/db/querybuilder/index.md#method-renameColumn) | Builds a SQL statement for renaming a column. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`renameTable()`](#method-renameTable) | Builds a SQL statement for renaming a DB table. | `QueryBuilder` |
| <span id="method-resetSequence"></span>[`resetSequence()`](/docs/api/yii/db/querybuilder/index.md#method-resetSequence) | Creates a SQL statement for resetting the sequence value of a table's primary key. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`selectExists()`](#method-selectExists) | Creates a SELECT EXISTS() SQL statement. | `QueryBuilder` |
| <span id="method-setConditionClasses"></span>[`setConditionClasses()`](/docs/api/yii/db/querybuilder/index.md#method-setConditionClasses) | Setter for [`$conditionClasses`](/docs/api/yii/db/querybuilder/index.md#property-conditionClasses) property. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-setExpressionBuilders"></span>[`setExpressionBuilders()`](/docs/api/yii/db/querybuilder/index.md#method-setExpressionBuilders) | Setter for [`$expressionBuilders`](/docs/api/yii/db/querybuilder/index.md#property-expressionBuilders) property. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-truncateTable"></span>[`truncateTable()`](/docs/api/yii/db/querybuilder/index.md#method-truncateTable) | Builds a SQL statement for truncating a DB table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`update()`](#method-update) | Creates an UPDATE SQL statement. | `QueryBuilder` |
| [`upsert()`](#method-upsert) | Creates an SQL statement to insert rows into a database table if they do not already exist (matching unique constraints), or update them if they do. | `QueryBuilder` |
| <span id="method-concatUnionSql"></span>[`concatUnionSql()`](/docs/api/yii/db/querybuilder/index.md#method-concatUnionSql) protected | Concatenates the first `SELECT` statement with the UNION clauses built by [`buildUnion()`](/docs/api/yii/db/querybuilder/index.md#method-buildUnion). | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-defaultConditionClasses"></span>[`defaultConditionClasses()`](/docs/api/yii/db/querybuilder/index.md#method-defaultConditionClasses) protected | Contains array of default condition classes. Extend this method, if you want to change default condition classes for the query builder. See [`$conditionClasses`](/docs/api/yii/db/querybuilder/index.md#property-conditionClasses) docs for details. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`defaultExpressionBuilders()`](#method-defaultExpressionBuilders) protected | Contains array of default expression builders. Extend this method and override it, if you want to change default expression builders for this query builder. See [`$expressionBuilders`](/docs/api/yii/db/querybuilder/index.md#property-expressionBuilders) docs for details. | `QueryBuilder` |
| <span id="method-extractAlias"></span>[`extractAlias()`](/docs/api/yii/db/querybuilder/index.md#method-extractAlias) protected | Extracts table alias if there is one or returns false | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-hasLimit"></span>[`hasLimit()`](/docs/api/yii/db/querybuilder/index.md#method-hasLimit) protected | Checks to see if the given limit is effective. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-hasOffset"></span>[`hasOffset()`](/docs/api/yii/db/querybuilder/index.md#method-hasOffset) protected | Checks to see if the given offset is effective. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareInsertSelectSubQuery"></span>[`prepareInsertSelectSubQuery()`](/docs/api/yii/db/querybuilder/index.md#method-prepareInsertSelectSubQuery) protected | Prepare select-subquery and field names for INSERT INTO ... SELECT SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`prepareInsertValues()`](#method-prepareInsertValues) protected | Prepares a `VALUES` part for an `INSERT` SQL statement. | `QueryBuilder` |
| <span id="method-prepareSelectQuery"></span>[`prepareSelectQuery()`](/docs/api/yii/db/querybuilder/index.md#method-prepareSelectQuery) protected | Performs driver-specific preparation after [`Query::prepare()`](/docs/api/yii/db/query/index.md#method-prepare). | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareUpdateSets"></span>[`prepareUpdateSets()`](/docs/api/yii/db/querybuilder/index.md#method-prepareUpdateSets) protected | Prepares a `SET` parts for an `UPDATE` SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareUpsertColumns"></span>[`prepareUpsertColumns()`](/docs/api/yii/db/querybuilder/index.md#method-prepareUpsertColumns) protected |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareUpsertSets"></span>[`prepareUpsertSets()`](/docs/api/yii/db/querybuilder/index.md#method-prepareUpsertSets) protected | Prepares the `SET` assignments for the update branch of an upsert statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-UPSERT_AFFECTED_PARAM_PREFIX"></span>`UPSERT_AFFECTED_PARAM_PREFIX` | `':yii_upsert_affected'` | Parameter name prefix for the affected-row OUT bind registered by a `BLOB` upsert. | `QueryBuilder` |
| <span id="const-PARAM_PREFIX"></span>[`PARAM_PREFIX`](/docs/api/yii/db/querybuilder/index.md#const-PARAM_PREFIX) | `':qp'` | The prefix for automatically generated query binding parameters. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |

## Method details

### addForeignKey() <span id="method-addForeignKey"></span>

```php
public function addForeignKey(mixed $name, mixed $table, mixed $columns, mixed $refTable, mixed $refColumns, mixed $delete = null, mixed $update = null): string
```

Builds a SQL statement for adding a foreign key constraint to an existing table.

The method will properly quote the table and column names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the foreign key constraint. |
| `$table` | `mixed` | The table that the foreign key constraint will be added to. |
| `$columns` | `mixed` | The name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or use an array to represent them. |
| `$refTable` | `mixed` | The table that the foreign key references to. |
| `$refColumns` | `mixed` | The name of the column that the foreign key references to. If there are multiple columns, separate them with commas or use an array to represent them. |
| `$delete` | `mixed` | The ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL |
| `$update` | `mixed` | The ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL |

**Returns**

`string`: The SQL statement for adding a foreign key constraint to an existing table.

### alterColumn() <span id="method-alterColumn"></span>

```php
public function alterColumn(string $table, string $column, string $type): string
```

Builds a SQL statement for changing the definition of a column.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `string` | The table whose column is to be changed. The table name will be properly quoted by the method. |
| `$column` | `string` | The name of the column to be changed. The name will be properly quoted by the method. |
| `$type` | `string` | The new column type. The [`getColumnType()`](/docs/api/yii/db/querybuilder/index.md#method-getColumnType) method will be invoked to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'. |

**Returns**

`string`: The SQL statement for changing the definition of a column.

### batchInsert() <span id="method-batchInsert"></span>

```php
public function batchInsert(string $table, array $columns, array|Generator $rows, array &$params = []): string
```

Generates a batch INSERT SQL statement.

For example,

```
$sql = $queryBuilder->batchInsert('user', ['name', 'age'], [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
]);
```

Note that the values in each row must match the corresponding column names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `string` | The table that new rows will be inserted into. |
| `$columns` | `array` | The column names. |
| `$rows` | `array\|`[`Generator`](https://www.php.net/manual/en/class.generator.php) | The rows to be batch inserted into the table. |
| `$params` | `array` | The parameters to be bound to the batch INSERT SQL statement. This parameter is passed by reference and will be modified by this method. |

**Returns**

`string`: The batch INSERT SQL statement.

### buildOrderByAndLimit() <span id="method-buildOrderByAndLimit"></span>

```php
public function buildOrderByAndLimit(mixed $sql, mixed $orderBy, mixed $limit, mixed $offset): string
```

Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$sql` | `mixed` | The existing SQL (without ORDER BY/LIMIT/OFFSET) |
| `$orderBy` | `mixed` | The order by columns. See [`Query::orderBy()`](/docs/api/yii/db/querytrait/index.md#method-orderBy) for more details on how to specify this parameter. |
| `$limit` | `mixed` | The limit number. See [`Query::limit()`](/docs/api/yii/db/querytrait/index.md#method-limit) for more details. |
| `$offset` | `mixed` | The offset number. See [`Query::offset()`](/docs/api/yii/db/querytrait/index.md#method-offset) for more details. |

**Returns**

`string`: The SQL completed with ORDER BY/LIMIT/OFFSET (if any)

### buildWithQueries() <span id="method-buildWithQueries"></span>

```php
public function buildWithQueries(mixed $withs, mixed &$params): string
```

Oracle does not support the `RECURSIVE` keyword for CTEs. Recursion is implicit when a CTE references itself.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$withs` | `mixed` | Of configurations for each WITH query |
| `$params` | `mixed` | The binding parameters to be populated |

**Returns**

`string`: Compiled WITH prefix of query including nested queries

**Since**

2.0.35

### dropCommentFromColumn() <span id="method-dropCommentFromColumn"></span>

```php
public function dropCommentFromColumn(mixed $table, mixed $column): string
```

Builds a SQL command for adding comment to column.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table whose column is to be commented. The table name will be properly quoted by the method. |
| `$column` | `mixed` | The name of the column to be commented. The column name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for adding comment on column

**Since**

2.0.8

### dropCommentFromTable() <span id="method-dropCommentFromTable"></span>

```php
public function dropCommentFromTable(mixed $table): string
```

Builds a SQL command for adding comment to table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table whose column is to be commented. The table name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for adding comment on column

**Since**

2.0.8

### dropIndex() <span id="method-dropIndex"></span>

```php
public function dropIndex(string $name, string $table): string
```

Builds a SQL statement for dropping an index.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the index to be dropped. The name will be properly quoted by the method. |
| `$table` | `string` | The table whose index is to be dropped. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for dropping an index.

### executeResetSequence() <span id="method-executeResetSequence"></span>

```php
public function executeResetSequence(mixed $table, mixed $value = null): mixed
```

Execute a SQL statement for resetting the sequence value of a table's primary key.

`IDENTITY` columns reset via `ALTER TABLE ... MODIFY` because system sequences (`ISEQ$$_*`) are not addressable
by name.

The column's current generation clause is read from the data dictionary and preserved when resetting the
identity; Oracle retains the identity options the statement does not specify. User-named sequences use the
original `DROP` + `CREATE` recipe.

Reason for execute is that some databases (Oracle) need several queries to do so.

The sequence is reset such that the primary key of the next new row inserted will have the specified value or the
maximum existing value `+1`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The name of the table whose primary key sequence is reset. |
| `$value` | `mixed` | The integer value for the primary key of the next new row inserted. If this is not set, the next new row's primary key will have the maximum existing value `+1`. |

**Returns**

`mixed`

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this is not supported by the underlying DBMS

**Since**

2.0.16

### insert() <span id="method-insert"></span>

```php
public function insert(mixed $table, mixed $columns, mixed &$params): string
```

Creates an INSERT SQL statement.

Appends the locator `RETURNING` clause required by Oracle `BLOB` values.

For example,
```
$sql = $queryBuilder->insert('user', [
    'name' => 'Sam',
    'age' => 30,
], $params);
```
The method will properly escape the table and column names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table that new rows will be inserted into. |
| `$columns` | `mixed` | The column data (name => value) to be inserted into the table or instance of [Query](/docs/api/yii/db/query/index.md) to perform INSERT INTO ... SELECT SQL statement. Passing of [Query](/docs/api/yii/db/query/index.md) is available since version 2.0.11. |
| `$params` | `mixed` | The binding parameters that will be generated by this method. They should be bound to the DB command later. |

**Returns**

`string`: The INSERT SQL

### mergeReturning() <span id="method-mergeReturning"></span>

```php
public function mergeReturning(string $sql, array $params, array<string, string> $placeholders): string
```

Appends a `RETURNING` clause for the given OUT placeholders, merging any locator clause already present.

A DML statement built by [`insert()`](/docs/api/yii/db/oci/querybuilder/index.md#method-insert) or [`update()`](/docs/api/yii/db/oci/querybuilder/index.md#method-update) may already end with a locator `RETURNING`
clause; its entries fold into the new clause because Oracle allows a single `RETURNING` clause per statement.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$sql` | `string` | DML statement built by this query builder. |
| `$params` | `array` | The parameters bound to the SQL statement. |
| `$placeholders` | `array<string, string>` | OUT placeholders indexed by unquoted column name. |

**Returns**

`string`: The SQL statement with the merged `RETURNING` clause.

### renameTable() <span id="method-renameTable"></span>

```php
public function renameTable(string $table, string $newName): string
```

Builds a SQL statement for renaming a DB table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `string` | The table to be renamed. The name will be properly quoted by the method. |
| `$newName` | `string` | The new table name. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for renaming a DB table.

### selectExists() <span id="method-selectExists"></span>

```php
public function selectExists(mixed $rawSql): string
```

Creates a SELECT EXISTS() SQL statement.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rawSql` | `mixed` | The subquery in a raw form to select from. |

**Returns**

`string`: The SELECT EXISTS() SQL statement.

**Since**

2.0.8

### update() <span id="method-update"></span>

```php
public function update(mixed $table, mixed $columns, mixed $condition, mixed &$params): string
```

Creates an UPDATE SQL statement.

Oracle BLOB updates require a condition that guarantees at most one matched row.

For example,

```
$params = [];
$sql = $queryBuilder->update('user', ['status' => 1], 'age > 30', $params);
```

The method will properly escape the table and column names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table to be updated. |
| `$columns` | `mixed` | The column data (name => value) to be updated. |
| `$condition` | `mixed` | The condition that will be put in the WHERE part. Please refer to [`Query::where()`](/docs/api/yii/db/query/index.md#method-where) on how to specify condition. |
| `$params` | `mixed` | The binding parameters that will be modified by this method so that they can be bound to the DB command later. |

**Returns**

`string`: The UPDATE SQL

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if the condition does not cover a unique key using non-null scalar values.

### upsert() <span id="method-upsert"></span>

```php
public function upsert(mixed $table, mixed $insertColumns, mixed $updateColumns, mixed &$params): string
```

Creates an SQL statement to insert rows into a database table if
they do not already exist (matching unique constraints),
or update them if they do.

A `BLOB` value routes to a single anonymous PL/SQL block through [`upsertWithLob()`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/oci/QueryBuilder.php#L800), because Oracle `MERGE`
cannot return the LOB locators the payload binds require; every other case builds the regular `MERGE`.

For example,

```
$sql = $queryBuilder->upsert('pages', [
    'name' => 'Front page',
    'url' => 'https://example.com/', // url is unique
    'visits' => 0,
], [
    'visits' => new \yii\db\Expression('visits + 1'),
], $params);
```

The method will properly escape the table and column names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table that new rows will be inserted into/updated in. |
| `$insertColumns` | `mixed` | The column data (name => value) to be inserted into the table or instance of [`Query`](/docs/api/yii/db/query/index.md) to perform `INSERT INTO ... SELECT` SQL statement. |
| `$updateColumns` | `mixed` | The column data (name => value) to be updated if they already exist. If `true` is passed, the column data will be updated to match the insert column data. If `false` is passed, no update will be performed if the column data already exists. |
| `$params` | `mixed` | The binding parameters that will be generated by this method. They should be bound to the DB command later. |

**Returns**

`string`: The resulting SQL.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this is not supported by the underlying DBMS.

**Since**

2.0.14

**See also**

- <https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606>

### defaultExpressionBuilders() <span id="method-defaultExpressionBuilders"></span>

```php
protected function defaultExpressionBuilders(): array
```

Contains array of default expression builders. Extend this method and override it, if you want to change
default expression builders for this query builder. See [`$expressionBuilders`](/docs/api/yii/db/querybuilder/index.md#property-expressionBuilders) docs for details.

**Returns**

`array`

**Since**

2.0.14

### prepareInsertValues() <span id="method-prepareInsertValues"></span>

```php
protected function prepareInsertValues(mixed $table, mixed $columns, mixed $params = []): array
```

Prepares a `VALUES` part for an `INSERT` SQL statement.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table that new rows will be inserted into. |
| `$columns` | `mixed` | The column data (name => value) to be inserted into the table or instance of [Query](/docs/api/yii/db/query/index.md) to perform INSERT INTO ... SELECT SQL statement. |
| `$params` | `mixed` | The binding parameters that will be generated by this method. They should be bound to the DB command later. |

**Returns**

`array`: Array of column names, placeholders, values and params.

**Since**

2.0.14