
JSON_CONTAINS 함수의 path 매개변수는 target JSON 데이터의 특정 경로를 지정하여 비교할 수 있습니다. 예를 들어, target JSON 데이터가 다음과 같다면:
#hostingforum.kr
json
{
"name": "John",
"age": 30,
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY"
}
}
candidate JSON 데이터가 다음과 같다면:
#hostingforum.kr
json
{
"name": "Jane",
"age": 25,
"address": {
"street": "456 Elm St",
"city": "Los Angeles",
"state": "CA"
}
}
path 매개변수를 사용하여 target JSON 데이터의 "address" 경로에 candidate JSON 데이터가 포함되어 있는지 확인하고 싶다면, 다음과 같이 사용할 수 있습니다:
#hostingforum.kr
sql
JSON_CONTAINS(target_json, candidate_json, '$.address')
이 코드는 target JSON 데이터의 "address" 경로에 candidate JSON 데이터가 포함되어 있는지 확인합니다. '$.address'는 path 매개변수를 지정하는 방법입니다. '$'는 JSON 데이터의 루트 경로를 나타내고, 'address'는 target JSON 데이터의 "address" 경로를 지정합니다.
또한, path 매개변수를 사용하여 target JSON 데이터의 특정 필드에 candidate JSON 데이터가 포함되어 있는지 확인할 수도 있습니다. 예를 들어, target JSON 데이터가 다음과 같다면:
#hostingforum.kr
json
{
"name": "John",
"age": 30,
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY"
}
}
candidate JSON 데이터가 다음과 같다면:
#hostingforum.kr
json
{
"street": "456 Elm St",
"city": "Los Angeles",
"state": "CA"
}
path 매개변수를 사용하여 target JSON 데이터의 "address" 경로의 "street" 필드에 candidate JSON 데이터가 포함되어 있는지 확인하고 싶다면, 다음과 같이 사용할 수 있습니다:
#hostingforum.kr
sql
JSON_CONTAINS(target_json, candidate_json, '$.address.street')
이 코드는 target JSON 데이터의 "address" 경로의 "street" 필드에 candidate JSON 데이터가 포함되어 있는지 확인합니다.
2025-03-16 18:39