Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Using ALL_CONS_COLUMN view inside a function

RE: Using ALL_CONS_COLUMN view inside a function

From: Yasin Baskan <yasin.baskan_at_yapikredi.com.tr>
Date: Tue, 28 Aug 2007 09:19:43 +0300
Message-ID: <083667B535F3464CA0DD0D1DAFA4E3760E47B0C8@camexc1.kfs.local>

ALL_* views show information related to objects the user has access to. In which schema does your function reside? This function will return results based on the owner of the function. Try using dba_cons_columns.

-----Original Message-----

From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Brett Hammerlindl Sent: Tuesday, August 28, 2007 5:32 AM
To: oracle-l_at_freelists.org
Subject: Using ALL_CONS_COLUMN view inside a function

I hope someone can help me sort out something that makes no sense to me.

I have written an Oracle function that returns a VARCHAR2 (see below) You can see it has a cursor for a select of rows from the ALL_CONS_COLUMN view.

The function works fine when I run with p_owner set to the current user,

but I have hit a snag when I put in other owners.

Here is an example when I run my function with parameters of 'SYS' and 'REGISTRY_PK', it returns a NULL string because no rows are found. BUT when I run this select, I get 2 rows returned.   Select * from ALL_CONS_COLUMNS
   Where owner = 'SYS' and constraint_name = 'REGISTRY_PK'

When I hit this problem, I looked for the simplest case I could find that had a problem. It is based on the statement.   select count(*) cc from all_tables where owner = 'SYS'

The value returned inside a function is 27 while the query returns 703.

This is an Oracle 10g database. I am only using example with SYS as owner
since others can see if they get the same results. I had this problem with p_owner set other users as well.

Does anyone know what is going on?

How do I get a function to return a VARCHAR2 list the column names?

Thank you for the help, Brett

VARCHAR2,   p_constraint_name
VARCHAR2)
  RETURN VARCHAR2 IS

  v_column VARCHAR2(40);
  v_sql    VARCHAR2(1000);
  v_join   VARCHAR2(12) := ' || ''|'' || ';
  cursor column_cursor is
    select *
      from all_cons_columns
     where owner = p_owner
       and constraint_name = p_constraint_name
     order by position;

BEGIN
  for column in column_cursor loop
    v_column := column.column_name;
    if (column.position = 1) then
      v_sql := v_column;
    else
      v_sql := v_sql || v_join || v_column;     end if;
  end loop;
  return v_sql;
END concatenateConstraintColumns;

--

http://www.freelists.org/webpage/oracle-l

Bu mesaj ve onunla iletilen tum ekler gonderildigi kisi ya da kuruma ozel ve Bankalar Kanunu geregince, gizlilik yukumlulugu tasiyor olabilir. Bu mesaj, hicbir sekilde, herhangi bir amac icin cogaltilamaz, yayinlanamaz ve para karsiligi satilamaz; mesajin yetkili alicisi veya alicisina iletmekten sorumlu kisi degilseniz, mesaj icerigini ya da eklerini kopyalamayiniz, yayinlamayiniz, baska kisilere yonlendirmeyiniz ve mesaji gonderen kisiyi derhal uyararak bu mesaji siliniz. Bu mesajin iceriginde ya da eklerinde yer alan bilgilerin dogrulugu, butunlugu ve guncelligi Bankamiz tarafindan garanti edilmemektedir ve bilinen viruslere karsi kontrolleri yapilmis olarak yollanan mesajin sisteminizde yaratabilecegi zararlardan Bankamiz sorumlu tutulamaz.

This message and the files attached to it are under the privacy liability in accordance with the Banking Law and confidential to the use of the individual or entity to whom they are addressed. This message cannot be copied, disclosed or sold monetary consideration for any purpose. If you are not the intended recipient of this message, you should not copy, distribute, disclose or forward the information that exists in the content and in the attachments of this message; please notify the sender immediately and delete all copies of this message. Our Bank does not warrant the accuracy, integrity and currency of the information transmitted with this message. This message has been detected for all known computer viruses thence our Bank is not liable for the occurrence of any system corruption caused by this message
--

http://www.freelists.org/webpage/oracle-l Received on Tue Aug 28 2007 - 01:19:43 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US