Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Converting DB2 SQL to Oracle SQL

729366Oct 21 2009 — edited Oct 21 2009
Hi I am currently converting functions, views, and queries from IBM DB2 SQL to Oracle SQL. I ran into a few problems that I am not sure how to solve:

PROBLEM 1:

In the following code, the parameters p_er_id, p_entity_id, and p_dsrc_acct_id are not recognized although the syntax for creating the function is correct. I get the error "P_DSRC_ACCT_ID is an invalid identifier" when it is clearly in the function parameters. I am using EasySQL Checker to validate the SQL since I am currently not given privileges to create functions in the environment:

--get account values
drop function GetAcctVals@
CREATE FUNCTION GetAcctVals (p_er_id bigint, p_entity_id bigint, p_dsrc_acct_id bigint)
RETURNS varchar(5000)
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC
BEGIN ATOMIC

--init vars
declare v_return_value varchar(5000);
set v_return_value='';

--get dsrc_accts
for v_row as
select * from (
select distinct 1 as ord1, a.dsrc_acct_id as ord2, 'ACCT: (' || rtrim(NVL(b.dsrc_code, '')) || ') ' || rtrim(NVL(dsrc_acct, '')) as val
from er_entity_state x
join dsrc_acct a on a.dsrc_acct_id = x.dsrc_acct_id
join dsrc_code b on b.dsrc_id = a.dsrc_id
where x.er_id = p_er_id and x.entity_id = p_entity_id and x.dsrc_acct_id = p_dsrc_acct_id
) z order by ord1, ord2, val;
do
if length(v_return_value || v_row.val || chr(13) || chr(10)) < 5000 then
set v_return_value = v_return_value || v_row.val || chr(13) || chr(10);
end if;
end for;

return v_return_value;
END@

----------------------------------------------------------------------------------------------

PROBLEM 2:

I also get another error with the following query that puzzles me:

SELECT A.dsrc_id,
A.dsrc_code,
B.role_code,
C.res_config_code as er_rule_set,
D.name as can_rule_set
FROM dsrc_code A
JOIN role_code B ON B.role_code_id=A.role_code_id
JOIN resolution_config C ON C.res_config_id=A.mm_config_id
JOIN fast_match D ON D.fast_config_id=A.fast_config_id
ORDER BY a.dsrc_id

I receive the error "ORA-00923: FROM keyword not found where expected". This error only occurs if one of the JOINs are introduced into the statement, a call from the table dsrc_code itself will not generate the error. From my understanding, the same JOIN commands from DB2 work in Oracle, so I don't quite understand the problem.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2009
Added on Oct 21 2009
7 comments
1,049 views