비전공자 개발일기

FIND_IN_SET() 본문

DB(MySQL)

FIND_IN_SET()

HiroDaegu 2022. 1. 4. 20:28
728x90
SMALL

FIND_IN_SET() in MySQL

  • Syntax: FIND_IN_SET(search string, string list)
  • Example: FIND_IN_SET('ank', 'b,ank,of,monk')
	$datas = "";
	foreach ($data_info as $key => $value) {
		$datas .= $value . ",";
	}
  • Example2:
                SELECT * FROM client_contract WHERE FIND_IN_SET(idx,'{$datas}')
    -> client_contract 테이블에서 {$datas}라는 필드값에서 idx인 데이터만을 반환
  • Result: 2

-> 특정 세트(ex 배열) 내에 있는 걸 찾는다는 의미로, 해당 string의 위치를 반환

-> 검색한 문자의 값이 없을 경우, 0을 반환

 

https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_find-in-set

 

MySQL :: MySQL 5.7 Reference Manual :: 12.8 String Functions and Operators

12.8 String Functions and Operators Table 12.12 String Functions and Operators Name Description ASCII() Return numeric value of left-most character BIN() Return a string containing binary representation of a number BIT_LENGTH() Return length of argument

dev.mysql.com

https://www.w3resource.com/mysql/string-functions/mysql-find_in_set-function.php

 

MySQL FIND_IN_SET() function - w3resource

MySQL FIND_IN_SET() returns the position of a string if it is present (as a substring) within a list of strings.

www.w3resource.com

 

 

 

728x90
LIST

'DB(MySQL)' 카테고리의 다른 글

Database  (0) 2021.07.22
Database  (0) 2021.07.21