2006年12月17日 星期日 19:44
import sqlite3
conn=sqlite3.connect('db.dat')
cur=conn.cursor()
cur.execute("select * from info where title like '%安静舒适%'")
rs=cur.fetchone()
>>> rs==None
True
我确定数据库中有含有"安静舒适"的字段,为什么不行呢?
在sqlite3中实现模糊查询用哪个词?
请指教!!
2006年12月17日 星期日 20:25
变成 unicode 值试试
junyi sun wrote::
> import sqlite3
> conn=sqlite3.connect('db.dat')
> cur=conn.cursor()
> cur.execute("select * from info where title like '%安静舒适%'")
> rs=cur.fetchone()
>
>>>> rs==None
> True
>
> 我确定数据库中有含有"安静舒适"的字段,为什么不行呢?
> 在sqlite3中实现模糊查询用哪个词?
>
> 请指教!!
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
--
Vim 中文 Google 论坛 http://groups.google.com/group/Vim-cn
2006年12月17日 星期日 21:01
谢谢楼上: 我找到原因了,因为百分号在python中有特殊语意,所以不能按照一般方法 用chr(37)代替%即可。 注:%的ascii码是37 On 12/17/06, tocer <tocer.deng在gmail.com> wrote: > 变成 unicode 值试试 > > junyi sun wrote:: > > import sqlite3 > > conn=sqlite3.connect('db.dat') > > cur=conn.cursor() > > cur.execute("select * from info where title like '%安静舒适%'") > > rs=cur.fetchone() > > > >>>> rs==None > > True > > > > 我确定数据库中有含有"安静舒适"的字段,为什么不行呢? > > 在sqlite3中实现模糊查询用哪个词? > > > > 请指教!! > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -- > Vim 中文 Google 论坛 http://groups.google.com/group/Vim-cn > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese
2006年12月17日 星期日 22:21
>
> import sqlite3
> conn=sqlite3.connect('db.dat')
> cur=conn.cursor()
> cur.execute("select * from info where title like '%安静舒适%'")
> rs=cur.fetchone()
>
> >>> rs==None
> True
>
> 我确定数据库中有含有"安静舒适"的字段,为什么不行呢?
> 在sqlite3中实现模糊查询用哪个词?
>
> 请指教!!
这才是标准形式:
cur.execute("select * from info where title like %s", ['%安静舒适%'])
或者
cur.execute("select * from info where title like '%%安静舒适%%'")
估计是这样的,我自己也还没有试过。
谢谢楼上:
> 我找到原因了,因为百分号在python中有特殊语意,所以不能按照一般方法
> 用chr(37)代替%即可。
>
普通字符串中 % 并没有特殊意义,只有在进行格式化的时候才特殊用。
--
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20061217/0cbeb49c/attachment.html
Zeuux © 2025
京ICP备05028076号