OracleデータベースのSQL単行関数---文字関数続き
前のブログはいくつかの文字関数を練習して、それから自分でまた関連する資料を調べて、前のブログの中でまだたくさんあります
文字関数は練習されていませんが、今回は主に前回の未使用の文字関数について補足練習を行います.
指定した文字に対応する10進数を返し、文字列の場合は文字列の先頭文字の10進数を返します.
ascii関数とは逆に、整数を与えて特定の文字を返す
1つの文字列で指定した文字を検索し、指定した額の文字の位置を返し、1回だけ取得します.
C 1:検索された文字列
C 2:検索する文字列
I:検索の開始位置、デフォルトは1で、もし正であれば、左から右へ検索を開始し、逆です.取得しない0
J:出現位置:tips:この位置は何回目の出現を指す.デフォルトは1、負または0のシステムエラーです.
例:
興味深い関数は、与えられた文字列の読み方と同じ文字列を返します.
文字列処理関数にTRIM関数があるので、時間を見つけて詳しく理解し、練習します.
文字関数は練習されていませんが、今回は主に前回の未使用の文字関数について補足練習を行います.
ascii()
指定した文字に対応する10進数を返し、文字列の場合は文字列の先頭文字の10進数を返します.
select ascii('AAA') A,ascii('aa') a,ascii('0') ZERO , ascii(' ') space from dual;
chr()
ascii関数とは逆に、整数を与えて特定の文字を返す
select chr(65) x,chr(97) y from dual;
instr(C1,C2,I,J)
1つの文字列で指定した文字を検索し、指定した額の文字の位置を返し、1回だけ取得します.
C 1:検索された文字列
C 2:検索する文字列
I:検索の開始位置、デフォルトは1で、もし正であれば、左から右へ検索を開始し、逆です.取得しない0
J:出現位置:tips:この位置は何回目の出現を指す.デフォルトは1、負または0のシステムエラーです.
例:
select instr('Oracle hello Oracle hello','Oracle',-1,2) from dual;
ltrim、rtrim
select RTRIM('hello oracle','oracle') from dual;-- hello: ‘oracle’
soundex
興味深い関数は、与えられた文字列の読み方と同じ文字列を返します.
create table test_soundex ( username varchar2(20) ); insert into test_soundex values('Kiritor'); insert into test_soundex values('Kirito'); insert into test_soundex values('kiritor'); insert into test_soundex values('Alex'); select username from test_soundex where soundex(username)=soundex('Kiritor');
文字列処理関数にTRIM関数があるので、時間を見つけて詳しく理解し、練習します.