sql >> Databasteknik >  >> RDS >> Oracle

Hur får man tillgång till strukturen och får kolumnlistan, datatyper av refcursor?

Du kan konvertera referensmarkören till en DBMS_SQL markören med DBMS_SQL.TO_CURSOR_NUMBER fungera. Sedan, med markörnumret, kan du inspektera manipulera det via DBMS_SQL . Detta inkluderar att kunna beskriva dess kolumner, som visas i exemplet nedan:

DECLARE
  l_rc              SYS_REFCURSOR;

  l_cursor_number   INTEGER;
  l_col_cnt         INTEGER;
  l_desc_tab        DBMS_SQL.desc_tab;
  l_col_num         INTEGER;
BEGIN
  OPEN l_rc FOR 'SELECT object_name, object_type, last_ddl_time FROM dba_objects where rownum <= 10';

  l_cursor_number   := DBMS_SQL.to_cursor_number (l_rc);

  DBMS_SQL.describe_columns (l_cursor_number, l_col_cnt, l_desc_tab);

  l_col_num         := l_desc_tab.FIRST;

  IF (l_col_num IS NOT NULL) THEN
    LOOP
      DBMS_OUTPUT.put_line ('Column #' || l_col_num);
      DBMS_OUTPUT.put_line ('...name: ' || l_desc_tab (l_col_num).col_name);
      DBMS_OUTPUT.put_line ('...type: ' || l_desc_tab (l_col_num).col_type);
      DBMS_OUTPUT.put_line ('...maxlen: ' || l_desc_tab (l_col_num).col_max_len);
      -- ... other fields available in l_desc_tab(l_col_num) too.
      l_col_num   := l_desc_tab.NEXT (l_col_num);
      EXIT WHEN (l_col_num IS NULL);
    END LOOP;
  END IF;

  DBMS_SQL.close_cursor (l_cursor_number);
END;

Utdata

Column #1
...name: OBJECT_NAME
...type: 1
...maxlen: 128
Column #2
...name: OBJECT_TYPE
...type: 1
...maxlen: 23
Column #3
...name: LAST_DDL_TIME
...type: 12
...maxlen: 7


  1. Hur sparar jag BLOB som fil i PL/SQL?

  2. Wordpress Fatalt fel:Oupptäckt fel:Anrop till odefinierad funktion mysql_connect() i /wp-includes/wp-db.php:1570

  3. Docker PGMASTER PostgreSQL versionsuppdatering

  4. Använda ODBC-data i RapidMiner