19

我想知道是否可以在 SQlite 中连接和添加空格。这就是我的意思:

SELECT NAME || SURNAME AS USER_NAME FROM USERS

但随后在查询中添加一些内容以使结果显示为:

Name Surname

并不是

NameSurname

在 SQlite 中是否有可能发生这样的事情?

4

2 回答 2

33

Concat 也是空间:

SELECT NAME || ' ' || SURNAME AS USER_NAME FROM USERS
于 2013-07-15T14:03:25.570 回答
6

A hack in PHP when using Laravel. It adds the concat() functionality by having SQLite call back to PHP. For example you add it to your PhpUnit script.

The second line gets the \PDO handle, if you don't use Laravel, replace it with your way of getting the handle.

        /** @var \Illuminate\Database\Connection $connection */
        $connection = DB::connection();
        $dbHandle = $connection->getPdo();

        // Add MySQL concat() support to SQLite
        if ('sqlite' === $dbHandle->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
            $dbHandle->sqliteCreateFunction(
                'concat',
                function (...$input) {
                    return implode('', $input);
                }
            );
        }

Other SQLite libraries in PHP have a similar sqliteCreateFunction().

于 2020-01-09T13:56:29.927 回答