Maria
Maria

Reputation: 169

How to retrieve data from Table-Function in DB2

I have a Table Function it return a table of (student_id,student_name)

I want to call it and insert the result into another table

I use

INSERT INTO STUDENT_TMP SELECT Table(MyDB.fn_getStudent())

but i did not get the result I have got an error :

ERROR: DB2 SQL Error: SQLCODE=-390, SQLSTATE=42887,
 SQLERRMC=MyDB.AA;SQL131208155041300,DRIVER=3.67.26 
    Error Code: -390

Upvotes: 2

Views: 3807

Answers (1)

halfbit
halfbit

Reputation: 3939

I found the followin exsample on ibm sites:

select t1.timeid, t1.storeid, t1.sales
from time, store, table (cvsample.salesfunc(time.timeid, store.storeid)) as t1
where time.timeid = t1.timeid and store.storeid = t1.storeid;

notice the syntax: table (cvsample.salesfunc(time.timeid, store.storeid)) as t1

so you prob dont need fields and 'as' you still need '*' and the 'FROM'

so

INSERT INTO STUDENT_TMP SELECT * FROM Table (MyDB.fn_getStudent())

Upvotes: 2

Related Questions