I need to convert below function from DB2 to Oracle, can anybody help? I have no idea about DB2 :
CREATE FUNCTION READMSGS( SOURCE_NAME VARCHAR(12), SOURCE_SCHEMA VARCHAR(12), SOURCE_VERSION VARCHAR(64), EXPLAIN_LEVEL CHAR(1))
RETURNS TABLE ( ID varchar(20),
DEPTNUM INT,
AVGSAL DECIMAL (9,2),
EMPCNT INT,
WORKDEPT INT )
LANGUAGE SQL
DETERMINISTIC
NO EXTERNAL ACTION
READS SQL DATA
RETURN
SELECT ID,
DEPTNUM,
AVGSAL,
EMPCNT,
WORKDEPT
FROM EMP3 ;
All Parameters are unused which bit weird.You need to remove them if they are unused.
It looks simple to me it is simply returning a custom table/type from function. Here is my weak effort to solve your question
1st step would be to create custom type if you don't have any
create or replace type CustomerType(
ID Varchar2(20),
DEPTNUM Number,
AVGSAL Number,
EMPCNT Number,
WORKDEPT Number
);
Secondly modified function in plsql
FUNCTION EXPLAINSMSGS(SOURCE_NAME in VARCHAR2,SOURCE_SCHEMA in VARCHAR2, SOURCE_VERSION in VARCHAR2,EXPLAIN_LEVEL in Varchar2) return record is
l_customType CustomerType;
l_ID Varchar2(20);
l_DEPTNUM Number;
l_AVGSAL Nubmer;
l_EMPCNT Number,
l_WORKDEPT Varchar2(100);
Begin
SELECT ID,
DEPTNUM,
AVGSAL,
EMPCNT,
WORKDEPT
INTO l_ID,
l_DEPTNUM,
l_AVGSAL,
l_EMPCNT,
l_WORKDEPT
FROM EMP3 ;
l_customType :=CustomerType(l_ID,l_DEPTNUM,l_AVGSAL,l_EMPCNT,l_WORKDEPT);
Return l_customType;
End;
The DB2 function is declared as DETERMINISTIC. It means it will return the same set of rows for n number of invocation. Glancing through this DB2 code, you will not need a function in Oracle, rather create a view for the select statement as in
CREATE VIEW explainmsgs AS SELECT id, deptnum, avgsal, empcnt, workdept FROM emp3 /
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.