Function to display reverse string of the given string in PL/SQL

VijayaTech Labs Blog

CREATE OR REPLACE FUNCTION rev_str_f(str VARCHAR2) RETURN VARCHAR2
IS
v_str VARCHAR2(10);   –you can specify your own size
v_str_rev VARCHAR2(10); –specify same size as v_str
BEGIN
v_str := ‘&string’;
DBMS_OUTPUT.PUT_LINE(‘Given String: ‘||v_str);
FOR i IN 1..LENGTH(v_str) LOOP
v_str_rev := v_str_rev||SUBSTR(v_str,-i,1);
DBMS_OUTPUT.PUT_LINE(v_str_rev);
END LOOP;
DBMS_OUTPUT.PUT_LINE(‘The reverse String for given ‘||v_str||’ is: ‘||v_str_rev);
RETURN v_str_rev;
END rev_str_f;

Share this post with your friends

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top