PL/SQL Program to Reverse a String

PL/SQL Program to Reverse a String

Here we are going to write a pl/sql program to reverse a string.

In this below program going to use the substr() function. substr() function returns a part of string.

Syntax of substr() function is :-

substr(string, position, length);

We are going to use this function to extract character by character from string in reverse order and concatenate it previous extracted character. || is used to concatenate string.

PL/SQL Program to Reverse a String

  string1 varchar2(50):='tutorialspoint4all';
  string2 varchar2(50);
  len number;
  k number;
  for k in reverse 1..len
    string2:=string2 || substr(string1,k,1);
  end loop;
  dbms_output.put_line('String After Reverse is:'||string2);

Output is

String After Reverse is:lla4tniopslairotut

Leave a Reply

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