Stuck on query Substr() for variable length strings

I have these sample data:
GET sampledata
WITH sampledata AS
     (SELECT '/customizations/ams/apps/oracle' v1 FROM DUAL
      UNION ALL
      SELECT '/customizations/webui/main/repository/developer/cz/apps/oracle' FROM DUAL
      UNION ALL
      SELECT '/customizations/webui/audit/oie/ap/apps/oracle' FROM DUAL)
SELECT sampledata.v1 aa
  FROM sampledata;
  
AA
------------------------------------------
/customizations/ams/apps/oracle
/customizations/webui/main/repository/developer/cz/apps/oracle
/customizations/webui/audit/oie/ap/apps/oracle
What I would really like to do is to extract the value between the slashes appearing before "/ apps/oracle /.

If in the examples above, I want to extract:
ams
cz
ap
The problem is that the position of this element varies. In the sample data "AMS" appears after the 2nd slash, 'cz' after the 6th and "ap" after the 5th.

I can get the value by one simple example:
GET sampledata
WITH sampledata AS
     (SELECT '/customizations/ams/apps/oracle' v1
        FROM DUAL)
SELECT sampledata.v1 aa
     , substr(sampledata.v1,17, instr(substr(sampledata.v1,17),'/')-1) aj
from sampledata;  

AA                              AJ
------------------------        ---------------------
/customizations/ams/apps/oracle ams
But of course, it is useless, that the segment I want to put the hand isn't always in the same place.

Any advice much appreciated!

Thank you

Hello

If you're on g 10 (or higher), try regular expressions:

SELECT sampledata.v1 aa,
       regexp_replace(v1, '^.*/([^/]+)/apps/oracle.*$', '\1') aj
FROM sampledata;

Tags: Database

