mysql 获取数组长度
时间: 2023-10-16 20:03:51 浏览: 187
php中处理mysql_fetch_assoc返回来的数组 不用foreach----echo
要在MySQL中获取数组长度,可以使用函数mysql_fetch_lengths()。这个函数返回结果集的当前行的每一列的数据长度。但是要注意,在调用mysql_fetch_row()之前或在检索结果集中的所有行之后调用mysql_fetch_lengths()将返回NULL。下面是一个示例代码:
```
MYSQL_ROW row;
unsigned long *lengths;
unsigned int num_fields;
unsigned int i;
row = mysql_fetch_row(result);
if (row) {
num_fields = mysql_num_fields(result);
lengths = mysql_fetch_lengths(result);
for(i = 0; i < num_fields; i++) {
printf("Column %u is %lu bytes in length.\n", i, lengths[i]);
}
}
```
引用解释了如何使用mysql_fetch_lengths()函数来获取数据长度。引用提到了在转换Oracle SQL到MySQL时可能遇到的问题,因为MySQL没有像Oracle那样的自定义数组。所以你可能需要根据具体情况自己进行调整和修改。引用提供了一个函数Get_StrArrayLength来计算字符串数组的长度,你可以根据自己的需求进行实现和调用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [mysql_fetch_lengths()获得结果集的数据长度](https://blog.csdn.net/suhiymof/article/details/53762238)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [mysql 自定义函数计算类java,求数组字符串长度(亲测可用)](https://blog.csdn.net/IT_Octopus/article/details/107205019)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文