41.14. 对象名称搜索规则

  1. 包中的变量和列名称相同时,优先列名


    create table test(a int);
    insert into test values(1);

    CREATE OR REPLACE function GET_AVG_PRICE()
      RETURN text IS

      a int;
    BEGIN
        --    列名      包变量
       select  a   into   a       from test limit 1;
       dbms_output.put_line(a);
       
       
       return a || '';
    END GET_AVG_PRICE;
    /
  1. 包名和表名有重复时,优先表名(23.3版本禁止重复)

    
    create table tn (id int);
    
    create package tn IS
    id text;
    end;
    /
    
    
    CREATE OR REPLACE function abc()
      RETURN text IS
    
      a tn.id%type; -- 引用表 类型为int
      v text;
    BEGIN
       select  pg_typeof(a) into v ;
       dbms_output.put_line(v);
    
    
       return v;
    END abc;
    /
    

另外包名和schema名称不允许重复,所以不存在冲突的情况。