DB2 Scalar functions - TABLE_SCHEMA
The TABLE_SCHEMA function returns the schema name of the object found after any alias chains have been resolved.
The schema is SYSIBM.
The specified object-name (and object-schema) are used as the starting point of the resolution. If the starting point does not refer to an alias, the schema name of the starting point is returned. The resulting schema name may be of a table, view, or undefined object. In a Unicode database, if a supplied argument is a graphic string, it is first converted to a character string before the function is executed.
If object-schema is not supplied, the default schema is used for the qualifier.
The data type of the result of the function is VARCHAR(128 OCTETS). If object-name can be null, the result can be null; if object-name is null, the result is the null value. If object-schema is the null value, the default schema name is used. The result is the character string representing a schema name. The result schema could represent the schema name for one of the following objects:
Therefore, if a non-null object-name value is given to this function, a value is always returned, even if the object name with the result schema name does not exist. For example, TABLE_SCHEMA('DEPT', 'PEOPLE') returns 'PEOPLE ' if the catalog entry is not found.
SELECT NPAGES , CARD FROM SYSCAT.TABLES WHERE TABNAME = TABLE_NAME ('A1') AND TABSCHEMA = TABLE_SCHEMA ('A1')
The requested statistics for HEDGES.T1 are retrieved from the catalog.
SELECT NPAGES , CARD FROM SYSCAT.TABLES WHERE TABNAME = TABLE_NAME ('X1','HEDGES') AND TABSCHEMA = TABLE_SCHEMA ('X1','HEDGES')
Assuming that HEDGES.X1 is a table, the requested statistics for HEDGES.X1 are retrieved from the catalog.
SELECT NPAGES , CARD FROM SYSCAT.TABLES WHERE TABNAME = TABLE_NAME ('A2','PBIRD') AND TABSCHEMA = TABLE_SCHEMA ('A2','PBIRD')
The statement returns 0 records as no matching entry is found in SYSCAT.TABLES where TABNAME = 'T2' and TABSCHEMA = 'HEDGES'.
SELECT TABSCHEMA AS SCHEMA , TABNAME AS NAME , TABLE_SCHEMA (BASE_TABNAME, BASE_TABSCHEMA) AS REAL_SCHEMA , TABLE_NAME (BASE_TABNAME, BASE_TABSCHEMA) AS REAL_NAME FROM SYSCAT.TABLES
The statement returns the qualified name for each object in the catalog and the final referenced name (after alias has been resolved) for any alias entries. For all non-alias entries, BASE_TABNAME and BASE_TABSCHEMA are null so the REAL_SCHEMA and REAL_NAME columns will contain nulls.