英文:
ORA-22806: not an object or REF when use json path item function
问题
"ORA-22806: not an object or REF" 这个错误是在我在Oracle 21c中运行以下SQL时报告的:
create table t(j json);
insert into t values('{"k": "v"}');
select t.j.type() from t t;
但这个是成功的:
select t.j.k.type() from t t;
我无法理解为什么会出现这个错误,有人可以帮助我吗?
英文:
The error "ORA-22806: not an object or REF" was reported when I run the following sql in oracle 21c.
create table t(j json);
insert into t values('{"k": "v"}');
select t.j.type() from t t;
SQL> select t.j.type() from t t;
select t.j.type() from t t
*
ERROR at line 1:
ORA-22806: not an object or REF
but this's success;
select t.j.k.type() from t t;
I can not understand why this error was occured, can anyone help me?
答案1
得分: 1
你可以使用:
SELECT JSON_VALUE(j, '$.type()') FROM t;
我无法理解为什么会出现这个错误,有人可以帮助我吗?
t.j
是该列的标识符,您还没有进入 JSON 结构,因此当您调用 t.j.type()
时,SQL 引擎会假定 t.j
将是具有 type
方法的 SQL 对象(或引用具有该方法的对象),而似乎它不会切换到解析 JSON 并在 JSON 解析器中找到 type
方法。
这可能可以归类为 JSON 实现的错误,但您可以通过使用上面所示的 JSON_VALUE
来解决这个问题。
英文:
You can use:
SELECT JSON_VALUE(j, '$.type()') FROM t;
> I can not understand why this error was occurred, can anyone help me?
t.j
is the identifier for the column, and you have not yet descended into the JSON structure, so when you call t.j.type()
the SQL engine assumes that t.j
will be an SQL object with the type
method (or a reference to an object with that method) and it appears that it does not switch to parsing the JSON and find the type
method within the JSON parser.
This could probably be classified as a bug with the JSON implementation but you can get around it by using JSON_VALUE
as shown above.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论