diff --git a/django/db/models/fields/json.py b/django/db/models/fields/json.py index 7b9b2ae6b26a..571e6e79f345 100644 --- a/django/db/models/fields/json.py +++ b/django/db/models/fields/json.py @@ -352,10 +352,13 @@ def as_mysql(self, compiler, connection): def as_oracle(self, compiler, connection): lhs, params, key_transforms = self.preprocess_lhs(compiler, connection) json_path = compile_json_path(key_transforms) - return ( - "COALESCE(JSON_QUERY(%s, '%s'), JSON_VALUE(%s, '%s'))" - % ((lhs, json_path) * 2) - ), tuple(params) * 2 + if connection.features.supports_primitives_in_json_field: + sql = ( + "COALESCE(JSON_VALUE(%s, '%s'), JSON_QUERY(%s, '%s' DISALLOW SCALARS))" + ) + else: + sql = "COALESCE(JSON_QUERY(%s, '%s'), JSON_VALUE(%s, '%s'))" + return sql % ((lhs, json_path) * 2), tuple(params) * 2 def as_postgresql(self, compiler, connection): lhs, params, key_transforms = self.preprocess_lhs(compiler, connection)