I am running the following code on Oracle 12c :
DECLARE
l_json clob;
l_var varchar2(90);
l_query clob;
mypath clob;
l_path_value varchar2(100);
BEGIN
SELECT json_column into l_json from my_table;
SELECT path_column into l_path_value from my_table; -- this returns 'watchers'
mypath := '$.second."'||l_path_value||'"'; -- $.second."watchers"
l_query := 'select json_value('''||l_json||''', '''||mypath||''' ERROR ON ERROR) from dual';
execute Immediate l_query into l_var;
DBMS_OUTPUT.PUT_LINE('var: '||l_var);
END;
After running this, i get the result as:
Error report -
ORA-40441: JSON syntax error
ORA-06512: at line 12
40441. 00000 - "JSON syntax error"
*Cause: The provided JavaScript Object Notation (JSON) data had invalid
syntax and could not be parsed.
*Action: Provide JSON data with the correct syntax.
I am expecting result as:
var: 0
So is there a problem with length of the JSON passed?
My json looks like :
{
"first": {
"private": false,
"html_url": "https://github.com/mralexgray/Alfred-Google-Translate",
"description": "Extension for Alfred that will do a Google translate for you",
"fork": true,
"url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate",
"forks_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/forks",
"keys_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/teams",
"hooks_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/hooks",
"issue_events_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/issues/events{/number}",
"events_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/events",
"assignees_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/assignees{/user}",
"branches_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/branches{/branch}",
"tags_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/tags",
"blobs_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/statuses/{sha}",
"languages_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/languages",
"stargazers_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/stargazers",
"contributors_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/contributors",
"subscribers_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/subscribers",
"subscription_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/subscription",
"commits_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/contents/{+path}",
"compare_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/merges",
"archive_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/downloads",
"issues_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/issues{/number}",
"pulls_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/pulls{/number}",
"milestones_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/milestones{/number}",
"notifications_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/labels{/name}",
"releases_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/releases{/id}",
"deployments_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/deployments",
"created_at": "2013-06-04T10:45:10Z",
"updated_at": "2013-06-04T10:45:10Z",
"pushed_at": "2013-01-12T19:39:03Z",
"git_url": "git://github.com/mralexgray/Alfred-Google-Translate.git",
"ssh_url": "git@github.com:mralexgray/Alfred-Google-Translate.git",
"clone_url": "https://github.com/mralexgray/Alfred-Google-Translate.git",
"svn_url": "https://github.com/mralexgray/Alfred-Google-Translate",
"homepage": null,
"size": 103,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Shell",
"has_issues": false,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 0,
"mirror_url": null,
"open_issues_count": 0,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master"
},
"second": {
"private": false,
"html_url": "https://github.com/mralexgray/Alfred-Google-Translate",
"description": "Extension for Alfred that will do a Google translate for you",
"fork": true,
"url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate",
"forks_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/forks",
"keys_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/teams",
"hooks_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/hooks",
"issue_events_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/issues/events{/number}",
"events_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/events",
"assignees_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/assignees{/user}",
"branches_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/branches{/branch}",
"tags_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/tags",
"blobs_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/statuses/{sha}",
"languages_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/languages",
"stargazers_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/stargazers",
"contributors_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/contributors",
"subscribers_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/subscribers",
"subscription_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/subscription",
"commits_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/contents/{+path}",
"compare_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/merges",
"archive_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/downloads",
"issues_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/issues{/number}",
"pulls_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/pulls{/number}",
"milestones_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/milestones{/number}",
"notifications_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/labels{/name}",
"releases_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/releases{/id}",
"deployments_url": "https://api.github.com/repos/mralexgray/Alfred-Google-Translate/deployments",
"created_at": "2013-06-04T10:45:10Z",
"updated_at": "2013-06-04T10:45:10Z",
"pushed_at": "2013-01-12T19:39:03Z",
"git_url": "git://github.com/mralexgray/Alfred-Google-Translate.git",
"ssh_url": "git@github.com:mralexgray/Alfred-Google-Translate.git",
"clone_url": "https://github.com/mralexgray/Alfred-Google-Translate.git",
"svn_url": "https://github.com/mralexgray/Alfred-Google-Translate",
"homepage": null,
"size": 103,
"stargazers_count": 0,
"watchers_count": 0,
"language": "Shell",
"has_issues": false,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 0,
"mirror_url": null,
"open_issues_count": 0,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master"
}
}
If your varchar2(90) is too small for the return value it may return null. See JSON_value_on_error_clause for a reference.
I'm not sure it will help - with the example you've shown it doesn't make any difference, and I'm not sure whether any control or multibyte characters in a different value might cause a problem - but I would bind the JSON value, rather than implicitly converting to a string and back:
l_query := 'select json_value(:json, '''||mypath||''' ERROR ON ERROR) from dual';
execute Immediate l_query into l_var using l_json;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.