วันพุธที่ 17 ธันวาคม พ.ศ. 2557

คำสั่ง SQL REPLACE

คำสั่ง SQL REPLACE

เป็นคำสั่งที่ใช้สำหรับการระบุเงื่อนไขการเลือกข้อมูลในตาราง (Table) โดยทำการแทนที่ข้อความที่พบในตำแหน่งที่ต้องการ 

Database : MySQL,Microsoft Access,SQL Server,Oracle

Syntax
SELECT REPLACE(Field,Search,Replace) AS [New-Field] FROM [Table-Name]

Table : customer

CustomerID
Name
Email
CountryCode
Budget
Used
C001
Win Weerachaiwin.weerachai@thaicreate.com
TH
1000000600000
C002
John Smithjohn.smith@thaicreate.com
EN
2000000800000
C003
Jame Bornjame.born@thaicreate.com
US
3000000600000
C004
Chalee Angelchalee.angel@thaicreate.com
US
4000000100000

Sample1 การเลือกข้อมูลโดยทำการแทนที่ค่า Win ด้วย Mr.Win

SELECT REPLACE(Name, 'Win', 'Mr.Win') AS MyName FROM customer

Output 
MyName
Mr.Win Weerachai
John Smith
Jame Born
Chalee Angel

ไม่มีความคิดเห็น:

แสดงความคิดเห็น