Similar Questions

  • Variable-length string

    Hello.
    I need pl/sql function with a parameter, it should looks like:
     
    CREATE OR REPLACE FUNCTION GenerateStringOfZeroes( Length IN NUMBER ) 
    return VARCHAR2 AS
    BEGIN
    return ...
    END
    It must return a string of zeros with a length as it incoming parameter.
    for example
    GenerateStringOfZeroes (9);

    "should return: ' 000000000";

    What is the best way to do it?
    Thank you!

    return lpad ('0', '0', length);

    Concerning

  • Format analysis of the measurement data of variable length for Newport THP/N

    I try to analyse the response of a sensor of zED-THP/N of Newport. The answer is back with ID SEQ TYPE TEMP C HUMD %.

    ID = 1, SEQ is constantly changing, TYPE = 15, temperature = nnn.n

    I am trying to capture the Temp, and this presented a challenge. (The humidity is easy, I'm reading after the C - 5 has 'C')

    The SEQ number starts as n and evolves to nnnn... so using 7x4a does not work due to the changing length of the SS.

    When I use '15' 4, because the Type is still 15, and SEQ contains a 15 in the number, which also becomes a problem.

    Everything that I have which is constant is that there are spaces between each value and the value of temperature I'm looking begins after the 3rd space.

    Any help would be great

    David Sandelman

    Great... progress is good.

    If you use the single command, tol ERDG00A return all my sensors in a given request:

    The request channel data that must be completed is channel 0. All other channels should be empty. Not \r, just empty. I should have mentioned that in the original post. Then configure the channels as before, ensure that each channel of moisture is a\r\n. The next channel group must be a\x20.

    To explain, just one tells DASYLab to find the number of variable length, and he still needs a delimiter to put end. many devices use a comma, but they use a space. The hexadecimal ASCII for space is 20, so say us DASYLab to find numbers in a string of ASCII and stop when he finds a space, using the notation of DASYLab to hexagonal \x20.  notation for the carriage return character (\r isor hex 15), and \n is the notation for the line break ( or hex 12).

    15 84 0 18.5 C 64.5%
    1 50 15 C 18.4, 64.2%
    2 214 15 18.5 C 64.7%
    3 237 15 18.3 C 64.3%

    I like the idea of a single data request command for all four channels - less necessary communication protocol. In interpreting the device number, you will be able to ensure that the analysis works correctly.

    CH 0: a\x20

    CH 1: a\x20

    CH 2: a\x20

    CH 3: a\x20

    CH 4: a\r\n

    CH 5: a\x20

    CH 6: a\x20

    CH 7: a\x20

    CH 8: a\x20

    CH 9: a\r\n

    CH 10: a\x20

    CH 11: a\x20

    CH 12: a\x20

    CH 13: a\x20

    CH 14: a\r\n

  • Get the bind variables name string SQL or the cursor

    Hello

    Is there way to get of the bind variables name string SQL or the cursor?

    Example of
    DECLARE
      l_sql VARCHAR2(2000);
      desctab DBMS_SQL.DESC_TAB;
      curid   PLS_INTEGER;
    BEGIN
    
      l_sql := 'SELECT * FROM emp WHERE mgr = :X and deptno = :Y';
    
      curid := dbms_sql.open_cursor;
      dbms_sql.parse(curid, l_sql, dbms_sql.NATIVE);
      ....
    END;
    What I mean with the SQL string:
    I love to get using some functions from above code variable l_sql all the bind variable.
    In this case the function should return array where is for example: X and: Y

    Back to bind the cursor variable names, I mean same but rather string I pass number of cursor.

    Y at - it sucks ready function or some may share a code customized for this purpose?

    Thanks

    Kind regards
    Jari

    http://dbswh.webhop.NET/dbswh/f?p=blog:Home:0Regards,

    Published by: jarola December 19, 2011 02:44

    I found there are wwv_flow_utilities.get_binds of the function not documented in APEX packages that do what I want.
    Usage example
    set serveroutput on
    DECLARE
      binds DBMS_SQL.varchar2_table;
    BEGIN
      binds := wwv_flow_utilities.get_binds('select :P1_TEST from dual');
      FOR i IN 1 .. binds.count
      LOOP
        dbms_output.put_line(binds(i));
      END LOOP;
    END;
    /
    
    anonymous block completed
    :P1_TEST
    But I would not use these functions without papers as those who can change or there is no future versions APEX.
    Is there a documented function or the custom function that do the same thing as wwv_flow_utilities.get_binds?

    Some old basic example code of my friends. Also the media getting the bind variable of PL/SQL code blocks anon.

    SQL> create or replace function GetBindVariables( statement varchar2 ) return TStrings is
      2          --// bind variables names are terminated by one the following special chars
      3          SPECIAL_CHAR    constant TStrings := TStrings(' ',')','+','-','>','<','*',',','=',';',CHR(10),CHR(13));
      4
      5          --// max size of a bind var name
      6          MAX_VARSIZE     constant integer := 100;
      7
      8          pos     integer;
      9          pos1    integer;
     10          occur   integer;
     11          varName varchar2(100);
     12          varList TStrings;
     13  begin
     14          varList := new TStrings();
     15
     16          --// looking for the 1st occurance of a bind variable
     17          occur := 1;
     18
     19          loop
     20                  pos := InStr( statement, ':', 1, occur );
     21                  exit when pos = 0;
     22
     23                  varName := SubStr( statement, pos, 100 );
     24
     25                  --// find the terminating char trailing the
     26                  --// bind variable name
     27                  pos1 := Length( varName );
     28                  for i in 1..SPECIAL_CHAR.Count
     29                  loop
     30                          pos := InStr( varName, SPECIAL_CHAR(i) ) - 1;
     31                          if (pos > 0) and (pos < pos1) then
     32                                  pos1 := pos;
     33                          end if;
     34                  end loop;
     35
     36                  --// extract the actual bind var name (without
     37                  --// colon char prefix)
     38                  varName := SubStr( varName, 2, pos1-1 );
     39
     40                  --// maintain a unique list of var names
     41                  if not varName member of varList then
     42                          varList.Extend(1);
     43                          varList( varList.Count ) := varName;
     44                  end if;
     45
     46                  --// look for the next occurance
     47                  occur := occur + 1;
     48          end loop;
     49
     50          return( varList );
     51  end;
     52  /
    
    Function created.
    
    SQL>
    SQL> select
      2          column_value as BIND_VAR
      3  from TABLE(
      4          GetBindVariables('select * from foo where col=:BIND1 and day = to_date(:B2,''yyyy/mm/dd'')')
      5  );
    
    BIND_VAR
    ------------------------------
    BIND1
    B2
    
    SQL> 
    

    PS. just realize this code is case-sensitive, while variable bind is not. Should throw a upper() or lower() by adding the name of the var to the list - never really a problem for me because I'm pretty tense when it use cases correctly in the code. ;-)

    Published by: Billy Verreynne, December 19, 2011 06:19

  • defining the results of a query to a variable

    Hi all

    I'm having a problem affecting the results of a query to a variable. What I'm trying to do, is to do an AJAX call to a .cfc file and pass back the results of the function. The main problem is, I'm again moving a block of HTML (resulting from a cfquery in a cfoutput) stored in a variable. My code is something like...

    < name cffunction = "getText" access = "remote" returntype = 'Cancel' >

    < datasource = "" #request.dsn # cfquery "name ="queryTable">"
    SELECT kort, infoB

    Of infoTable

    < / cfquery >


    < cfset result = ' <!-this is the part I'm stuck, I want the table go here. -> ">"

    < table >
    < cfoutput query = "tablequery" >
    < b >
    < td > #infoA # < table > < td > #infoB # < table >
    < /tr >
    < / cfoutput >
    < /table >


    < cfwddx action = "cfml2js" input = "" # result # ' toplevelvariable 'o' = > "

    < / cffunction >

    It is a simplified version of what I want to do, but you get the idea...

    Is it still the right way to go about this?  Thank you

    That's what I get for trying the E-mail response feature!  Are you not happy, that I double checked my post.

    You could do a lot of string concatenation here to do stuff like"& Kort &""& infoB &""> time and time again."  But in reality the tags is so much easier to use.



      

        
      

    #infoA #.#infoB #.

  • Record and play variable a string will not copy

    I have a variable of string - serialization of an xml variable result - in a process.

    It has a length of 'unlimited '.

    When I opened the recording and playback, there is text indicating the beginning of sequenced xml:

    < node_x

    That's all that I can see.

    Unfortunately, the option 'copy value' in the menu contextual is dimmed, just at the moment where I most need!

    This is normal behavior for a scenario like this?

    Is there anyway that I can get to copy...

    Thanks in advance!

    At least try to open and close the variable perspective.

  • Pass arguments of variable length to an another variable length arguments

    Do not pass an argument of variable length to another argument of variable length

    For example

    public void call(name:String,..._params):Object

    {

    ExternalInterface.call("saveglobalscore",score) (name, params);
    }

    call ("test", "param1");

    "param1" is considered to be an argument with the type of array in the second function of «call», but is what I want to treat it as an argument as a string.

    The result is:

    < call name = 'test' returntype = "xml" > < arguments > <table > <property id = '0' > < name String > < / string > < / property > </ array > </ arguments > < / call >

    But what I want is

    < call name = 'test' returntype = "xml" > < arguments > < String > name < / String > < / arguments > < / call >

    I have to do is:

    public void call(name:String,..._params):Object

    {

    If (params.length == 1)

    {

    ExternalInterface.call("saveglobalscore",score) (name, params [0]);

    } Else if (params.length == 2)

    {

    ExternalInterface.call("saveglobalscore",score) (name, params [0], params [1]);

    } Else if (params.length == 3)

    {

    ExternalInterface.call("saveglobalscore",score) (name, params [0], params [1], [2] params);

    } else

    throw new Error ("I'm crazy");

    }

    This is a terrible solution, if it no work around?

    The compiler must can handle this situation.

    Try:

    public void call(name:String,..._params):Object

    {

    params.unshift (Name);

    ExternalInterface.call.apply (ExternalInterface, params);

    }

    Alex Harui

    Flex SDK Developer

    Adobe Systems Inc..

    Blog: http://blogs.adobe.com/aharui

  • How to find the query select bind variables

    How to extract the variable name to bind to AS suite of sql queries
    ' SELECT NAME IN: NAME OF THE DOUBLE '
    or
    "SELECT * FROM WHERE DOUBLE (: NAME = NAME)".
    or
    "SELECT * FROM WHERE DOUBLE: NAME IS NULL'."
    or
    "SELECT * FROM WHERE DOUBLE: NAME | NAME = LAST_NAME'
    or
    ' SELECT * FROM DUAL WHERE: a = 10'
    or
    "SELECT * from where DOUBLE: A > = 10'.
    or
    "SELECT * from where DOUBLE: A < = 10 '.

    Give a solution using SUBSTR, REGEXP_SUBSTR, please answer quickly
    best answer will be marked correct/good...

    Search: and then search for the following word breaker then have the substr for them: and the separator.
    You can build an own function to find the same.

  • What is the right way of javadoc a variable-length argument list

    What is the right way of javadoc a variable-length argument list?

    Let's say I have the following function:
    public void foo(Integer... intArray){
    //...
    }
    I'm not sure how I would want doc this, well, is there something special, I want to point out?

    Thank you for your time,
    Brandon

    Identical to another argument. Name it and say what's the point.

  • my calendar is stuck on "mobile timetables for the server account" after mountain lion update

    my calendar is stuck on "mobile timetables for the server account" after mountain lion update

    HOPE TO HEAR SOME ADVICE PLEASE :)

    1) go in your user library folder (~ / library). Hold down the option/alt key while accessing the menu Finder go.

    2) go to the calendar folder

    (3) delete all files that say "cache" (replace the your desktop in the case where you want to move them at least)

    (4) always in the user library folder, go to the Preferences folder

    (5) delete the com.apple.calendar.plist (on the desktop again)

    (6) restart your computer

  • Updated 2011 MacBook Pro at El Capitan 10.11.4. At the opening of the Photos, he entered into mode 'Library Preparation', but was stuck at 50% complete for more than 30 minutes. What should I do?

    Updated 2011 MacBook Pro at El Capitan 10.11.4. At the opening of the Photos, he entered into mode 'Library Preparation', but was stuck at 50% complete for more than 30 minutes. What should I do?

    Give it time - it may take a few hours depending on the size of your library is

    LN

  • query Oracle for top two salaries of each group departmentwise

    query Oracle for top two departmentwise salary

    sigh...

    But anyway,.
    Top - n queries:
    http://www.Oracle.com/technology/oramag/Oracle/07-Jan/o17asktom.html
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2853107469873
    and of course a lot of 'em here OTN...

  • SQL function for comparing 2 strings

    Hi all
    Is there a SQL function for comparing 2 strings?

    There is no function of pre defined in Sql for the string comparison. You can create according to your requirement.

    Concerning

  • The use of bind variables in dynamic query created for Ref Cursor

    Hello

    I'm in a situation where there is a Ref cursor to which the query is built execution based on a loop. This is why the number of links would be known until the program runs.
    The application is currently using literals instead of bind variables.

    code snippet of the above is
    strSql: = "select * from emp where 1 = 1 and ().

    loop cursor1
    If cond is true then
    strSql = strSql | "ename = ' |" Cursor1.ColumnName;
    end loop;

    Open cursor2 for strSql;

    How to use links in the example above.

    sb92075 wrote:

    user13019948 wrote:
    Hello

    Here is the code I have my trying to change literal-based link to the base.

    What do you mean by "based bind?

    who, what, how determines the values to be 'bound '?

    He's referring to the coding style. He is currently using concatenated literal, and the goal is to change it to use the bindings.

    If I understand this it is known as method 4 dynamic SQL and requires DBMS_SQL. There are examples autour but they vary according to the type of statement being generated - SELECT statements require column lists to be parsed, unlike the INSERT/UPDATE/DELETE.

    This came up recently on my current project and I hit a demo. Here a table of names and values accepted procedure and had to build these in a single WHERE clause along the lines of

    AND t_names(i) = t_values(i)
    

    for an undetermined number of elements in the array. For this demonstration, I used a table that we called "attribute" (don't ask) which has columns including 'attribute_id' and 'name', and I need to build a query along the lines of

    select description from attribute where attribute_id = :b1 and name = :b2
    

    by the way '1012' and 'ISIN' respectively. (I use a table better and after a CREATE statement for her but I have to rush right now, sorry).

    declare
       k_sql_base        constant varchar2(500) := 'select description from attribute';
    
       t_names           constant varchar2_t := varchar2_t('attribute_id',  'name');
       t_values          constant varchar2_t := varchar2_t('1012',          'ISIN');
    
       l_sql             varchar2(500) := k_sql_base;
       l_rows_fetched    integer := 0;
       l_value           varchar2(4000);
    
       l_cursor_handle   integer;
    
    begin
       -- Construct the SQL statement with column names and bind variables e.g.
       -- 'select description from mars.attribute where attribute_id = :b1 and name = :b2'
       for i in t_names.first .. t_names.last loop
          l_sql := l_sql ||
             case i
                when t_names.first then ' where ' else ' and '
             end ||
             t_names(i) || ' = :b' || i;
       end loop;
    
       dbms_output.put_line('SQL statment = ' || l_sql); 
    
       -- Parse the statement we built above (the remaining steps require a parsed cursor):
       l_cursor_handle := dbms_sql.open_cursor;
       dbms_sql.parse(l_cursor_handle, l_sql, dbms_sql.native);
    
       -- Associate the 1st column of output with variable l_value - required for SELECT statements:
       -- (actually the 3rd param here 'column' seems to be only used to get a datatype, in this case we want a string -
       -- dbms_sql.column_value actually extracts the value into a specified variable, which can be different.
       -- All examples in the documentation pass a local variable without further comment, so not entirely clear what this does other than set the output datatype.)
       dbms_sql.define_column(l_cursor_handle, 1, l_value, 4000);
    
       -- Now go through values array binding actual values to :bn variables in the cursor (similar to USING clause of EXECUTE IMMEDIATE)
       for i in t_values.first .. t_values.last loop
          dbms_sql.bind_variable(l_cursor_handle, ':b'||i, t_values(i));
          dbms_output.put_line('Bound :b'||i || ' as ' || t_values(i));
       end loop;
    
       -- Open the cursor and fetch the result (no loop here because we are expecting a single-row result):
       l_rows_fetched := dbms_sql.execute_and_fetch(l_cursor_handle);
    
       -- 'Returns value of the cursor element for a given position in a cursor'
       -- Copy the value of column 1 to variable l_value (has to match
       -- dbms_sql.column_value(l_cursor_handle, 1, l_value);
       dbms_sql.column_value(l_cursor_handle, 1, l_value);
    
       dbms_output.put_line('Result = ''' || l_value || '''');
    
       dbms_sql.close_cursor(l_cursor_handle);
    end;
    

    Hope that helps...

  • xdofx:substr and xdofx:instr do not work for variable incontext G1

    Hello

    I have a RTF I used variable incontext G1 for a group.

    I have to do the substring and instring in a field. When I use xdofx:substr ($G1/field, instr($G1/field,'#1-',0) + 3, instr($G1/field,'#2',1)), I get no value because xdofx:substr does not work for incontext field! I don't know why.

    so I used substring(), it works instead of xdofx:substr, but for instring, I studied, can't find anything for this.

    Field: "#1 - TEST 0123456789 #2.

    If I use substring($G1/field,3,4) - the output will be 'TEST '.

    The question is how can I use instring inside substring() to operate for a $G1/field of incontext my code.

    Thank you.

    You can use xdoxslt:instr, as in the example

Maybe you are looking for