Query getting alphabetical neighbours of chars in a strings

10gR2
Hello,
Can anybody give me a Select for getting the neighbour-chars (by Ascii-Code) of a simple source-string for a certain number of iterations?
E.g. the source-string is "M" and the number of iterations is 7 then the Select's should give seven rows like:
"M"
"LM"
"MN"
"LMN"
"KLM"
"MNO"
"KLMNO"
"M" is the starting char; the next iteration gives the alphabetically preceding char "L" and concats with the starting char; the next iteration gives the alphabetical successor of the starting char (and concats it); the next iteration results the next the alphabetically preceding char of the most left-sided char of the last result; the next iteration gives the next alphabetical successor of the most right-sided char of the last iteration's result... and so on...
2nd example, when starting with "DE":
"DE"
"CDE"
"DEF".....
Any ideas / hints ?

Well, I don't see any business logic in that requirement, but here we go :
SQL> var letter varchar2(10)
SQL> var occ number
SQL> exec :letter:='M'
PL/SQL procedure successfully completed.
SQL> exec :occ:=7
PL/SQL procedure successfully completed.
SQL> select str
  2  from   (select lvl,
  3                 decode(lv,1,(select replace(max(sys_connect_by_path(chr(ascii(letter)-(nb-level+1)),',')),',')||letter from dual connect by level <= nb),
  4                           2,letter||(select replace(max(sys_connect_by_path(chr(ascii(substr(letter,-1,1))+level),',')),',') from dual connect by level <= nb),
  5                             (select replace(max(sys_connect_by_path(chr(ascii(letter)-(nb-level+1)),',')),',')||letter from dual connect by level <= nb)
  6                             ||(select replace(max(sys_connect_by_path(chr(ascii(substr(letter,-1,1))+level),',')),',') from dual connect by level <= nb)) str
  7          from   (select letter, level lvl, mod(level,3) lv, sum(decode(mod(level,3),1,1)) over (order by level) nb
  8                  from   (select :letter letter, :occ occ from dual)
  9                  connect by level <= occ-1)
10          where :occ > 1
11          union all
12          select 0,:letter from dual where :occ>0)
13  order by lvl;
STR
M
LM
MN
LMN
KLM
MNO
KLMNO
7 rows selected.
SQL> exec :letter:='DE'
PL/SQL procedure successfully completed.
SQL> exec :occ:=3
PL/SQL procedure successfully completed.
SQL> /
STR
DE
CDE
DEF
SQL> exec :letter:='DE'
PL/SQL procedure successfully completed.
SQL> exec :occ:=4
PL/SQL procedure successfully completed.
SQL> /
STR
DE
CDE
DEF
CDEF
SQL>Nicolas.
adding a WHERE clauses to support occ=1 or occ=0
Edited by: N. Gasparotto on Dec 22, 2008 4:34 PM

