Home » Other » Training & Certification » pl/sql
pl/sql [message #304444] Wed, 05 March 2008 04:04 Go to next message
vinaya.v
Messages: 8
Registered: March 2008
Junior Member
1.how to reverse the numbers using pl/sql
for eg
input is 78987345
output should be 54378987

2.how to store values in an array.

3.wat is an varray
Re: pl/sql [message #304451 is a reply to message #304444] Wed, 05 March 2008 04:31 Go to previous messageGo to next message
Michel Cadot
Messages: 64102
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
PL/SQL User's Guide and Reference
Application Developer's Guide - Fundamentals

"Suggestions & Feedback" is not the correct forum to post your question.
Next time post it in "SQL & PL/SQL Newbies" or "Homework" one.

Also always post what you already tried and where you are stuck.

Regards
Michel

[Updated on: Wed, 05 March 2008 04:33]

Report message to a moderator

Re: pl/sql [message #304459 is a reply to message #304444] Wed, 05 March 2008 05:16 Go to previous messageGo to next message
mshrkshl
Messages: 247
Registered: September 2006
Location: New Delhi
Senior Member
use reverse.

e.g
select reverse(78987345) from dual;


regards,

[Updated on: Wed, 05 March 2008 05:18]

Report message to a moderator

Re: pl/sql [message #304467 is a reply to message #304459] Wed, 05 March 2008 05:51 Go to previous messageGo to next message
Littlefoot
Messages: 20888
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Just beware of use of undocumented features (REVERSE function is one of them); there's no guarantee that it will work in any of the future releases. So, relying your code on something undocumented perhaps isn't that good idea.
Re: pl/sql [message #304477 is a reply to message #304467] Wed, 05 March 2008 06:18 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
using sql to reverse the number:
you can make use of the SUBSTR()to generate a row and then use SYS_CONNECT_BY_PATH().

regards,
Re: pl/sql [message #304484 is a reply to message #304459] Wed, 05 March 2008 06:36 Go to previous messageGo to next message
Michel Cadot
Messages: 64102
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
@mshrkshl

Does it happens that sometimes you post correct answer?
SQL> select reverse(78987345) from dual;
                                 REVERSE(78987345)
--------------------------------------------------
               -0000000000000000000000000000000000

1 row selected.

Regards
Michel

Re: pl/sql [message #304650 is a reply to message #304444] Thu, 06 March 2008 00:44 Go to previous messageGo to next message
mshrkshl
Messages: 247
Registered: September 2006
Location: New Delhi
Senior Member
SQL> ed
Wrote file afiedt.buf

  1  declare
  2   inputstring varchar2(100) :='78987345';
  3   outputstring varchar2(1);
  4   n number;
  5  begin
  6  for n in 1..length(inputstring)
  7   loop
  8    select substr(inputstring,length(inputstring)-n+1,1) into outputstring from dual;
  9    dbms_output.put(outputstring);
 10   end loop;
 11    dbms_output.put_line(' ');
 12* end;

SQL> /

54378987

PL/SQL procedure successfully completed.


regards,
Re: pl/sql [message #304656 is a reply to message #304650] Thu, 06 March 2008 01:01 Go to previous messageGo to next message
Michel Cadot
Messages: 64102
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
The input is not a string it is a number.

Same remark. Frown Sad

Regards
Michel

[Updated on: Thu, 06 March 2008 01:03]

Report message to a moderator

Re: pl/sql [message #304710 is a reply to message #304444] Thu, 06 March 2008 05:46 Go to previous messageGo to next message
mshrkshl
Messages: 247
Registered: September 2006
Location: New Delhi
Senior Member
SQL> ed
Wrote file afiedt.buf

  1  declare
  2     input number :=78987345;
  3     output number(1);
  4    n number;
  5    begin
  6    for n in 1..length(input)
  7     loop
  8      select substr(input,length(input)-n+1,1) into output from dual;
  9      dbms_output.put(output);
 10     end loop;
 11      dbms_output.put_line(' ');
 12*  end;
SQL> /
54378987

PL/SQL procedure successfully completed.


regards,
Re: pl/sql [message #304714 is a reply to message #304710] Thu, 06 March 2008 05:54 Go to previous message
Michel Cadot
Messages: 64102
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
"length" takes a string as (first) parameter as well as "substr".
NEVER rely on implicit conversion.

Regards
Michel
Previous Topic: Help with SUM query..?
Next Topic: need guidence
Goto Forum:
  


Current Time: Fri Dec 02 20:47:03 CST 2016

Total time taken to generate the page: 0.14497 seconds