Re: [ADMIN] How to cal function in in another function

Поиск
Список
Период
Сортировка
От Chandra Sekhar Surapaneni
Тема Re: [ADMIN] How to cal function in in another function
Дата
Msg-id 0F7F9A82BB0DBB4396A9F8386D0E0612011AE78A@pos-exch1.corp.positivenetworks.net
обсуждение исходный текст
Список pgadmin-support
You should try it as follows:
 
create or replace function subfun1(int8) returns record as
'
declare
   rec record;
begin
    select ename as ename,mgr as mgr into rec from emp where empno=$1 ;
    return rec;
end;
'
language'plpgsql';
---------------------------------------------------------
 
select subfun1(22);
   subfun1
-------------
 (swarna,23)
------------------------------------------------------------
 
create or replace function mainfun(int8) returns record as
'
declare
    no record;
    return_rec record;
begin
    no := subfun1($1);  
    select sal,dept into return_rec from emp where mgr=no.mgr limit 1;
    return return_rec;
end;
'
language'plpgsql';
 
-------------------------------------------------
select mainfun(22);
  mainfun
-----------
 (2600,20)
-------------------------------------------------
 
 
Regards,
Chandra Sekhar Surapaneni
 
 


From: pgsql-admin-owner@postgresql.org [mailto:pgsql-admin-owner@postgresql.org] On Behalf Of VivekanandaSwamy R.
Sent: Wednesday, June 28, 2006 3:53 AM
To: pgadmin-support@postgresql.org
Cc: pgsql-admin-owner@postgresql.org
Subject: [ADMIN] How to cal function in in another function

Hi,
i have written these functions....,please go through this...
 
table emp: It contains
 
empno     ename           mgr            sal          dept
-------------------------------------------------------------------------
22            swarna           23             2600            20
 
Now i wrote function(sub function)
 
create or replace function subfun1(int8,out p_mgr int8,out p_name varchar) as
'
begin
select ename,mgr into p_name,p_mgr from emp where empno=$1 ;
end;
'
language'plpgsql';
 
 When i executing this function,it returns like....
select subfun1(22);         returns (23,swarna) as record type
 
Now i want use/call this function in main function
   
create or replace function mainfun(int8,out p_sal int8,out p_dept varchar) as
'
declare
no record;
begin
select subfun1($1) into no;
select sal,dept into p_sal,p_dept from emp where mgr=no.p_mgr limit 1;
end;
'
language'plpgsql';
 
Now when i am executing this function like....
 
select mainfun(22);   returns error message like....
 
    ERROR:  record "no" has no field "p_mgr"
    CONTEXT:  PL/pgSQL function "mainfun" line 5 at select into variables
 
So,how to solve this problem?

 
   
 
       
 
 
 
 

Thanks  &  Regards

Vivekananda.R | Software Engineer           

Infinite Computer Solutions | Exciting Times…Infinite Possibilities...

SEI-CMMI level 5 | ISO 9001:2000

 Tel +91-80-5193-0000| Fax  +91-80-51930009 | Cell No  +91-9986463365|www.infics.com          

 
Information transmitted by this e-mail is proprietary to Infinite Computer Solutions and / or its Customers and is intended for use only by the individual or the entity to which it is addressed, and may contain information that is privileged, confidential or exempt from disclosure under applicable law. If you are not the intended recipient or it appears that this mail has been forwarded to you without proper authority, you are notified that any use or dissemination of this information in any manner is strictly prohibited. In such cases, please notify us immediately at info.in@infics.com and delete this email from your records.

В списке pgadmin-support по дате отправления:

Предыдущее
От: "Dave Page"
Дата:
Сообщение: Re: pgadmin3 segmentation fault
Следующее
От: "Keith C. Perry"
Дата:
Сообщение: Re: How to provide db access to other systems