我確定這是超級簡單的,但我將如何去將姓氏,名字轉換爲姓氏,FirstInitial?更改姓氏,名字到姓氏,FirstInitial
例如改變史密斯,約翰·史密斯,J或約翰遜,約翰 - 約翰遜,J等
謝謝!
我確定這是超級簡單的,但我將如何去將姓氏,名字轉換爲姓氏,FirstInitial?更改姓氏,名字到姓氏,FirstInitial
例如改變史密斯,約翰·史密斯,J或約翰遜,約翰 - 約翰遜,J等
謝謝!
在名字和姓列的情況下:
select LastName,substr(FirstName,1,1)
from mytable
;
在保存在一個列中的全稱的情況下:
select substr(fullname,1,instr(fullname || ',',',')-1) || substr(fullname,instr(fullname || ',',','),2)
from mytable
;
或
select regexp_replace (fullname,'([^,]*,?)(.).*','\1\2')
from mytable
;
下面是一個方法,僅使用「標準」instr
和substr
。假設你輸入一個字符串格式'Smith,John'
:
select substr(fullname, 1, instr(fullname, ',')+1) from yourtable;
yourtable
是表的名稱,fullname
是列名。
instr(fullname, ',') finds the position of the comma within the input string (it would be 6 in 'Smith,John'); then
substr instr`,PLUS 1(獲得第一個首字母)。
你試過了什麼? –