Hi experts,
I have T-SQL funtion, here the query is used to list the data separated by comma.how can we write in PL/SQL.
role
table for example: -------
audit
cement
mason
result should be: audit,cement,ma son.
ALTER FUNCTION dbo.fnGetRolesB yEmployeeID
(
@EmployeeID uniqueidentifie r
)
RETURNS varchar(max)
AS
BEGIN
DECLARE @Roles varchar(max)
SELECT @Roles = COALESCE(@Roles + ' , ', '') + R.Role
FROM Employees AS E LEFT OUTER JOIN
UsersInRoles AS U ON E.EmployeeID = U.UserID LEFT OUTER JOIN
Roles AS R ON U.RoleID = R.RoleID
WHERE (E.EmployeeID = @EmployeeID)
RETURN @Roles
END
I Converted in pl/SQL like this,
create or replace
FUNCTION fnGetRolesByEmp loyeeID
(
v_EmployeeID IN char
)
RETURN VARCHAR2
AS
v_Roles VARCHAR2(4000);
BEGIN
SELECT coalesce(v_Role s || ' , ', '') || R.ROLE
INTO v_Roles
FROM Employees E
LEFT JOIN UsersInRoles U
ON E.EmployeeID = U.UserID
LEFT JOIN Roles R
ON U.RoleID = R.RoleID
WHERE ( E.EmployeeID = v_EmployeeID ) ;
RETURN v_roles;
END;
but this query not fetches two values , could any one provide the solution, it would be appreciated.
I have T-SQL funtion, here the query is used to list the data separated by comma.how can we write in PL/SQL.
role
table for example: -------
audit
cement
mason
result should be: audit,cement,ma son.
ALTER FUNCTION dbo.fnGetRolesB yEmployeeID
(
@EmployeeID uniqueidentifie r
)
RETURNS varchar(max)
AS
BEGIN
DECLARE @Roles varchar(max)
SELECT @Roles = COALESCE(@Roles + ' , ', '') + R.Role
FROM Employees AS E LEFT OUTER JOIN
UsersInRoles AS U ON E.EmployeeID = U.UserID LEFT OUTER JOIN
Roles AS R ON U.RoleID = R.RoleID
WHERE (E.EmployeeID = @EmployeeID)
RETURN @Roles
END
I Converted in pl/SQL like this,
create or replace
FUNCTION fnGetRolesByEmp loyeeID
(
v_EmployeeID IN char
)
RETURN VARCHAR2
AS
v_Roles VARCHAR2(4000);
BEGIN
SELECT coalesce(v_Role s || ' , ', '') || R.ROLE
INTO v_Roles
FROM Employees E
LEFT JOIN UsersInRoles U
ON E.EmployeeID = U.UserID
LEFT JOIN Roles R
ON U.RoleID = R.RoleID
WHERE ( E.EmployeeID = v_EmployeeID ) ;
RETURN v_roles;
END;
but this query not fetches two values , could any one provide the solution, it would be appreciated.
Comment