473,498 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can we create UDF using View instead of table

Hi everybody!
I have a UDF. It is working fine.
But when i try apply the same UDF to a view it is not working.
CREATE VIEW SSN_SORTED AS
WITH TEMP(EMP#,SOCSEC#,JOB_FTN,DEPT,SALARY,DATE_BN,FST_ NAME,LST_NAME) AS
(SELECT MAX(EMP#),MAX(SOCSEC#),MAX(JOB_FTN),MAX(DEPT),MAX( SALARY),MAX(DATE_BN)
,MAX(FST_NAME),MAX(LST_NAME)
FROM PERSONNEL
GROUP BY SOCSEC#
FETCH FIRST 20000 ROWS ONLY)
SELECT * FROM TEMP;

Here is UDF fow paging this veiw:
CREATE VIEW SSN_SORTED AS
WITH TEMP(EMP#,SOCSEC#,JOB_FTN,DEPT,SALARY,DATE_BN,FST_ NAME,LST_NAME) AS
(SELECT MAX(EMP#),MAX(SOCSEC#),MAX(JOB_FTN),MAX(DEPT),MAX( SALARY),MAX(DATE_BN)
,MAX(FST_NAME),MAX(LST_NAME)
FROM PERSONNEL
GROUP BY SOCSEC#
FETCH FIRST 20000 ROWS ONLY)
SELECT * FROM TEMP;

UDF example of use:
SELECT * FROM TABLE(GET_PAGES_SSN('000-00-0000'))
FETCH FIRST 20 ROWS ONLY;

sqlcode: -440
No authorized routine named "GET_PAGES_SSN" of type "FUNCTION
" having compatible arguments was found.
Here is same UDF working without any problem with Tables:

CREATE FUNCTION GET_PAGES(PAGE_NO INTEGER,LINES INTEGER)
RETURNS TABLE ( EMP# INTEGER
,SOCSEC# CHAR(11)
,JOB_FTN CHAR(4)
,DEPT SMALLINT
,SALARY DECIMAL(7,2)
,DATE_BN DATE
,FST_NAME VARCHAR(20)
,LST_NAME VARCHAR(20)
)
RETURN
Select *
from
PERSONNEL
where
INTEGER(SUBSTR((CHAR(EMP#)),1,7)) >= LINES * (PAGE_NO - 1) + 1000000;

EXAMPLE OF USE
SELECT * FROM TABLE(GET_PAGES(3,12))
FETCH FIRST 12 ROWS ONLY;
EMP# SOCSEC# JOB_FTN DEPT SALARY DATE_BN FST_NAME
LST_NAME
----------- ----------- ------- ------ --------- ---------- -----------------
--- --------------------
2000000 182-27-6668 WKR 27 12712.08 02/04/1973 Fehdcd
Eamitaaa
2000001 360-75-6667 WKR 33 12739.97 02/04/1973 Tjiddd
Jeiitaya
2000002 223-88-6663 WKR 20 3143.58 01/01/1978 Xffabc
Feabaimm
2000003 599-41-6664 WKR 18 4255.15 01/02/1977 Jpebbb
Piybeabb
.................................................. ............................
.................................................. ......
Thank's in advance.

--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....m-db2/200809/1

Sep 6 '08 #1
2 2856
>SELECT * FROM TABLE(GET_PAGES_SSN('000-00-0000'))
FETCH FIRST 20 ROWS ONLY;

sqlcode: -440
No authorized routine named "GET_PAGES_SSN" of type "FUNCTION
" having compatible arguments was found.
You did not describe any function named get_pages_ssn(VARCHAR()) in your
post.
Only get_pages(integer, integer)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Sep 7 '08 #2
Thank you Serge.
I fixed and it is working.

Serge Rielau wrote:
>>SELECT * FROM TABLE(GET_PAGES_SSN('000-00-0000'))
FETCH FIRST 20 ROWS ONLY;

sqlcode: -440
No authorized routine named "GET_PAGES_SSN" of type "FUNCTION
" having compatible arguments was found.

You did not describe any function named get_pages_ssn(VARCHAR()) in your
post.
Only get_pages(integer, integer)

Cheers
Serge
--
Message posted via http://www.dbmonster.com

Sep 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1769
by: kackson | last post by:
Hi. I created a simple view with the following statements: CREATE VIEW dbo.VIEW1 AS SELECT dbo.VIEW_ALL.ID, dbo.VIEW_ALL.Code, Another.dbo.OTHER_VIEW.Label as SpecialCode FROM ...
1
1842
by: aur56 | last post by:
I am using stringbuilder to create a html email message that is basically a two column table with the field name in one column, and the field value in another, and about 30 rows. I don't get any...
6
12257
by: Bruce | last post by:
I want to create a new table based on an existing table, but I don't want the tables to have any enforced relationship. Is this possible without having to do a CREATE TABLE and an INSERT? ...
7
8819
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
10
8769
by: Zack Sessions | last post by:
Has anyone tried to create a SQL7 view using the CREATE VIEW command and ADO.NET? If so, is there a trick in trapping a SQL error when trying to create the view? I have a VB.NET app that, amoung...
2
8911
by: Curtiosity | last post by:
I have done a create or replace view called creditcard1. If I do a "select * from creditcard1" it retrieves the data just fine. If I try to do a statement where I am listing the column names it...
2
35044
by: Shirley | last post by:
We are running DB2 on iSeries V5R2. Using AQUA DATA STUDIO with a connection to our iSeries, I created a view using SQL and I am trying to create an index on this view using the code below. ...
4
22678
by: cognosqueen | last post by:
I need to create a view of a sql table, but change the data types. I know the syntax below is not correct, and can't figure out if it is wrong or if you just can't do this. I have only created...
3
3953
by: suek | last post by:
I have a table with over 4000 records to search upon, and the users don't like a combo box. So what I have been trying to do for the last twelve hours is do some code to get a text box to search. ...
0
7125
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
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6890
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
7379
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...
1
4915
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...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.