{"record":{"id":"6f61e16042cebe7f","repo":"t8y2/dbx","slug":"failed-to-load-view-source-for-s-s-dbms-metadat","errorCode":null,"errorMessage":"failed to load view source for %s.%s: DBMS_METADATA: %v; ALL_VIEWS: %w","messagePattern":"failed to load view source for (.+?)\\.(.+?): DBMS_METADATA: (.+?); ALL_VIEWS: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/oracle-go/main.go","lineNumber":3419,"sourceCode":"\tmetadataErr := db.QueryRow(\n\t\t\"SELECT DBMS_METADATA.GET_DDL('VIEW', :1, :2) FROM DUAL\",\n\t\tviewName, schema,\n\t).Scan(&ddl)\n\tif metadataErr == nil && strings.TrimSpace(ddl) != \"\" {\n\t\treturn strings.TrimSpace(ddl), nil\n\t}\n\n\tvar source string\n\tfallbackErr := db.QueryRow(\n\t\t\"SELECT TEXT FROM ALL_VIEWS WHERE OWNER = :1 AND VIEW_NAME = :2\",\n\t\tschema, viewName,\n\t).Scan(&source)\n\tif fallbackErr == nil && strings.TrimSpace(source) != \"\" {\n\t\treturn strings.TrimSpace(source), nil\n\t}\n\tif fallbackErr != nil && !errors.Is(fallbackErr, sql.ErrNoRows) {\n\t\tif metadataErr != nil {\n\t\t\treturn \"\", fmt.Errorf(\n\t\t\t\t\"failed to load view source for %s.%s: DBMS_METADATA: %v; ALL_VIEWS: %w\",\n\t\t\t\tschema, viewName, metadataErr, fallbackErr,\n\t\t\t)\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"failed to load view source for %s.%s from ALL_VIEWS: %w\", schema, viewName, fallbackErr)\n\t}\n\treturn \"\", fmt.Errorf(\"view source not found: %s.%s\", schema, viewName)\n}\n\nfunc (s *server) buildTableDDL(schema, table string) (string, error) {\n\tcolumns, err := s.getColumns(schema, table)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif len(columns) == 0 {\n\t\treturn \"\", fmt.Errorf(\"table not found: %s.%s\", schema, table)\n\t}\n\tvar builder strings.Builder","sourceCodeStart":3401,"sourceCodeEnd":3437,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/oracle-go/main.go#L3401-L3437","documentation":"The driver loads a view's source first via DBMS_METADATA.GET_DDL and falls back to querying ALL_VIEWS.TEXT. If the fallback query fails with a real error (not just no rows) AND the DBMS_METADATA attempt also failed, both causes are combined into this dual-cause error so developers can see why each path failed.","triggerScenarios":"Both DBMS_METADATA.GET_DDL and the ALL_VIEWS fallback query fail — e.g. missing SELECT_CATALOG privileges plus a network error, invalid view text in ALL_VIEWS, or the view lives in a schema the caller cannot read.","commonSituations":"User granted access to the view but not to DBMS_METADATA or dictionary views; long views whose TEXT is in LONG column requiring special handling; network blips during introspection.","solutions":["Read both wrapped causes: fix the DBMS_METADATA error (usually grants) and the ALL_VIEWS error separately","Grant the user EXECUTE on DBMS_METADATA and SELECT ANY DICTIONARY (or dictionary access) as appropriate","Confirm schema/viewName are correct and the caller has SELECT on the view itself","Retry if the underlying cause was transient (network/ORA-03113)"],"exampleFix":"// before\n-- user can see the view but not DBMS_METADATA\nGRANT SELECT ON hr.v TO app;\n// after\nGRANT EXECUTE ON DBMS_METADATA TO app;\nGRANT SELECT ANY DICTIONARY TO app; -- then retry DDL extraction","handlingStrategy":"try-catch","validationCode":"var canMeta, canDict bool\ndb.QueryRow(`SELECT COUNT(*) FROM session_privs WHERE privilege IN ('EXECUTE ANY PROCEDURE','SELECT ANY DICTIONARY')`).Scan(&canDict)\n_ = canMeta; _ = canDict // require dictionary access before view DDL extraction","typeGuard":null,"tryCatchPattern":"src, err := loadViewSource(s, schema, view)\nif err != nil && strings.Contains(err.Error(), \"DBMS_METADATA: \") {\n    // both paths failed; inspect each cause and retry with elevated introspection role\n    log.Printf(\"both extraction paths failed for %s.%s: %v\", schema, view, err)\n}","preventionTips":["Grant EXECUTE on DBMS_METADATA and dictionary SELECT to the introspection user","Test both extraction paths with a known-good view during setup","Handle LONG-column TEXT carefully when reading ALL_VIEWS","Retry transient network failures before concluding grants are the problem"],"tags":["go","oracle","view","dbms-metadata","privileges"],"backgroundTag":"view-source-extraction-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}