How to reverse string without using string function?

Questions by vinit0180

Showing Answers 1 - 12 of 12 Answers

Madhava Reddy

  • May 23rd, 2013
 

Code
  1. begin

  2. declare @inputstring varchar(100),@var1 int,@reversestring varchar(100),@string2 varchar(100)

  3. SELECT @inputstring = REVERSE

  4. SELECT @var1 = LEN(@inputstring)

  5. WHILE (@var1 > 0)

  6. begin

  7. SELECT @string2 = SUBSTRING(@inputstring,@var1,1)

  8. SELECT @inputstring = SUBSTRING(@inputstring,1,@var1-1)

  9. SELECT @reversestring = isnull(@reversestring,)+ISNULL(@string2,)

  10. SELECT @var1 =@var1 -1

  11. end

  12. SELECT @reversestring

  13. end



  Was this answer useful?  Yes

lviswanath

  • Jul 18th, 2013
 

You can do by this way

Code

  1. V_STR VARCHAR2(10);   --you can specify your own size

  2. V_STR_REV VARCHAR2(10); --specify same size as v_str


  3. V_STR := &string;

  4. DBMS_OUTPUT.PUT_LINE(Given String: ||V_STR);

  5. FOR i IN 1..LENGTH(V_STR) LOOP

  6. V_STR_REV := V_STR_REV||SUBSTR(V_STR,-i,1);

  7. DBMS_OUTPUT.PUT_LINE(V_STR_REV);


  8. DBMS_OUTPUT.PUT_LINE(The REVERSE String FOR given ||v_str|| IS: ||V_STR_REV);

  9. END;

anandkiran

  • Sep 10th, 2013
 

Use simple decremented for loop with an variable

Code
  1.             String x = "";

  2.             String s = "test";

  3.             for (int i = s.Length - 1; i >= 0; i--)

  4.             {

  5.  

  6.                 x = x + s[i];

  7.             }

  8.  Console.WriteLine(x);

  Was this answer useful?  Yes

PANKAJ

  • Jul 23rd, 2014
 

Code
  1. #include<iostream>

  2. #include<conio.h>

  3. using namespace std;

  4. int main()

  5. {

  6.     int i;

  7.     char *name="pankaj";

  8.     for(i=0;*(name+i)!=NULL;i++)

  9.     {

  10.  

  11.     }

  12.     for(int j=i-1;j>=0;j--)

  13.     {

  14.         cout<<*(name+j);

  15.     }

  16.     return 0;

  17. }

  18.  


  Was this answer useful?  Yes

harsh

  • Sep 22nd, 2014
 

Answer:

Code
  1. REVERSE a string IN oracle:

  2.  


  3. V_string VARCHAR2(10):=SRIRAM;

  4. V_reverse VARCHAR2(10):=NULL;

  5. V_string1 VARCHAR2(10);

  6. v_count NUMBER;


  7. v_count:=LENGTH(V_string);

  8. DBMS_OUTPUT.PUT_LINE(v_count);

  9. FOR CountCurr IN  REVERSE 1..v_count


  10. DBMS_OUTPUT.PUT_LINE(CountCurr);

  11. V_string1:=SUBSTR(V_string,CountCurr,1);

  12. V_reverse:=V_reverse||V_string1;

  13. DBMS_OUTPUT.PUT_LINE(V_reverse);


  14. --DBMS_OUTPUT.PUT_LINE(V_reverse);


  15. /

  Was this answer useful?  Yes

DECLARE
input varchar2(30);
reverse varchar2(30);
n integer(3);
BEGIN
input:=&input;
for n in reverse 1..length(input) loop
reverse:=reverse||substr(input,n,1);
end loop;
dbms_output.put_line(reverse);
end;
/

  Was this answer useful?  Yes

Senthil

  • Jul 9th, 2016
 

Code
  1. DECLARE @revString VARCHAR(55)=

  2. DECLARE @string2 VARCHAR(55)=REVERSE string WITHOUT REVERSE() FUNCTION

  3. DECLARE @ln INT=LEN(@string2)

  4. WHILE @ln > 0

  5. BEGIN

  6.         SET @revString = @revString + SUBSTRING(@string2, @ln, 1)

  7.         SET @ln= @ln - 1

  8. END

  9. SELECT @string2, @revString,@ln

  Was this answer useful?  Yes

vishalNair

  • Aug 15th, 2016
 

DECLARE
WORD VARCHAR(30):=ANUPAMA;
NEW_WORD VARCHAR(30);
X NUMBER(10) :=0;
BEGIN
X:=LENGTH(WORD);
FOR Y IN 0 ..X-1
LOOP
Z:=SUBSTR(WORD,X-Y,1) ;
NEW_WORD : = NEW_WORD||Z;
DBMS_OUTPUT.PUT_LINE(WORD IS ||NEW_WORD)
END LOOP;
END;

  Was this answer useful?  Yes

pradeep

  • Nov 22nd, 2016
 

set serveroutput on
DECLARE
WORD VARCHAR(30):=ANUPAMA;
NEW_WORD VARCHAR(30);
X NUMBER(10) :=0;
BEGIN
X:=LENGTH(WORD);
FOR Y IN 0 ..X-1
LOOP
NEW_WORD :=SUBSTR(WORD,X-Y,1);
DBMS_OUTPUT.PUT_LINE(WORD IS ||NEW_WORD);
END LOOP;
END;

  Was this answer useful?  Yes

Hemanth

  • Nov 26th, 2016
 

Code
  1. DECLARE

  2. V_VAR1 VARCHAR2(30) := welcome;

  3. V_VAR2 VARCHAR2(30);

  4. BEGIN

  5. FOR I IN REVERSE 0..LENGTH(V_VAR1)-1 LOOP

  6. V_VAR2 := V_VAR2|| SUBSTR(V_VAR1,I,1);

  7. END LOOP;

  8. DBMS_OUTPUT.PUT_LINE(V_VAR2);

  9. END;

  Was this answer useful?  Yes

Gyanaranjan Mishra

  • Jan 9th, 2017
 

In a simpler way
--reverse a string
DECLARE
my_string VARCHAR2(100):=ODISHA;
new_string VARCHAR2(100);
BEGIN
FOR i IN REVERSE 1..Length(my_string)
LOOP
new_string:=new_string||SubStr(my_string,i,1);
-- Dbms_Output.put_line(new_string);
END LOOP;
Dbms_Output.put_line(new_string);
END;
/

  Was this answer useful?  Yes

Dhanyaa

  • Jan 13th, 2017
 

SELECT REVERSE(WELCOME) FROM DUAL;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions