I have a hard time looking for correct syntax to create a function with variables and if condition.
create or replace
FUNCTION createURL( IDName IN varchar2, IDValue IN number )
RETURN VARCHAR2
IS
ApplicationURL VARCHAR2(100);
AppplicationParm VARCHAR2(255);
DBName VARCHAR(100);
BEGIN
select sys_context('USERENV','DB_NAME') AS Instance into DBName FROM DUAL;
IF DBName = 'WAMDEV' THEN ApplicationURL := 'http://srpwam10:080/maxi';
ELSIF DBName ='WAMDEVPJ' THEN ApplicationURL := 'http://srpwam10:080/maxi';
ELSIF DBName = 'WAMTST' THEN ApplicationURL := 'http://wamtest/maxi';
ELSIF DBName = 'WAMTSTPJ' THEN ApplicationURL := 'http://wamtest/maximo';
ELSIF DBName = 'WAMQA' THEN ApplicationURL := 'http://wamqa/maxi';
ELSIF DBName = 'WAMQAPJ' THEN ApplicationURL := 'http://wamqa/maximo';
ELSE DBName := 'WAMP'; ApplicationURL := 'http://wam/maxi';
END IF ;
IDN := IDName;
IF IDN = 'workorderid' THEN AppplicationParm := '/ui/?event=loadapp' || CHR(38) || 'value=wotrack' || CHR(38) || 'uniqueid=' || TO_CHAR(IDValue);
ELSIF IDN = 'assetuid' THEN AppplicationParm := '/ui/?event=loadapp' || CHR(38) || 'value=asset' || CHR(38) || 'uniqueid=' || TO_CHAR(IDValue);
ELSIF IDN = 'locationsid' THEN AppplicationParm := '/ui/?event=loadapp' || CHR(38) || 'value=location' || CHR(38) || 'uniqueid=' || TO_CHAR(IDValue);
ELSE AppplicationParm := '/ui/?event=loadapp' || CHR(38) || 'value=sr' || CHR(38) || 'uniqueid=' || TO_CHAR(IDValue);
END IF;
RETURN 'javascript:void(window.open(''' || ApplicationURL || ApplicationParm || ''',''_blank''))';
END;
I'm not sure if the code is correct and what's the problem? I can not creat the function. Your help will be great appreciated.
IDN := IDName;- you haven't defined a variable calledIDN. However, you could just useIDNAMEdirectly in the comparisons, rather than creating a variable just to do the comparisons. E.g.if idname = ... elsif idname = ...