參考網址

以下為MYSQL ViewTable 作為範例

CREATE ALGORITHM = UNDEFINED DEFINER = `root`@`localhost` SQL SECURITY DEFINER VIEW `view_rcab4` AS
SELECT
 `tb_rcab2`.`RelTtrSno` AS `RelTtrSno`,
 `tb_rcab2`.`TtrSno` AS `TtrSno`,
 `tb_customer`.`Account` AS `Account`,
CASE `tb_rcab2`.`AnonyMode` WHEN 'TRUE' THEN `tb_rcab2`.`Sdr` ELSE `tb_customer`.`CName` END AS `CName`,
CASE `tb_rcab2`.`AnonyMode` WHEN 'TRUE' THEN `tb_rcab2`.`SdrPhone` ELSE `tb_customer`.`CPhone` END AS `CPhone`,
CASE `tb_rcab2`.`AnonyMode` WHEN 'TRUE' THEN `tb_rcab2`.`SdrAdr` ELSE `tb_customer`.`CAddres` END AS `CAddres`
FROM
 (`tb_rcab2`
JOIN
 `tb_customer`)
WHERE
 (
 (`tb_rcab2`.`IsEmailCheck` = 'TRUE') AND(`tb_rcab2`.`CancelMk` = 'FALSE') AND(
 `tb_customer`.`Account` = `tb_rcab2`.`PickupXrem`
 )
 );

我們以此行為例

CASE `tb_rcab2`.`AnonyMode` WHEN ‘TRUE’ THEN `tb_rcab2`.`Sdr` ELSE `tb_customer`.`CName`  END AS `CName`,

在 tb_rcab2`.`AnonyMode` =  ‘TRUE’  的時候顯示  `tb_rcab2`.`Sdr` 的欄位資料,否則顯示 `tb_customer`.`CName`欄位資料並將顯示欄位名稱更改為 CName.

 

PS:參考網址內… 除MYSQL使用方式外,還有 Oracle 的使用方式…

 

Leave a Comment