2017-01-04 13 views
0


エラーレポート:これを実行した後私は、Oracle 12cの上で次のコード実行していますレンスのためのJSONを使用して問題JSON_VALUE以上11000文字の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; 

を、私はその結果を取得します -
ORA-40441:JSON構文エラー
ORA-06512:行12で
40441. 00000 - "JSONの構文エラー"
*原因:提供するJavaScript Object Notation(JSON)形式のデータを持っていた無効
構文であり、解析できませんでした。
*処置:JSONデータに正しい構文を指定してください。

VAR:

私はその結果を期待しています0

ので、渡されたJSONの長さに問題があるのでしょうか?あなたのVARCHAR2(90)は、戻り値のために、それはnullを返すことが小さすぎると

{ 
"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": "[email protected]: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": "[email protected]: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" 
    } 
} 
+0

これは参考になった例を示しているようですが、これは参考にならないかもしれません。実際のJSONとパス、または少なくとも問題を再現するために使用できるものは、タイプミスや文字混乱、構造のわずかな間違いです。実際、JoshMaagが示唆したことはありますが、それはあなたの例では示されていません。 –

+0

@AlexPoole、私は実際のJSONを更新し、JSON_VALUEクエリを更新しました。私はJSONの構文が間違っている例外を取得していますが、JSONの構文を検証しました。合ってます。 jsonの長さのために問題がありますか?助けてください。 –

+0

CLOBリテラルと表のCLOB列の両方として、[OracleのLive SQLで動作する](https://livesql.oracle.com/apex/livesql/s/ed2ddt004q6vwdx3uns56rt4k)が表示されています。私はあなたが実際のテーブル値で見ることができない制御文字または他の何かを持っていると思います。 (ちょっと、その列に 'is json'チェック制約がありますか?) –

答えて

0

私のJSONは次のようになります。参照のためにJSON_value_on_error_clauseを参照してください。

+0

私は本当のJSONとエラートレースで質問を更新しました。チェックしてください。 –

0

私はそれが助けになるかどうかはわかりません。あなたが示した例では何の違いもなく、異なる値の制御文字またはマルチバイト文字が問題を引き起こすかどうかはわかりませんが暗黙的に文字列とバックに変換するのではなく、JSON値をバインドします。

l_query := 'select json_value(:json, '''||mypath||''' ERROR ON ERROR) from dual'; 
execute Immediate l_query into l_var using l_json; 
関連する問題