t8y2/dbx · error
failed to load view source for %s.%s: DBMS_METADATA: %v; ALL
Error message
failed to load view source for %s.%s: DBMS_METADATA: %v; ALL_VIEWS: %w
What it means
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.
Source
Thrown at agents/drivers/oracle-go/main.go:3419
metadataErr := db.QueryRow(
"SELECT DBMS_METADATA.GET_DDL('VIEW', :1, :2) FROM DUAL",
viewName, schema,
).Scan(&ddl)
if metadataErr == nil && strings.TrimSpace(ddl) != "" {
return strings.TrimSpace(ddl), nil
}
var source string
fallbackErr := db.QueryRow(
"SELECT TEXT FROM ALL_VIEWS WHERE OWNER = :1 AND VIEW_NAME = :2",
schema, viewName,
).Scan(&source)
if fallbackErr == nil && strings.TrimSpace(source) != "" {
return strings.TrimSpace(source), nil
}
if fallbackErr != nil && !errors.Is(fallbackErr, sql.ErrNoRows) {
if metadataErr != nil {
return "", fmt.Errorf(
"failed to load view source for %s.%s: DBMS_METADATA: %v; ALL_VIEWS: %w",
schema, viewName, metadataErr, fallbackErr,
)
}
return "", fmt.Errorf("failed to load view source for %s.%s from ALL_VIEWS: %w", schema, viewName, fallbackErr)
}
return "", fmt.Errorf("view source not found: %s.%s", schema, viewName)
}
func (s *server) buildTableDDL(schema, table string) (string, error) {
columns, err := s.getColumns(schema, table)
if err != nil {
return "", err
}
if len(columns) == 0 {
return "", fmt.Errorf("table not found: %s.%s", schema, table)
}
var builder strings.BuilderView on GitHub (pinned to c0390bff16)
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)
Example fix
// before -- user can see the view but not DBMS_METADATA GRANT SELECT ON hr.v TO app; // after GRANT EXECUTE ON DBMS_METADATA TO app; GRANT SELECT ANY DICTIONARY TO app; -- then retry DDL extraction
Defensive patterns
Strategy: try-catch
Validate before calling
var canMeta, canDict bool
db.QueryRow(`SELECT COUNT(*) FROM session_privs WHERE privilege IN ('EXECUTE ANY PROCEDURE','SELECT ANY DICTIONARY')`).Scan(&canDict)
_ = canMeta; _ = canDict // require dictionary access before view DDL extraction Try / catch
src, err := loadViewSource(s, schema, view)
if err != nil && strings.Contains(err.Error(), "DBMS_METADATA: ") {
// both paths failed; inspect each cause and retry with elevated introspection role
log.Printf("both extraction paths failed for %s.%s: %v", schema, view, err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to load view source for %s.%s from ALL_VIEWS: %w
- failed to disable Oracle segment attributes: %w
- view source not found: %s.%s
- agent session not found: %s
- reserve connection for manual transaction: %w
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/6f61e16042cebe7f.
Report an issue: GitHub.