Here is part of my PL/SQL block:
ACCEPT create_like_user PROMPT 'Enter CREATE LIKE user ID: '
ACCEPT new_user PROMPT 'Enter new user ID to create: '
VARIABLE s_grantee VARCHAR2(256)
DECLARE
CURSOR all_user_cur IS
SELECT distinct grantee
FROM dba_role_privs
WHERE grantee = UPPER('&create_like_user')
AND grantee NOT IN (SELECT role FROM dba_roles)
ORDER BY grantee;
CURSOR all_defrol_cur IS
SELECT granted_role
FROM dba_role_privs
WHERE grantee = :s_grantee
AND default_role = 'NO'
ORDER BY granted_role;
BEGIN
FOR u_name IN all_user_cur
LOOP
dbms_output.put_line('alter user "'||UPPER('&new_user')||
'" default role ALL except ');
:s_grantee := u_name.grantee;
FOR r_name IN all_defrol_cur
LOOP
-- NEED CONDITION HERE TO TEST FOR THE LAST RECORD IN THE CURSOR
-- IF NOT THE LAST RECORD, PRINT THE FOLLOWING LINE
dbms_output.put_line(' '||r_name.granted_role||',');
-- IF ON THE LAST RECORD, PRINT THIS LINE INSTEAD
-- (i.e., without the ',' appended to the end)
dbms_output.put_line(' '||r_name.granted_role);
END LOOP;
dbms_output.put_line(' '||';');
END LOOP;
END;
/
I have added comments in the code where I need a conditional statement to print one line if it is not the last record and the other line if it is the last record.
Appreciate any help you can provide. I have not found any documentation that provides a clear example for what I am trying to accomplish. I'm new to PL/SQL.
Thanks!
ACCEPT create_like_user PROMPT 'Enter CREATE LIKE user ID: '
ACCEPT new_user PROMPT 'Enter new user ID to create: '
VARIABLE s_grantee VARCHAR2(256)
DECLARE
CURSOR all_user_cur IS
SELECT distinct grantee
FROM dba_role_privs
WHERE grantee = UPPER('&create_like_user')
AND grantee NOT IN (SELECT role FROM dba_roles)
ORDER BY grantee;
CURSOR all_defrol_cur IS
SELECT granted_role
FROM dba_role_privs
WHERE grantee = :s_grantee
AND default_role = 'NO'
ORDER BY granted_role;
BEGIN
FOR u_name IN all_user_cur
LOOP
dbms_output.put_line('alter user "'||UPPER('&new_user')||
'" default role ALL except ');
:s_grantee := u_name.grantee;
FOR r_name IN all_defrol_cur
LOOP
-- NEED CONDITION HERE TO TEST FOR THE LAST RECORD IN THE CURSOR
-- IF NOT THE LAST RECORD, PRINT THE FOLLOWING LINE
dbms_output.put_line(' '||r_name.granted_role||',');
-- IF ON THE LAST RECORD, PRINT THIS LINE INSTEAD
-- (i.e., without the ',' appended to the end)
dbms_output.put_line(' '||r_name.granted_role);
END LOOP;
dbms_output.put_line(' '||';');
END LOOP;
END;
/
I have added comments in the code where I need a conditional statement to print one line if it is not the last record and the other line if it is the last record.
Appreciate any help you can provide. I have not found any documentation that provides a clear example for what I am trying to accomplish. I'm new to PL/SQL.
Thanks!