3 回答

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊
代碼如下:
CREATE function Get_StrArrayStrOfIndex
(
@str varchar(1024), --要分割的字符串
@split varchar(10), --分隔符號(hào)
@index int --取第幾個(gè)元素
)
returns varchar(1024)
as
begin
declare @location int
declare @start int
declare @next int
declare @seed int
set @str=ltrim(rtrim(@str))
set @start=1
set @next=1
set @seed=len(@split)
set @location=charindex(@split,@str)
while @location<>0 and @index>@next
begin
set @start=@location+@seed
set @location=charindex(@split,@str,@start)
set @next=@next+1
end
if @location =0 select @location =len(@str)+1
--這兒存在兩種情況:1、字符串不存在分隔符號(hào) 2、字符串中存在分隔符號(hào),跳出while循環(huán)后,@location為0,那默認(rèn)為字符串后邊有一個(gè)分隔符號(hào)。
return substring(@str,@start,@location-@start)
end
運(yùn)行效果:
調(diào)用示例:select dbo.Get_StrArrayStrOfIndex('8,9,4',',',2)
返回值:9

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個(gè)贊
private static final SessionFactory sessionFactory = new Configuration()
.configure().buildSessionFactory();
public List selectPerson(String sql) {
try {
Session session = sessionFactory.openSession();
List list=(List)session.createQuery(sql).list();
session.close();
sessionFactory.close();
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
沒看明白你用什么語言的,以上試用JAVA語言時(shí),抽取的數(shù)據(jù)...讀取是用list.get(i);

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
$GetArr=array();
while($tmp=$db->mysql_fetch_array($query,$result_type)){
$GetArr[]=$tmp;
}
print_r($GetArr);
添加回答
舉報(bào)