如何在SQLite中模拟REPEAT() [英] How to simulate REPEAT() in SQLite

查看:134
本文介绍了如何在SQLite中模拟REPEAT()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数关系型数据库都有某种 REPEAT()字符串函数,例如:

  SELECT REPEAT('abc',3)

会收益

  abcabcabc 

SQLite另一方面有一个非常有限的功能集。这里列出了SQLite支持的功能:



http ://www.sqlite.org/lang_corefunc.html



可以模拟 REPEAT()在SQLite中可用的功能?

解决方案

解决方案的灵感来源于这个答案,

如何模拟LPAD / RPAD SQLite



我想在Stack Overflow上分享它,因为这可能对其他SQLite用户有用。解决方案如下:

   -  X =字符串
- Y =重复次数

replace(substr(quote(zeroblob((Y + 1)/ 2)),3,Y),'0',X)


Most relational databases have some sort of REPEAT() string function, for instance:

SELECT REPEAT('abc', 3)

Would yield

abcabcabc

SQLite on the other hand has a very limited feature set. The functions supported by SQLite are listed here:

http://www.sqlite.org/lang_corefunc.html

Can REPEAT() be simulated with the functions available in SQLite?

解决方案

A solution was inspired by this answer to a related question, here:

How to simulate LPAD/RPAD with SQLite

I wanted to share this on Stack Overflow, as this may be useful to other SQLite users. The solution goes like this:

-- X = string
-- Y = number of repetitions

replace(substr(quote(zeroblob((Y + 1) / 2)), 3, Y), '0', X)

这篇关于如何在SQLite中模拟REPEAT()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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