0 follower

Final Class Yiisoft\Db\Oracle\Builder\LongestBuilder

InheritanceYiisoft\Db\Oracle\Builder\LongestBuilder » Yiisoft\Db\Expression\Function\Builder\MultiOperandFunctionBuilder

Builds SQL representation of function expressions which returns the longest string from a set of operands.

(SELECT value FROM (
    SELECT operand1 AS value FROM DUAL
    UNION
    SELECT operand2 AS value FROM DUAL
) ORDER BY LENGTH(value) DESC FETCH FIRST 1 ROWS ONLY)

Protected Methods

Hide inherited methods

Method Description Defined By
buildFromExpression() Builds a SQL expression to represent the function which returns the longest string. Yiisoft\Db\Oracle\Builder\LongestBuilder

Method Details

Hide inherited methods

buildFromExpression() protected method

Builds a SQL expression to represent the function which returns the longest string.

protected string buildFromExpression ( \Yiisoft\Db\Expression\Function\Greatest $expression, array &$params )
$expression \Yiisoft\Db\Expression\Function\Greatest

The expression to build.

$params array

The parameters to bind.

return string

The SQL expression.

                protected function buildFromExpression(MultiOperandFunction $expression, array &$params): string
{
    $selects = [];
    foreach ($expression->getOperands() as $operand) {
        $selects[] = 'SELECT ' . $this->buildOperand($operand, $params) . ' AS value FROM DUAL';
    }
    $unions = implode(' UNION ', $selects);
    return "(SELECT value FROM ($unions) ORDER BY LENGTH(value) DESC FETCH FIRST 1 ROWS ONLY)";
}