473,408 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Function not returning values ( Sometimes??)

Hi all

My function return the a customer address. Some customers has got 2 then it doesn't return any values. The cust with one value does return the correct value. How can I fix this. Here is my Script

Function

Expand|Select|Wrap|Line Numbers
  1. CREATE or replace FUNCTION get_add(acc_no IN varchar) 
  2.    RETURN varchar 
  3.    IS 
  4.        C_CONTACT1_NEW VARCHAR(50);
  5.  
  6.  
  7. BEGIN 
  8.  
  9.  
  10. SELECT C_CONTACT1
  11. into 
  12. C_CONTACT1_NEW
  13.  
  14. FROM orders A
  15. where a.consigneekey = acc_no
  16.  
  17. group by C_CONTACT1
  18.  
  19.  
  20.    RETURN(C_CONTACT1_NEW); 
  21.  END;
  22.  
Execute with this.

Expand|Select|Wrap|Line Numbers
  1. SELECT get_add('002358-C') FROM DUAL; 
  2.  
  3.  
Nov 25 '11 #1
3 2484
rski
700 Expert 512MB
If some customers has more than one address then what should be returned, both of them? Tipical functions can return only one value so you will have to merge both addresses into one and return it or use pipelined functions. If you use pipelined functions you will be abel to get all values the function returns by querying it
select * from TABLE(<function_name>).
The pipelined function may look like that (be aware I didn't test it)

Expand|Select|Wrap|Line Numbers
  1. CREATE or replace FUNCTION get_add(acc_no IN varchar)  
  2.  RETURN varchar  
  3. PIPELINED
  4.  IS  
  5.        C_CONTACT1_NEW VARCHAR(50); 
  6. BEGIN  
  7. FOR C_CONTACT1_NEW IN SELECT C_CONTACT1 into C_CONTACT1_NEW 
  8.   FROM orders A 
  9.   where a.consigneekey = acc_no 
  10.   group by C_CONTACT1 
  11. LOOP
  12.  PIPE row(C_CONTACT1_NEW);  
  13. END LOOP 
  14. RETURN
  15. END;
  16.  
Nov 25 '11 #2
It must show both values. I tried creating the function with your code but got an error at the line

FOR C_CONTACT1_NEW IN SELECT C_CONTACT1 into C_CONTACT1_NEW



PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:

( - + case mod new null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
reverse avg c


Any help in this would be appreciated.
Nov 28 '11 #3
rski
700 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. create type row_type as object ( i varchar2(50));
  2. create type table_type as table of row_type;
  3.  
  4.  
  5. create or replace function f_test(acc_no varchar)
  6. return object_table_type
  7. pipelined
  8. as
  9. C_CONTACT1_NEW VARCHAR(50);  
  10. begin
  11.  
  12.  
  13. FOR C_CONTACT1_NEW IN (SELECT C_CONTACT1 into C_CONTACT1_NEW  
  14.   FROM orders A  
  15.   where a.consigneekey = acc_no  
  16.   group by C_CONTACT1)
  17. loop
  18. pipe row(object_row_type(C_CONTACT1_NEW.C_CONTACT1));
  19. end loop;
  20. return;
  21. end;
  22.  
But why do you need a function? You can return all values you need with simple sql query, the one you use in LOOP.
Nov 28 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Golawala, Moiz M (GE Infrastructure) | last post by:
Hi All, I am having problem returning values from a Stored Procedure that creates a dynamic table (table variable) inserts values during a procedure and then I select from that dynamic table to...
3
by: Jochen Zeischka | last post by:
I'm puzzled. When compiling this: template<class ValRes, class Val1, class Val2> Veld<ValRes>& mult(Veld<ValRes>& res, const Veld<Val1>& v1, const Veld<Val2>& v2) { // something return res; }...
4
by: Siemel Naran | last post by:
Hi. I have found one advantage of returning values through the argument list. It's that we have to store the return value. But when we return by value, we may forgot to store the return value. ...
5
by: shyam | last post by:
Hi All I have to write a function which basically takes in a string and returns an unknown number( at compile time) of strings i hav the following syntax in mind char *tokenize(char *) ...
2
by: Tany | last post by:
How can I declare function returning array of Integer pointers . Please help !!
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
14
by: Fabian Steiner | last post by:
Hello! I have got a Python "Device" Object which has got a attribute (list) called children which my contain several other "Device" objects. I implemented it this way in order to achieve a kind...
3
by: John Turner | last post by:
typedef void (*vfp)(); typedef vfp (*fp)(); static fp hello() { printf("Hello.\n"); return (fp)&hello; } main(){
4
by: barcaroller | last post by:
I am trying to adopt a model for calling functions and checking their return values. I'm following Scott Meyer's recommendation of not over-using exceptions because of their potential overhead. ...
1
by: ziycon | last post by:
I'm getting to grips with ASP Classic using VBScript. I'm having a problem with returning values from a function. No matter what I do I can't return values from another function to store in a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.