从SQL结果创建逗号分隔字符串 [英] Create a comma seprated string from SQL result

查看:70
本文介绍了从SQL结果创建逗号分隔字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数据

I have a data like this

 ID         ITEM NO
45824587	  2545654
32589662      5878985
11414252      2145477
25789632      2458926





我想分配一个字符指针并希望存储结果使用逗号如



I want to allocate a char pointer and want to store the result using comma like

char *ptr = 45824587,32589662,11414252,25789632;2545654,5878985,2145477,2458926





请给我提供代码



Please provide me with the code

推荐答案

它不是那样的工作。

我们不为你工作。

如果你想让别人写你的代码,你必须付钱 - 我建议你去Freelancer.com并在那里问。



但是要阿瓦re:你得到你付出的代价。支付花生,获得猴子。
It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys.


使用 C ++ 可以让您的生活更轻松。

如果你必须使用 C 那么你必须(静态地或动态地)分配一个足够大的缓冲区(字符数组)来保存你的逗号 - 分开的值。然后你必须使用获取的结果构建逗号分隔值(不知道你实际上将如何获取数据库结果,我们无法帮助更多)。
Using C++ would make your life easier.
If you have to use C then you must allocate (either statically or dynamically) a big enough buffer (character array) for holding your comma-separated values. Then you have to build the comma-separated values using the fetched result (without knowing how are you actually going to fetch the database results, we cannot help more).


在C中,你可以在循环中使用'sprintf'。首先需要分配足够大小的字符数组(比如ptr)并使用第一条记录的值初始化它。然后在循环内执行以下操作,



In C, you may use 'sprintf' inside a loop. You first need to allocate a character array(say ptr) of enough size and initialize it with the value of the first record. Then inside a loop do the following,

sprintf(ptr, "%s, %s", ptr, nextValue);


这篇关于从SQL结果创建逗号分隔字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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