31
A
回答
37
SQLite沒有存儲的函數/存儲過程語言。所以CREATE FUNCTION
不起作用。你可以做的是從c庫到SQL函數(用戶定義函數)的映射函數。要做到這一點,使用SQLite的C API(參見:http://www.sqlite.org/c3ref/create_function.html)
如果你不使用C API,你的封裝API可以定義的東西,可以讓你訪問該功能,例如參見:
- PHP
sqlite_create_function()
(http://www.php.net/manual/en/function.sqlite-create-function.php) - 的Python
sqlite3.create_function()
(http://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.create_function) - 的Perl
$dbh->func(_$name,_$argc,_$func_ref,_"create_function")
(https://metacpan.org/pod/DBD::SQLite#dbh-sqlite_create_function-name-argc-code_ref)
0
這可能對很多人有用:在SQLiteStudio可以通過一個SQL內置插件輕鬆地定義新的函數和排序規則。
https://github.com/pawelsalawa/sqlitestudio/wiki/Official_plugins#sql-built-in
通過函數編輯器。
@Andrew:由於您提到了MSSQL,您可能有興趣知道使用.NET的System.Data.SQLite提供程序很容易在任何CLR語言中實現SQLite UDF。 http://sqlite.phxsoftware.com/ – Tim 2011-09-16 15:44:15
如果你像這個答案中提到的那樣映射一個用戶定義的函數,它是否保留在sqlite數據庫中,或者每次加載數據庫時都必須映射它嗎? – ThinkBonobo 2014-02-06 15:21:13
好問題。我想你可能不得不重新映射。 – 2014-02-15 15:56:48