如何在 SQLite 中创建自定义函数 [英] How to create custom functions in SQLite

查看:105
本文介绍了如何在 SQLite 中创建自定义函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能像在 MSSQL 中一样在 SQLite 中创建函数吗?

Can you create functions in SQLite like you can in MSSQL?

如果是这样,怎么办?什么是语法?

If so, how? What is the syntax?

谢谢

推荐答案

SQLite 没有存储函数/存储过程语言.所以 CREATE FUNCTION 不起作用.您可以做的是将函数从 c 库映射到 SQL 函数(用户定义的函数).为此,请使用 SQLite 的 C API(请参阅:http://www.sqlite.org/c3ref/create_function.html)

SQLite does not have a stored function/stored procedure language. So CREATE FUNCTION does not work. What you can do though is map functions from a c library to SQL functions (user-defined functions). To do that, use SQLite's C API (see: http://www.sqlite.org/c3ref/create_function.html)

如果您不使用 C API,您的包装器 API 可能会定义一些允许您访问此功能的内容,例如:

If you're not using the C API, your wrapper API may define something that allows you access to this feature, see for example:

  • PHP sqlite_create_function() (http://www.php.net/manual/en/function.sqlite-create-function.php)
  • Python sqlite3.create_function() (http://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function)
  • Perl $dbh->sqlite_create_function($name,$argc,$code_ref,$flags) (https://metacpan.org/pod/DBD::SQLite#$dbh-%3Esqlite_create_function(-$name,-$argc,-$code_ref,-$flags-))

这篇关于如何在 SQLite 中创建自定义函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