desc tablename
然后总行数就是你的字段数。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mysql>desc ysks
+-------+---------------+-----
| Field | Type | Null
+-------+---------------+-----
| 单号 | int(11) | YES
| 金额 | decimal(10,2) | YES
| 已收 | decimal(10,2) | YES
| 日期 | bigint(20)| YES
| 名称 | varchar(10) | YES
| 余额 | decimal(10,2) | YES
| 备注 | varchar(10) | YES
| 品名 | varchar(10) | YES
+-------+---------------+-----
8 rows in set (0.06 sec)
mysql>select FOUND_ROWS()
+--------------+
| FOUND_ROWS() |
+--------------+
|8 |
+--------------+
1 row in set (0.06 sec)
mysql>
方法二,通过系统表information_schema.`COLUMNS` ( mysql5以上版本支持)
mysql>select count(*) from information_schema.`COLUMNS`
->where TABLE_SCHEMA='csdn'
->and TABLE_NAME='ysks'
+----------+
| count(*) |
+----------+
|8 |
+----------+
1 row in set (0.06 sec)
mysql>
方法一,在你的程序中直接
desc tablename
然后总行数就是你的字段数。
mysql> desc ysks+-------+---------------+-----
| Field | Type | Null
+-------+---------------+-----
| 单号 | int(11) | YES
| 金额 | decimal(10,2) | YES
| 已收 | decimal(10,2) | YES
| 日期 | bigint(20) | YES
| 名称 | varchar(10) | YES
| 余额 | decimal(10,2) | YES
| 备注 | varchar(10) | YES
| 品名 | varchar(10) | YES
+-------+---------------+-----
8 rows in set (0.06 sec)
mysql> select FOUND_ROWS()
+--------------+
| FOUND_ROWS() |
+--------------+
| 8 |
+--------------+
1 row in set (0.06 sec)
mysql>
方法二,通过系统表information_schema.`COLUMNS` ( mysql5以上版本支持)
mysql> select count(*) from information_schema.`COLUMNS`-> where TABLE_SCHEMA='csdn'
-> and TABLE_NAME='ysks'
+----------+
| count(*) |
+----------+
| 8 |
+----------+
1 row in set (0.06 sec)
mysql>
CREATE function [dbo].[GetCharIndexNum](@findstring varchar(max),@string varchar(max))
returns int
AS
BEGIN
declare @location int , --要找的字符位置
@num int --要找的字符出现的次数
set @num =0
set @location = charindex (@findstring,@string)
while @location >0 ---字符串中存在要找的字符
begin
set @num =@num +1
set @string =substring(@string,@location+1,len(@string))
set @location = charindex (@findstring,@string)
end
return @num
END
--举个例子调用这个标量值函数 select [dbo].[GetCharIndexNum]('5','abc5ab5')
返回值2,5这个字符出现了2次
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)