mysql函式寫法

2021-07-05 03:46:58 字數 990 閱讀 2820

這個函式是將儲存的字段id集合拆分開查詢出名字,比如一張表儲存了另一張表的id集合是以"1,2,3,4"儲存,呼叫此函式會顯示對應的名字「值1,值2,值3,值4」

str:要拆分的字串。

s:拆分分隔符。

create definer=`root`@`localhost` function `const_function_strings`(str varchar(50),s varchar(10)) returns varchar(50) charset utf8

begin

declare strsub varchar(50)  default '';

declare startindex int default 1;

declare len int default 1;

while startindex<=length(str) do

set len= locate(s,str,startindex)-startindex;

if locate(s,str,startindex)=0 then 

set len=length(str)-(startindex-1);

set startindex=length(str)+1;

end if;

set strsub=concat(strsub,",",

(select typename from types 

where 

id=substring(str,startindex,len)));  

if locate(s,str,startindex)>0 then 

set startindex=locate(s,str,startindex)+1;

end if;

end while;

set strsub=substring(strsub,2,length(strsub));

return strsub;

end

MySQL常用寫法

create database database name 建立資料庫 drop database dbname 刪除資料庫 create table tabname col1type1 not null primary key col2type2 not null 建立新錶,新增限制條件,設定主鍵...

strcpy函式寫法

很多公司用這個函式考察應聘者的一些技能,如 風格 成熟度等。首先要避免國內一些教科書的誤導的諸如while dest src 這樣的 000001 include 002003 define bounds violated builtin trap 0 004005 define check bou...

匿名函式寫法

relaycommand this.addperson this.canaddperson 的意思可以翻譯為 relaycommand 引數 一,引數二 引數一 this.addperson 引數二 this.canaddperson this.addperson 的 意思是 乙個沒有引數的方 法,...