Reverse Of any number,Fibonacci sequence

hi all,
Can i find the reverse of any number and Fibonacci sequence in a SELECT query
without using pl/sql and reverse function.
please reply...

Hi,
extreme wrote:
... can you give me example for both 10g and 11gR2 recursive sub-queriesRecursive sub-queries were introduced in Oaracle 11.2; there are no recursive sub-queries in earlier versions.
Here's one way of getting the reverse of a NUMBER in Oracle 10 (and up):
WITH     got_txt     AS
     SELECT     TO_CHAR (12345, 'TM')     AS txt
     FROM     dual
,     exploded_txt     AS
     SELECT     LEVEL               AS pos
     ,     SUBSTR (txt, LEVEL, 1)     AS a_char
     FROM     got_txt
     CONNECT BY     LEVEL <= LENGTH (txt)
SELECT  TO_NUMBER ( REPLACE ( XMLAGG ( XMLELEMENT ( e
                                          , a_char
                                      ).EXTRACT ('//text()')
                             ORDER BY  pos     DESC
            )     AS reverse_num
FROM    exploded_txt
;As written, this only does one number per query. It can be adapted to do several numbers at the same time, but it's somewhat messier.
Starting in 11.2, you cn also use a recursive sub-query, as show below.
This method can easily handle multiple numebrs in the same query. You'll probably get them from one of your existing tables, not hard-coded in a sub-query, like sample_data, below:
WITH     sample_data AS
     SELECT  12345     AS n     FROM dual     UNION ALL
     SELECT     30.2             FROM dual     UNION ALL
     SELECT     0          FROM dual
,     got_txt (n, step, txt, reverse_txt)     AS
     SELECT     n
     ,     1                    AS step
     ,     TO_CHAR (n, 'TM')          AS txt
     ,     SUBSTR ( TO_CHAR (n, 'TM')
                 , 1
                 , 1
                 )               AS reverse_txt
     FROM    sample_data
    UNION ALL
     SELECT     n
     ,     step + 1          AS step
     ,     txt
     ,     SUBSTR ( txt
                 , step + 1
                 , 1
                 ) || reverse_txt     AS reverse_txt
     FROM    got_txt
     WHERE     step     < LENGTH (txt)
SELECT     n
,     TO_NUMBER (reverse_txt)     AS reverse_n
FROM     got_txt
WHERE     step     = LENGTH (txt)
;A somewhat simpler problem is how to reverse a given string.
As you can see, boith of the approaches above start by converting the given number to a string, and end by converting it back to a NUMBER, to meet your requirements.
Neither version (as posted) handles negative numbers properly. Both can be adapted to do so.

Similar Messages

  • POPULATE NUMBER IN SEQUENCE BUTTON

    Hi All, slightly more taxing questions for you I hope.
    I have created a PDF form to be used on mobile devices. Each time the form is filled that form needs to be individually numbered with an alpha-numeric code.
    Currently I have a field that states "form number" and the user types in ABC001 (for the first time they fill it in) ABC002 the next time etc etc....
    How do I add a button so the number will auto populate with the next number in sequence, remembering they may not have internet or network connectivity? I know it's possible but don't know how to write C++ or Java (or any other code).
    Thanks in advance
    Luke

    This can be done in XSL OR in procedure on the DB side. Performance wise better to do in procedure as mentioned by other use. You can choose to go with DB or XSL approach depending on number of orders you are expecting in a single message. If it is going to be 100s or few thousand messages then keeping it in XSL is not a problem. But if you are planning tens or hundreds of thousands of orders in the same request then better do it in stored procedure.
    How do you do in XSL?
    1. Put a for each on every unique order no. You can use xsl:Key or xslt:distinct-values() for this.
    2. Within for each unique value of order no, use position() function to pass line/order no as 1,2,3... etc. As soon as the loop moves to second iteration for the next unique order no, count will automatically start again from 1,2,3... and so on.
    Apart from slightly slower processing time, another drawback from this approach is that the data in the XML you send to DB procedure will be sorted by order numbers. All orders with same number will appear together.
    Another problem with this approach is that this will work only within one request, i.e. if the next request contains an order with same no which was already sent in a previous request, for this order the count will again start from 1. So if you want to keep the sequencing maintained across multiple requests, the easiest way to do is in the DB procedure where you can lookup in the table before inserting a new row and insert with next sequence of that order no.

  • Replace the hidden step property Id (GUID) by a unique integer number on sequence level.

    Hi,
    I want to log TestStand data into an existing SQL database.
    The step ID in my database is an integer (Integer data van -2^31 (-2.147.483.648) tot 2^31-1 (2.147.483.647)),
    so a GUID id does not fit in this field.
    Is it possible to change the GUID id to a unique integer number on sequence level? TestStand should stuff the integer id automatically while inserting steps…
    If a number field is added to the test steps definitions, is it possible that TestStand automatically fills the numeric step ID for each instance of the test steps in the sequence while inserting the step?
    Best regards

    You could use the index and step group of the step to create a numeric id, but it will change as soon as any step is inserted before the step.
    If you absolutely can't change your database and have to make it work, you could always generate/update a map of GUID to integer id for each sequence, perhaps at runtime from the first step in the sequence. Basically, have the first step create or update the mapping. You'd also likely need to store a last used id so you know what id to start with when you add anything to the map.
    Really probably the best solution is to change the database though. If you really want a unique ID per step that survives inserting new steps before it, then a GUID is a much simpler way to go.
    Hope this helps,
    -Doug

  • Generate an unique number without sequence

    Hello,
    I need generate an unique number without sequence. I am using Oracle 11.2, here is the details. The column idSeq is unique withing one specific idType. I don't want a sequence for each idType.
    create table tb_test (idSeq number(5), idType number(5), addr varchar2(256));
    insert into tb_test
    (select case when idSeq is null then 1 else max(idSeq)+1 end, 3, 'Main street');
    I am having ORA-00937 : not a single-group group function error, any suggestion?
    Edited by: 939569 on 13-Feb-2013 11:21 AM

    Hi,
    939569 wrote:
    Hello,
    I need generate an unique number without sequence. Explain what you're trying to do, and why a sequence won't do it.
    I am using Oracle 11.2, here is the details. The column idSeq is unique withing one specific idType. I don't want a sequence for each idType.
    create table tb_test (idSeq number(5), idType number(5), addr varchar2(256));
    insert into tb_test
    (select case when idSeq is null then 1 else max(idSeq)+1 end, 3, 'Main street');
    I am having ORA-00937 : not a single-group group function error,Right. Since the sub-query is using an aggregate function (MAX), everything in the SELECT clause must be an aggregate, a group by expression, a constant, or something that depends entirely on them. In this example, the CASE expression depends on idSeq, which is not an aggregate, not a group by expression (there is no GROUP BY clause) and not a constant.
    Also, the sub-query must have a FROM clause. All queries and sub-queries in Oracle require a FROM clause.
    any suggestion?Use a sequence. The numbers won't be consecutive within each idType, but what does that matter? Chances are, no matter what you do, you won't be able to maintain consecutive numbers within each idType anyway.
    If you won't use a sequence, then you can try:
    INSERT INTO  tb_test (idSeq, idType, addr)
    SELECT  1 + NVL ( MAX (id_seq)
                  , 0
    ,       3
    ,     'Main street;
    FROM     tb_test
    WHERE   idType  = 3
    ;

  • Generate Random Number By sequence

    How to generate random 4 digit random number using sequence or any other method. Please suggest

    4 digit random numbers can be obtained by:
    SQL> SELECT TRUNC(DBMS_RANDOM.VALUE(1000,9999)) FROM DUAL;
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   4002
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   4748
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   8328
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   3667
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   7464
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   4893
    SQL> /
    TRUNC(DBMS_RANDOM.VALUE(1000,9999))
                                   4961In mine case there is no repetition using Oracle 11.2.0.1 on Windows XP.
    Regards
    Girish Sharma

  • Could this Fibonacci sequence generator and prime tester code be made more

    Hey,
    Could this Fibonacci sequence generator and prime tester code be made more efficient?
    package sideprojects;
    public class Exam2008Question2F
         public static boolean isPrime(int n)
              int div=2;
              while(div*div<=n)
                   if(n%div==0)
                        return(false);
                   div++;
              return true;
         public static void main (String [] args)
              int prev = 1, curr = 1;
              System.out.println(prev+": It's a prime number.");
              for(int i=0;i<10;i++)
                   if(isPrime(curr))
                        System.out.println(curr + ": It's a prime number.");
                   else
                        System.out.println(curr + ": It's not a prime number.");
                   int next = prev + curr;
                   prev = curr;
                   curr = next;
    1: It's a prime number.
    1: It's a prime number.
    2: It's a prime number.
    3: It's a prime number.
    5: It's a prime number.
    8: It's not a prime number.
    13: It's a prime number.
    21: It's not a prime number.
    34: It's not a prime number.
    55: It's not a prime number.
    89: It's a prime number.Edited by: woodie_woodpeck on Apr 26, 2009 3:42 AM

    corlettk wrote:
    Not what you expected? Or are you saying something about the performance of long arithmetic verses int?No, I thought you posted your method using long's as well. When you implement them both using int's (or long's), the 6-increment should run quicker:
    public class PrimeTester {
        public static boolean isPrimeInc2(long n) {
            if(n < 2) return false;
            if(n == 2) return true;
            if(n%2 == 0) return false;
            long sqrtN = 1+(long)Math.sqrt(n);
            for(long i = 3; i <= sqrtN; i += 2) {
                if(n%i == 0) return false;
            return true;
        public static boolean isPrimeInc6(long n) {
            if(n < 2) return false;
            if(n == 2 || n == 3) return true;
            if(n%2 == 0 || n%3 == 0) return false;
            long sqrtN = 1+(long)Math.sqrt(n);
            for(long i = 6L; i <= sqrtN; i += 6) {
                if(n%(i-1) == 0 || n%(i+1) == 0) return false;
            return true;
        public static boolean isPrimeCached(long n) {
            if(n == 2) return true;
            if(n < 2) return false;
            long[] cache = {2,3,5,7,11,13,17,19,23,29,31};
            for(long c : cache) {
                if(n == c) return true;
                if(n%c == 0) return false;
            long stop = (long)Math.sqrt(n);
            for(long i = cache[cache.length-1]; i <= stop; i += 2) {
                if(n%i == 0) return false;
            return true;
        public static void main(String[] args) {
            long N = 1000000, start = 0, end = 0, repeat = 5;
            while(repeat-- > 0) {
                start = System.currentTimeMillis();
                for(long i = 1; i <= N; i++) isPrimeInc2(i);
                end = System.currentTimeMillis();
                System.out.println("isPrimeInc2(...) upto "+N+" took "+(end-start)+" ms.");
                start = System.currentTimeMillis();
                for(long i = 1; i <= N; i++) isPrimeInc6(i);
                end = System.currentTimeMillis();
                System.out.println("isPrimeInc6(...) upto "+N+" took "+(end-start)+" ms.");
                start = System.currentTimeMillis();
                for(long i = 1; i <= N; i++) isPrimeCached(i);
                end = System.currentTimeMillis();
                System.out.println("isPrimeCached(...) upto "+N+" took "+(end-start)+" ms.\n");
    }

  • I just updated my iPad 3 to ios 7.02 and can no longer sync with iTunes on my computer running OS 10.5.8. I'm wary about updating to Lion, which may cause any number of apps on my computer to no longer work. Although I may consider purchasing a new laptop

    I just updated my iPad to IOS 7.02 and unfortunately can no longer sync with my MacBook running OS 10.5.8. I'm wary about updating to Lion as this may cause any number of apps on my Macbook not to work at all or malfunction. Also my MacBook is 5 years old, and I was thinking about purchasing a new computer. I would like to decide when rather than be forced though. Does anyone have any suggestions for a work around? At the moment I do not subscribe to the cloud, and it looks like that is the only way I can back up my iPad now.

    Upgrade to Snow Leopard - it's compatible with the latest version of iTunes, and still supports PowerPC applications.
    $19.99 - http://store.apple.com/us/product/MC573Z/A/mac-os-x-106-snow-leopard
    Snow Leopard is required if you wanted to upgrade to Lion, anyway, which you may want to in the future if the latest version of iTunes no longer supports Snow Leopard.

  • Creation of project, Project ID any number ranges are there?

    Creation of project, Project ID any number ranges are there?

    Hi Saran,
    Project ID have Project Code and Description
    you can use Project ID which is a unique identifier for every project as a reference example shown.
    here ZCHARM is the Project ID ...you can also use numbers if required.
    There is no no. range concept for Projects
    Hope this clarifies
    Thanks
    Prakhar

  • ABAP-OO: Create any number of instances

    Hello,
    please, look at this simple scenario:
    DATA:
      my_class type ref to zcl_xyz.
      create object my_class.
    In that case I have just created one instance. Now I need a mechanism to create and identify any number of instance of the type zcl_xyz. <b>That means, I dont know exactly, if I need 5 or 200 instances.</b> Any feasible idea, how to handle that?
    Thanks and regards.

    Hi,
    Declare one static attribute in the class.
    Here is the sample code to trap the number of instance created for an object type.
    CLASS C1 DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA CREATE_COUNT TYPE I.
        METHODS CONSTRUCTOR.
    ENDCLASS.
    DATA: O1 TYPE REF TO C1,
          O2 LIKE O1,
          O3 LIKE O1.
    CREATE OBJECT: O1,
                   O2,
                   O3.
    WRITE: 'Number of created objects:', C1=>CREATE_COUNT.
    CLASS C1 IMPLEMENTATION.
      METHOD CONSTRUCTOR.
        CREATE_COUNT = CREATE_COUNT + 1.
      ENDMETHOD.
    ENDCLASS.
    Hope this hint helps you.

  • Report Script - How to get the total on the any number of rows selected

    Hi,<BR>I am using Essase and report script for the reporting purpose. In this i would like to know how to get the sum of all the rows selected. I know we can use the calculate row, but it has to be done with print row to display the newly created row. But i am using alphablox where this print row is not working. Is there any other alternative is there to get the sum of any number of rows, and displaying them??<BR>Please help me.<BR><BR>Regards<BR>R.Prasanna

    Pls check the structure and index.
    EMP_ID NUMBER(9) NOT NULL,
    EMP_CD           NUMBER(3),
    EMP_NO VARCHAR2(250 BYTE) NOT NULL,
    FROM_EFF_DT DATE NOT NULL,
    TO_EFF_DT DATE,
    CREATE INDEX IDX_EMP_NO ON EMP
    (EMP_NO)
    NOLOGGING
    TABLESPACE INDEXES
    PCTFREE 20
    INITRANS 10
    MAXTRANS 255
    STORAGE (
    INITIAL 56K
    NEXT 1784K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    FREELISTS 4
    FREELIST GROUPS 1
    BUFFER_POOL DEFAULT
    NOPARALLEL;

  • HT5622 pls apple team, i want to register for apple id on my iphone 4 any number i enter from my credit card , the system tells me that it is wrong.

    pls apple team, i want to register for apple id on my iphone 4 any number i enter from my credit card , the system tells me that it is wrong.

    Thanx very much Amishcake , your link was very helpful. i followed the steps and when i got to the part where you enter card details on my iphone , i discovered that the last two options  after amex that is 4. discover 5. None , are not part on the options i get on my iphone so i dont get to choose the none option. Am really worried.

  • I called 888 442 4551 and when the recording told me to press any number its not working,

    I called 888 442 4551 and when the recording ask me to press any number on dial pad its not working, means I can not make any choices,,,

    No, Apple does not support downgrading iOS. Never has.
    Start with a reset: Simultaneously hold down the Home and On buttons until the device shuts down. Ignore the off slider if it appears. Once shut down is complete, if it doesn't restart on it own, turn the device back on using the On button. In some cases it also helps to double click the Home button and close all apps BEFORE doing the reset.
    If that doesn't work, you may need do a full restore.

  • BE3000,E1 line out, internal IP PHONE normal phone call, phone prompt reversal of "The number dialed is empty" how to solve

    HI,
    BE3000,E1 line out, internal IP PHONE normal phone call, phone prompt reversal of "The number dialed is empty" how to solve
    thanks

    We need traces to figutr out what the problem is. Please make the call, download traces from the diagnostics page and send it.
    Thanks

  • Anyone have any luck on sequencing Itunes 12?

    Hey everyone, I was wondering if anyone has had any success on sequencing itunes 12.  I followed the instructions for iTunes 11 here:
    http://stealthpuppy.com/sequencing-apple-itunes-11-with-app-v-5/ 
    but, it didn't work properly.
    One of the issues I have is that when you launch iTunes,  you get the following message:
    Thinking it was because the ipod server was not started, I went back and re-sequenced it from manual to automatic, still did not work.
    Also,  This is going to be used in a lab environment, so it needs to be FULLY setup, the webpage said not to run it, but, I did it anyway-didn't keep my settings. 
    any ideas?

    Have you installed Apple Application Support and Apple Mobile Device Support on sequencer before sequencing and on the client PC before running the iTunes package?
    Please remember to click "Mark as Answer" or "Vote as Helpful" on the post that answers your question (or click "Unmark as Answer" if a marked post does not actually
    answer your question). This can be beneficial to other community members reading the thread.
    This forum post is my own opinion and does not necessarily reflect the opinion or view of my employer, Microsoft, its employees, or other MVPs.
    Twitter:
    @stealthpuppy | Blog:
    stealthpuppy.com |
    The Definitive Guide to Delivering Microsoft Office with App-V

  • How to reverse the Batch number which was enter wrongly during GRN posting

    Hi Folk,
    How to reverse the Batch number which was enter wrongly during GRN posting .
    Please revert.
    Thank you.

    You can either do a transfer posting and move quantity from this batch to another batch e.g. in MB1B with movement 311, or you cancel the entire material document using MBST transaction and redo your receipt correctly.
    Then you can flag the wrong batch for deletion in MSC2N.
    The batch itself gets deleted physically with the archiving transaction SARA object MM_SPSTOCK

Maybe you are looking for