23.2 GET_PRIMARY_KEY_COLUMNS Function

This procedure returns a comma-delimited list of column names in the primary key. Returns NULL if no PK constraint exists.

Syntax

FUNCTION apex_db_dictionary.get_primary_key_columns (
    p_table      IN   VARCHAR2,
    p_owner      IN   VARCHAR2     DEFAULT NULL,
    p_delimiter  IN   VARCHAR2     DEFAULT ',' )
    RETURN VARCHAR2;

Parameters

Parameter Description
p_table

Name of the object (table or view). May include the owner, e.g. HR.EMP.

p_owner

(Optional) The owner of the object (default current user).

p_delimiter

Delimiter used between column names (default ',').

Returns

This function returns a comma-delimited list of primary key column names. Returns NULL if no primary key constraint exists.

Example

This example returns the column or columns that comprise the primary key of the EMP table. If the table has a composite key, the columns are delimited by a colon (":").

declare
    l_pk_columns varchar2(32767);
begin
    l_pk_columns := apex_db_dictionary.get_primary_key_columns( 
        p_table     => 'EMP', 
        p_delimiter => ':' ); 
end;