如何格式化sqlite选择输出?

How to format sqlite select output?(如何格式化sqlite选择输出?)
本文介绍了如何格式化sqlite选择输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个简单的 SQLite 数据库.一个带有键和名称以及描述列的表.我希望能够格式化数据,以便我可以在 html 选择下拉列表中使用它.这是我尝试过的众多事情之一......

I have a simple SQLite DB. One table with a key and name and a description columns. I want to be able to format the data so I can use it in a html select pulldown. Here's one of the many things I have tried ...

sqlite> select * from ppt_branch;
1|smellopment|where everything sucks all the time
2|development|just a mess
3|stage|all the world's a stage
4|production|DO NOT TOUCH IT!
sqlite> select '<option value=' ppt_branch_id '>' from ppt_branch ;
SQL error: near "'>'": syntax error
sqlite> 

...但正如你所看到的那样是不对的.我希望输出像......

... but as you can see that is not right. I was hoping for output like ...

   <option value='1'>smellopment</option>
   <option value='2'>development</option>
   <option value='3'>stage</option>
   <option value='4'>production</option>

...但我什至不接近.谁能帮帮我?

... but I am not even close. Can anyone help me out?

推荐答案

好吧,您的语言应该捕获该查询结果并根据需要对其进行格式化.当您干净利落地编写软件(MVC 方法)时,您不要混合数据和格式.这不仅仅是为了有一天非网络部署的可能性,它主要是为了以专门的逻辑结构组织您的工作:一个用于数据,一个用于控制,一个用于查看.

Well, your language should catch that query result and format it as you want. When you write software cleanly (MVC approach), you don't mix data and formatting. It's not just for the possibility of non-web deployment one day, it's primarily to organize your work in specialized logical structures: one for data, one for control, one for viewing.

但这是使用文字的方法.你很接近,你只需要连接:

But here's the way to do it with literals. You were close, you just needed concatenation:

SELECT '<option value=''' || ppt_branch_id || '''>' || ppt_branch_name || '</option>' 
FROM ppt_branch;

这篇关于如何格式化sqlite选择输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Insert multiple rows, count based on another table columns(插入多行,根据另一个表列计数)
How to send to email (outlook) the selected items in SQL Server database using vb.net(如何使用 vb.net 将 SQL Server 数据库中的选定项目发送到电子邮件(Outlook))
DBCC CheckDb-any ways to detect errors vb.net?(DBCC CheckDb-vb.net 有什么检测错误的方法吗?)
Dynamic SQL generation is not supported against multiple base tables in WinForms(WinForms 中的多个基表不支持动态 SQL 生成)
Using a string which comprises of values in a query(使用由查询中的值组成的字符串)
Connect to MS SQL Server 2014 from a computer on a different network(从不同网络上的计算机连接到 MS SQL Server 2014)