用mysql寫case when的自定義函式要怎麼寫

2021-07-08 22:17:42 字數 1724 閱讀 5446

1樓:匿名使用者

mysql> create function helloworld4()

-> returns varchar(20)-> begin

-> return 'hello world!';

-> end;

-> //

query ok, 0 rows affected (0.00 sec)

mysql> select helloworld4() //+---------------+

| helloworld4() |

+---------------+

| hello world! |

+---------------+

1 row in set (0.00 sec)如果你會其它資料庫的話, 那麼看看那個 sql 儲存過程編寫 參考手冊 對你會有些幫助。

2樓:匿名使用者

delimiter $$

create function `aa`.`gg`(aa int)returns varchar(10)

begin

return if(aa=1,'y','n');

end$$

delimiter ;

select gg(1)

jessy2007 2014-05-15評價(0)(0)(0)

sql code

create function emun_case_when (para int) returns char(50) deterministic return interval(para, '張三', '李四', ...);

mysql自定義函式怎麼寫?

3樓:路路通

mysql> create function helloworld4()

-> returns varchar(20)

-> begin

->   return 'hello world!e69da5e6ba9062616964757a686964616f31333365643538';

-> end;

-> //

query ok, 0 rows affected (0.00 sec)

mysql> select helloworld4() //

+---------------+

| helloworld4() |

+---------------+

| hello world!  |

+---------------+

1 row in set (0.00 sec) ...展開mysql> create function helloworld4()

-> returns varchar(20)

-> begin

->   return 'hello world!';

-> end;

-> //

query ok, 0 rows affected (0.00 sec)

mysql> select helloworld4() //

+---------------+

| helloworld4() |

+---------------+

| hello world!  |

+---------------+

1 row in set (0.00 sec)

Mysql 用UUID做主鍵可行麼

在mysql中可以把uuid作為邏輯主鍵,物理主鍵依然使用自增id 1 uuid定義。uuid含義是通用唯一識別碼 universally unique identifier 這 是一個軟體建構的標準,也是被開源軟體 會 open software foundation,osf 的組織應用在分散式計...

php怎麼連線mysql資料庫,用php如何連線MySQL資料庫,請寫出程式碼。 急!!!

1 新建一個php mysql.php的檔案2 檢視mysql服務是否開啟,或者客戶端的mysql能夠正常開啟。滑鼠右鍵我的電腦 管理 服務和應用程式 服務 找到mysql服務,看看是不是啟用狀態。也可以開啟執行,輸入 mysql u root 使用者名稱 p 123456 密碼 看看能不能開啟客戶...

用php建mysql表時怎麼設定表的編碼為gb

可以使用 default charset gb2312 設定編碼。例如 建立一個名字為table的表,編碼為gb2312。create table if not exists table id int 11 not null auto increment,title varchar 255 not ...