Similar Messages

  • How can I get the number of chars in a String, without countig the Spaces?

    When I do String.length(), he returns the length with Spaces, but I want the number of chars and numbers.
    thx

    I'm afraid you'll need to write a method of your own for that. It's very simple fortunately:public static int getLengthWithoutWhitespace(String s) {
        java.util.StringTokenizer st = new java.util.StringTokenizer(s, " \t\r\n");
        int counter = 0;
        while (st.hasMoreTokens()) counter += st.nextToken().length();
        return counter;
    }This code is not tested... Here's another, a bit more reliable approach that simply passes through the characters of the string:public static int getLengthWithoutWhitespace2(String s) {
        int counter=0;
        for (int i=0; i < s.length(); i++)
            if (Character.isWhitespace(s.charAt(i))) counter++;
        return counter;
    }

  • How to get the first 4 chars form a var ?

    Hi guys,
    How to get the first 4 chars form a var ?
    i.e  temp type num20 value '00000000000012345678'.
    how to move the first 4 chars to another var?
    thx in advance.

    hi
    use OFFESTS..
    example:
    var1 = '12345678'.
    var2 = var1+0(4).
    now var2 conatins '1234'.
    thx
    pavan

  • How to ignore a variable defined in a query when the query gets executed

    Hi SAP guru, I am creating a query, which has a user input variable, say A, and a replacement path variable, say B, Bu2019s value is determined by A and the whole purpose of A is letting user entering an initial value and A must be ignored when the query gets executed. How can I achieve this in query designer?
    Thanks

    Hi, thanks for the reply. Actually this is not my problem. My problem is the query should be filtered by  a variable, say B, but B is not allowed to be entered directly by user (i.e. B could be a replacement path variable or user exit type). So B has to be derived from another user input variable, say A. However if I defined A in the query, A is by default used as one of the filters, which is not desirable because A is a subset of B in my case and should be ignored.
    Is there options (settings) that allow the query ignore a specified variable (A) ? If not is there other ways to get around this?
    Thanks
    MichScott

  • What api would I use to get the number of chars in string?

    What api would I use to get the number of chars in string?

    Assuming that you really mean that you want the number of charaters in a String (not string), that would be documented in java.lang.String
    The method is length()

  • Query getting  /crystal/ Program SYNTAX ERROR.

    Hi All,
    I connected to SAP BEX Query using MDX driver. when i execute query getting  /crystal/ Program SYNTAX ERROR.
    I imported these  crystal transports R21900741,786,695,754,780 .
    but got error for R71K900087 .
    MY SAP BW system version is SAP BW701 SP10 , Please suggest.
    Thanks,
    Joseph

    Thanks Mohammed. But our application is trying to pass a parameter which contains user data like section numbers....
    So when we pass the value 123.1(a) , here what is happening behind the scene of CR viewer
    webSource0.AddParameter "promptex-NAMEOFPARAMETER", "123.1%28a%29"
    and it throws up the error
    "The syntax of the value for prompt 'NAMEOFPARAMETER' is incorrect. Please correct the syntax and try again"
    I have no idea why it is throwing up this errror....

  • How do i get the last 4 chars

    String FileE = myFile.getName();
    This gives me a file name but how do I a reverse trim and get the last 4 chars??

    Hi
    What are you trying to achieve here, why are you pulling a file into a String Buffer ?
    fileName.getName() will output a string, you can use the following statement to get the last four characters of the filename
    Here is an example
    String fileName = "testfile";
    String lastFourChars = fileName.substring(fileName.length()-4);
    This will give you the last four characters of the filename.
    But if you are trying to get the extension of the file
    Do this
    String extension = fileName.substring(fileName.lastIndexOf("."));
    Thanks
    Swaraj
    Thanks
    Swaraj

  • Does The Query get Fired Again

    Does the query get fired again when i query a existing view
    1. create view abc as select name from Table
    2. select name from abc
    Table is a really large table wid many columns and many rows
    Lookin for a better performance coz i need names in one procedure and again need the same names for deletion in another procedure
    I dont want to fire the same query twice dats y.

    > there are like 20000 rows out of wch i need 2 retrieve 9000 or 10000 rows dependin on
    the constraints
    Go slow on the I'M SPEAK please... much better to deal with technical issues when using proper English.
    A 20,000 rows table is tiny and running a SQL that returns 10,000 or so rows, should be execute in seconds.. the slowest part of the operation should be shipping that 10,000 rows to the client (across the network) in case of a remote client.
    Maybe if you can describe the physical structure of the table (heap, index, partitioned?) and pinpoint just where the performance problem is (execution plan or an SQL*Plus autotrace), we could comment on why the performance seems (or maybe truly is) slow.

  • How to get a char from a String Class?

    How to get a char from a String Class?

    Use charAt(int index), like this for example:
    String s = "Java";
    char c = s.charAt(2);
    System.out.println(c);

  • How can I select the last 2 chars of a string

    Hello all,
    I am trying to select the last 2 characters of a string to match them to another string. This is for a Poem generator that contains 20 or so words and I have to pick 2 words at random, them look at the last 2 characters to see if they match in each string. Say "Plain" and "Rain" would match because they both have "in" at the end. The length of each word could vary. I don't want this doing for me just what Method should I be looking at.
    Thanks.

    hi,
    try this:
    public class StringTest {
         public static void main(String args[]) {
              StringTest obj = new StringTest();
              obj.same();
         void same() {
              String rain = new String("Rain");
              String plain = new String("Plain");
              int rainLength = rain.length();
              int plainLength = plain.length();
              if(rain.substring(rainLength-2).equals(plain.substring(plainLength-2))) {
                   System.out.println("same");
              else {
                   System.out.println("different");
    }you can use the length method to get the length of a string and then use the substring method, passing it length-2, so get the last 2 chars.

  • Deleting last char in a string...

    I have a string that is created as follows: strBuffer += k.getKeyChar();(k is KeyPressed ...KeyEvent) How can I delete the last Char in the string strBuffer?

    Hi
    // simply substring
    if (strBuffer.length() > 1)
        strBuffer = strBuffer.substring(0, strBuffer.length()-1);
    // you may also use
    if (strBuffer.length() > 1)
        StringBuffer buffer = new StringBuffer(strBuffer).
                                   deleteCharAt(strBuffer.length()-1);
        strBuffer = buffer.toString();
    }I've not tested the above code myself & I've written the above code on the go after reading your query. The above code definitely work & help you.
    Regards,
    JPassion

  • Query engine : Can not find DSN in Connection String

    DearSir/Madam,
    Opearating System Windows 7 Professional(32-bit).
    I am using Application, which is developed : Visual basic 6.0(32-bit), Report Writer : Crystal Report 9.2.693(32-bit) and database: Oracle 9.2.0.10(32-bit).
    ODBC Data source : System DSN created and Connection established (Based on Driver : CR ORACLE ODBC Driver 4.10 (cror818.dll))
    In windows 7 environment Data Base connectivity and data fetching also wroking fine.
    My problem is while running reports it display error as "Query engine : Can not find DSN in Connection String"
    I want run time reports.
    For your kind information, at the same time in Windows XP Professional there is no problem found and working fine.
    Kindly help me.
    Thanks and regards,
    Swarup

    Crystal Reports 9.x is not supported on Win 7. See the following wiki:
    http://wiki.sdn.sap.com/wiki/x/b4JiAw
    - Ludek

  • How to delete the last char in a String?

    i want to delete the last char in a String, but i don't want to convert the String to a StringBuffer or an array, who knows how to do?

    Try it in this way
    String MyString = "ABCDEF";
    MyString = MyString.substring(0,MyString.length()-1);

  • How to get IDL file name from CORBA IOR string

    hi, is it possible to get IDL file name from the IOR string? how?
    regards

    Hi,
    I don't think so.
    And if it was possible, which interface should be returned if
    the referenced object implements more than one?
    Regards.
    Karl

  • Getting a complete portion of an XML String (With tag names)

    Im working on an application that processes a huge amount of xml strings. Im using xpath since it makes it much easier to select and navigate through the tags. The only thing I can't do is get a complete portion of an XML string, for example, if i have
    <article>
    <articlebody>
    </articlebody>
    <references>
    <reference id="1"> ... </reference>
    <reference id="1"> ... </reference>
    <reference id="1"> ... </reference>
    </references>
    </article>
    I need to get the complete <reference> portion to parse later, so i need the following string:
    <references>
    <reference id="1"> ... </reference>
    <reference id="1"> ... </reference>
    <reference id="1"> ... </reference>
    </references>
    How can i do this using xpath? is it even possible? if not how else can i do it? (don't want to use regular expressions and string manipulation)
    Thanks for you help

    Im not sure if this really qualifies as using DOM, but this is all i do to get the data i want from the files (when i only want to get the text value of an element:
    InputSource inputSource = new InputSource(new StringReader(metadata));
    return xpath.evluate(expression, inputSource, returnType);where metadata is a String containing meta data, and return type is usually string or number.
    Im using Java 5 and
    Could you please explain a little more how to do this?
    Thank you

Maybe you are looking for

  • Error executing custom function module

    Hi all, am trying to read a function module form my java code as below. There is no problem with the function module. I think there is some problem with the java code that is written. I am sure the problem lies with the  TABLES IT_PRODUCT_DATA STRUCT

  • How to print (on paper) expected header and footer while printing Jtable

    Hello, I am printing jtable on paper using dot mtix printer.In header i want to print some name date and number like below Sun Date:12/8/20010 No.12334 | col1 | col2 | | col1 | col2 | footer When i am trying to print header its Font size is very big

  • CP5 - W7 - Nested/Grouped objects - Not possible

    Hi dear community, I use Photoshop, Premiere, after effects, and many other adobe produts... All of them have something in common, you can group or nest objects, vector based or pixel based media does not matter. In Premiere, yoy can group a film a t

  • JDBC/Servlets Connectivity Problems.

    Hi, I'm new to Java development. I'm trying to run this simple Servlet on OS : Sun Solaris 2.6 Web Server : Netscape Enterprise Server Database : Oracle 8i JDK2 and JSDK2 installed on the Server. JDBC Driver : Native Oracle JDBC Driver This program w

  • Visible / hide the tabs in JTabbed pane

    Hello, I've a frame with a tree on the left and a TabbedPane a on the right. I've 3 tab in my TabbedPane. I would like to change the visible tab when i clic on a node in the tree. My code is public void valueChanged(TreeSelectionEvent event) TreePath