instrํ•จ์ˆ˜๋Š” ์–ด๋–ค ์ŠคํŠธ๋ง์˜ ํŠน์ •์œ„์น˜์—์„œ ์‹œ์ž‘ํ•ด์„œ ํŠน์ • ์ผ€๋ฆญํ„ฐ๊ฐ€ ์œ„์น˜ํ•œ ๊ณณ๊นŒ์ง€์˜ ์œ„์น˜๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.


Java์˜ split ๋ฉ”์†Œ๋“œ์™€ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ• ๋•Œ ์˜ค๋ผํด์˜ substrํ•จ์ˆ˜์™€ ํ•จ๊ป˜ ๊ฐ™์ด ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์ฃ .


์˜ค๋ผํด ๋ฌธ์„œ์—์„œ ์„ค๋ช…ํ•˜๋Š” instrํ•จ์ˆ˜์— ๋Œ€ํ•œ ์ •์˜ ๋ฐ ๋ฌธ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.


The INSTR functions (INSTR, INSTRB, INSTRC, INSTR2, and INSTR4) searches a string for a substring using characters and returns the position in the string that is the first character of a specified occurrence of the substring. The functions vary in how they determine the position of the substring to return.

  • INSTR calculates lengths using characters as defined by the input character set.

  • INSTRB calculates lengths using bytes.

  • INSTRC calculates lengths using Unicode complete characters.

  • INSTR2 calculates lengths using UCS2 code points.

  • INSTR4 calculates lengths using UCS4 code points.

๋ฐ˜ํ™˜๊ฐ’

A nonzero INTEGER when the search is successful or 0 (zero) when it is not.


๋ฌธ๋ฒ• 

{INSTR | INSTRB | INSTRC | INSTR2 | INSTR4} (string , substring [, position [, occurrence]])


๊ทธ๋Ÿผ ๊ฐ„๋‹จํ•œ ์˜ˆ์ œ๋ฅผ ํ•œ๋ฒˆ ๋ณด์‹œ์ฃ .


abc.def.ghi.jkl ์ด๋ผ๋Š” ํŒจํ‚ค์ง€๋ช…์ด ์žˆ๋‹ค๊ณ  ํ•ด๋ด…์‹œ๋‹ค.


์ด ํŒจํ‚ค์ง€๋ช…์—์„œ abc.def ( ๋‘๋ฒˆ์งธ depth ๊นŒ์ง€)๋งŒ ์ถ”์ถœํ•ด๋‚ด๊ณ  ์‹ถ์€๋ฐ ๊ทธ๋Ÿฌ๋ ค๋ฉด substr์„ ์ƒ๊ฐํ•˜์‹ค ์ˆ˜๋„ ์žˆ๊ฒ ์ฃ .


select substr(packageNm, 1, 7) from ClassTable;


์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ฒฐ๊ณผ๋Š” abc.def ๊ฐ€ ๋‚˜์˜ฌ ๊ฒƒ์ž…๋‹ˆ๋‹ค.


ํ•˜์ง€๋งŒ ๋งŒ์•ฝ ํŒจํ‚ค์ง€๋ช…์ด 3๊ธ€์ž.3๊ธ€์ž ํ˜•ํƒœ๊ฐ€ ์•„๋‹ˆ๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”?


a.b.c.d.e.f ๋ผ๋Š” ํŒจํ‚ค์ง€๋ช…์„ ์œ„์ฒ˜๋Ÿผ ์ž๋ฅด๋ฉด a.b.c.d ๋ผ๊ณ  ์ž˜๋ ค์„œ ๋‚˜์˜ค๊ฒ ์ฃ ?


๋‘๋ฒˆ์งธ depth๊ฐ€ ์•„๋‹ˆ๋ผ 7๋ฒˆ์งธ๊นŒ์ง€ ์ถœ๋ ฅ์ด ๋˜๋ฒ„๋ฆฌ๊ฒ ๊ตฐ์š”.


์ด๋•Œ instr ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉ์„ ํ•ฉ๋‹ˆ๋‹ค.


select substr( packageNm, 1, instr( packageNm, '.', 1, 2) - 1 ) ) from ClassTable;


์ด๋ ‡๊ฒŒ ํ•จ์ˆ˜๋ฅผ ์จ์ค๋‹ˆ๋‹ค.


instr( packageNm, '.', 1, 2 ) ๋ผ๋Š” ๋ถ€๋ถ„์€ packageNm์ด๋ผ๋Š” ์ŠคํŠธ๋ง์„ '.' (๋งˆ์นจํ‘œ)๋กœ ๊ตฌ๋ถ„์„ ์ง“๊ณ  1๋ฒˆ์งธ ์ธ๋ฑ์Šค์—์„œ ์‹œ์ž‘ํ•ด์„œ 2๋ฒˆ์งธ ๋งˆ์นจํ‘œ๊ฐ€ ๋‚˜์˜ค๋Š” ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜์„ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ๋งˆ์นจํ‘œ๊ฐ€ ์žˆ๋Š” ์ธ๋ฑ์Šค๊ฐ€ ๋‚˜์˜ค๊ธฐ ๋•Œ๋ฌธ์— -1์„ ํ•ด์ค€ ๊ฐ’์„ substrํ•จ์ˆ˜์˜ length์— ๋„ฃ์–ด์ฃผ๋ฉด ๋‘๋ฒˆ์งธ depth๊นŒ์ง€ substrํ•œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.