SQL query to extract portions of a string.

Guys,

Please help me with a SQL to retrieve < PCS_NAME > and < PCS_ID > of the input below string:
SAB_20140306145347_ 1307928540_avn1omcr_dot_com_14_20110612.csv

The format of the string is:

SAB_ < CollectDateTime > _ < EMS_timestamp > _ < PCS_NAME > < PCS_ID > _ < startdate > .csv

< PCS_NAME > = "avn1omcr_dot_com."

and

< PCS_ID > = "14".

Thank you!

B

Maybe this:

WITH T AS

(

SELECT 'SAB_20140306145347_1307928540_avn1omcr_dot_com_14_20110612.csv' double str

)

SELECT REGEXP_REPLACE(str,'SAB_\d{14}_\d{10}_(.+)_\d{2}_\d{8}.csv','\1') as PCS_NAME,REGEXP_REPLACE(str,'SAB_\d{14}_\d{10}_(.+)_(\d{2})_\d{8}.csv','\2') PCS_ID

T

PCS_NAME PCS_ID

---------------- ------

avn1omcr_dot_com 14

Tags: Database

Similar Questions

  • SQL query to extract the part of a string.

    Could someone help me with a SQL to retrieve the section highlight of my channel?

    ABC_DEF_CDT_20140512140005_20140504030420_C20140512.055505. 20140522.070022.csv

    BTW, the format of the string is less to:

    < EMS_NAME > _CDT_ < CollectionDateTime > _ < EMS_timestamp > < StartDate > _C. < StartTime >. < EndDate >]. < EndTime> .csv

    Kind regards

    B

    One way would be
    
    SQL> with t
      2  as
      3  (
      4  select 'ABC_DEF_CDT_20140512140005_20140504030420_C20140512.055505.20140522.070022.csv' str
      5    from dual
      6  )
      7  select ltrim(regexp_substr(str, 'C[[:digit:]]{8}\.[[:digit:]]{6}'), 'C') str
      8    from t;
    
    STR
    ---------------
    20140512.055505
    
    SQL>
    
  • SQL Query to extract data between days and hours

    Hi friends,

    I need, it's for a report.

    Description of the requirement:

    Need of data in a table located in an OPEN State for more than 30 minutes

    Well, this requirement can be obtained from

    Select * from xyz where status = 'OPEN' and last_update_date < = sysdate---30 (30/1440) minutes and it is a parameter

    the query above will search all data that are in the OPEN State beginning to sysdate - (30/1440). So I want to change the query to restrict the data, by adding another parameter as DAY

    for example if I give 10 day, it should recover all the data only within 10 days and sysdate-30 minutes.

    We use the last_update_date column to restrict the day.

    If I do not give any date for entry must retrieve all records of sysdate-30 minutes.

    If I don't give minutes that he must retrieve all the records in the OPEN State.

    is the question clear enough? my English is bad.

    Please suggest me a query...

    Thank you and best regards,

    Arun Thomas T

    Hello

    Select * from xyz where status = 'OPEN' and

    last_update_date between nvl (sysdate -: days, last_update_date) and nvl2 (: days, last_update_date, nvl (sysdate -: minutes/1440, last_update_date));

    that should be:

    If the days parameter is entered then start - days of sysdate and end up last_update_date

    If days is not entered then boot from the begingin and put end to:

    1 sysdate -: minutes/1440 if minutes are entered

    2. up to the last_update_date if the minutes are not entered

  • Stop Error Message "Failed to parse the SQL query" appearing

    Hello

    I have a sql query that is built into a string and then compiled and executed at run time. This query lies in a region and is returned.

    The query uses a view that uses a database link. If the link of database falls down for some reason, the "Failed to Parse SQL Query" message and the details on the DB link not working. However, I want to be able to implement my own error message when this happens, but I can't find a way to capture the error. I have put an exception handler in the region but because the code is technically correct and only fails at runtime that is not catching it.

    Is anyway to catch this error and display my message?

    Thank you
    -Mark

    Hello

    Try to use condition to hide the region and instead of this report will show another area where is your custom error message?

    BR, Jari

  • SQL query for empty string

    I am trying to execute the following SQl query, SELECT * failure WHERE ID = '123 ' AND RepairAction =' '; using the DB tools run Query.vi. This query never find record in my database. My database contains a record where the registered ID contains the value '123' and the RepairAction field is an empty string. If I remove the declaration 'AND RepairAction' ';' my query text, the record is found. I think my problem is that I do not use the correct syntax to describe and an empty string. I tried the following: "," ",""," "and NULL as empty and none of these work string arguments.

    I was hoping someone might be able to tell me what the correct syntax is an empty string or if there is another approach that I take.

    Thanks in advance for your help,

    Jim

    Jim,

    Just to be sure, have you used 'is' instead of '=' in this command?

    This makes all the difference in this command.

    Cerati

  • SQL query to retrieve only numbers to a string variable

    Dear all Experts,

    I have a requirement in one of my projects where I need to extract only the numbers present in the variable.

    for example:

    BANK_ACCOUNT_NUMBER = 12345-67890';

    BANK_ACCOUNT_NUMBER = 12345 67890';

    BANK_ACCOUNT_NUMBER = "123.456.7890";

    BANK_ACCOUNT_NUMBER = 123-A456BC7890D';


    In all these cases, I need to retrieve only numbers such as BANK_ACCOUNT_NUMBER = 1234567890 and I am looking for SQL query only.


    Please suggest me the query how to extract numeric values from varchar variable.



    Thank you

    Knockaert

      select regexp_replace('123-A456BC7890D','[^0-9]') from dual;
    

    See you soon,.

    Manik.

  • String separated by commas to 'IN' operator in SQL query

    Hello

    The issue is that the "In" operator in the report query accepts values contained in the element of page Apex... 221,332,542.

    Is there a common solution for this problem?

    Thank you

    Patrick

    984146 wrote:

    The issue is that the "In" operator in the report query accepts values contained in the element of page Apex... 221,332,542.

    It's the common "variable list" model [anti-]. In

    select * from table where columnvalue in (7788, 7839, 7876)
    

    (7788, 7839, 7876)is a list of expressions and the predicate is evaluated as a membership condition.

    In

    select * from table where columnvalue in :P1_X
    

    :P1_Xis a scalar string, unable to contain multiple values.

    In a report of type APEX, a source report of the body of the PL/SQL function returning a SQL query with lexical substitution can be used to produce a "variable list:

    return 'select * from table where columnvalue in (' || :P1_X || ')';
    

    where P1_X contains less than 1000 values, has been disinfected to code SQL injectionand string values are properly cited.

    Some people suggest the following approach, that will work also in interactive APEX reports:

    select * from table where instr(':' || :P1_X || ':', ':' || columnvalue || ':') > 0
    

    However, it is underperforming because it eliminates the possibility of using the index optimizer or the size of the partition in the execution plan.

    See various elements in the list to ask Tom and imitating the channel to the table using sql features for effective solutions.

  • Clarification of the SQL query in 2 day + Guide APEX

    I worked through the Oracle Database Express Edition 2 day + Application Express Developer's Guide, and try to decipher the SQL query in Chapter 4 (building your app).

    The code is:

    SELECT d.DEPARTMENT_ID,

    d.DEPARTMENT_NAME,

    (select count (*) from oehr_employees where department_id = d.department_id)

    "Number of employees", he said.

    substr (e.first_name, 1, 1) |'. ' || Select 'Name Manager',

    c.COUNTRY_NAME 'place '.

    OEHR_DEPARTMENTS d,

    E OEHR_EMPLOYEES

    OEHR_LOCATIONS l,

    C OEHR_COUNTRIES

    WHERE d.LOCATION_ID = l.LOCATION_ID

    AND l.COUNTRY_ID = c.COUNTRY_ID

    AND e.department_id = d.DEPARTMENT_ID

    AND d.manager_id = e.employee_id

    AND instr (superior (d.department_name), superior (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0)

    I don't know exactly what is happening in the last line. I think I understand what the different functions but I'm not clear on the use of the: P2_REPORT_SEARCH string.

    What does this string? This code simply checking that d.department_name isn't NA?

    I have SQL experience but am not very familiar with the Oracle PL/SQL implementation. Can someone please give me a brief breakdown that check is doing in the context of the overall query? The application seems to work even if the conditional statement is not included.

    Thank you.

    2899145 wrote:

    Thanks for the reply. I apologize if the information I added was incomplete. The code came from the day 2 + Application Express (version 4.2) Developer Guide.

    In the section 'your own Application of 4 Buuilding' https://docs.oracle.com/cd/E37097_01/doc.42/e35122/build_app.htm#TDPAX04000 , they describe the creation of a report

    page that includes the "manager_id" and 'location_id '. The SQL query, I pasted above extracted from the data in other tables to substitute the real 'name of the Manager' and 'rent '.

    for the corresponding ID values. It makes sense, and the part of the SQL query that explicitly doing this makes sense.

    However, given that the document is a guide for the development of the APEX, I guess the command:

    AND instr (upper (d.department_name), upper (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0

    done something valuable, and I do not recognize what is exactly the value.

    From a practical point of view why would I need to include this conditional statement?  Which only added to the application?

    Looking at the guide in question, it is clear that the

    AND instr(upper(d.department_name),upper(nvl(:P2_REPORT_SEARCH,d.department_name)))>0
    

    the line is completely unnecessary in the context of this tutorial, and it can be removed. The search in the tutorial app page is implemented by using a report filter interactive rather than a P2_REPORT_SEARCH element, which does not seem to exist at all. (It's a quirk of the APEX that bind variable references to non-existent items are replaced with NULL silently rather than exceptions). I thought that perhaps it would be legacy code a version of the tutorial prior to the introduction of interactive reports at the APEX 3.1, but I can't find explicit instructions to create such an element of filter in the 3.0 tutorial. I guess it must have been automatically generated by the application wizard when you create a standard report page.

    If you do not want to see the effect he would have (as described in the post above), leave it in the source report, add a text element of P2_REPORT_SEARCH, and a button "submit" on page 2 and experimenting to find different values of the element and clicking on the submit button...

  • A necessary sql query

    Hi all

    I have two record values described.

    Select 1 as seq_no, "test1" as double data_set
    Union
    Select 1, '12test' from dual
    Union
    Select 2, 'abcd' from dual
    Union
    Select 2, 'ilm' from dual
    Union
    Select 2, '12test444' from dual

    Here, I need to extract the o/p from the DataSet above below

    1, 12test
    1, test1
    2, 12test444

    Select 1 as seq_no, "test1" as double data_set
    Union
    Select 1, '12test' from dual
    Union
    Select 2, 'abcd' from dual
    Union
    Select 2, 'ilm' from dual

    Here, I need to extract the o/p from the DataSet above below

    1, 12test
    1, test1
    2, abcd
    2, ilm

    The logic behind both above the o/p is

    If the search string 'test' is present in any data set (data set is defined by the same seq_no values), and then print the entire line containing the search string. As in the first data set of record value with seq_val 1 and 2 have two test string 'test', o/p is all the lines contating the search string 'test '.

    If the search string 'test' is not present in any data set (data set is defined by the same values seq_no) then print all lines not containing not the chain sought. As in the second set of data record value with seq_val 2 at once is not test string 'test', o/p is all lines not contating the search string 'test' in the test with 1as and all seq_val data the lines contating the search string 'test' in a set of data with seq_val 2

    Hope I could explain my logic o/p and I need to do in a sql query.

    Waiting for your answers.

    Thanks in advance.

    Hello

    Here's one way:

    WITH     got_rnk          AS
    (
         SELECT     seq_no, data_set
         ,     DENSE_RANK () OVER ( PARTITION BY  seq_no
                                   ORDER BY          CASE
                                       WHEN  INSTR (data_set, 'test') > 0
                                       THEN  1
                                       ELSE  2
                                     END
                           )     AS rnk
         FROM    table_x
    )
    SELECT     seq_no, data_set
    FROM     got_rnk
    WHERE     rnk     = 1
    ;
    

    The CASE expression returns 1 if data_set contains 'test', and it returns 2 if it is not. We will call this number x.
    You are not really interested in x itself. On the contrary, you want all the lines that have the lowest value of x between the lines with the same seq_no. In other words, if a row with a given_seq_num x = 1, then you want all the lines with this seq_no and x = 1, but it the lowest x for a seq_no is 2, then you want the lines with x = 2 instead.
    DENSE_RANK returns the number 1, if the riow data is the more low (or tied for the lowest) in its partition, so if him are all rows with x = 1 in the group, rnk = 1 corresponds to x = 1. But if all lines with the same seq_no have x = 2, then rnk = 1 corresponds to x = 2.

  • SQL (body of function from PL/SQL returning the SQL) query when you use to_char

    We are trying to build a page of Type SQL Query report (body of function from PL/SQL returning SQL query).
    our request is simple, to extract the month of the column recording_date.

    declare
    l_query varchar2 (1000);
    Start
    l_query: = 'select to_char (recording_date, 'MM') of re_productive;
    Return l_query;
    end;

    but we would like the following for this query problem

    Function returning SQL query: query cannot be parsed in the generator. If you believe that your query is syntactically correct, check the box of generic columns below the source of the region without analysis.
    (ORA-06550: line 4, column 42: PLS-00103: encountered the symbol "MY" what awaits one of the following values:.) (* @ % & = - +; <>/ at is mod remains not rem <>or! = or ~ = > = < = <>and or as between | multiset Member SUBMULTISET_ the symbol ".") was inserted before 'MY' to continue.)

    Notes:
    1 - the request is correct and it has been tested under sqlplus and toad.
    2. we tried option use generic name (analysis of query runtime only) column, but we get the same problem.


    any quick help please.

    Hello

    You have not escaped your quote in the string. Try this...

    DECLARE
    l_query VARCHAR2(32767);
    
    BEGIN
    
    l_query:= 'select to_char(recording_date,''MM'') from re_productive';
    
    RETURN l_query;
    
    END;
    

    See you soon

    Ben

  • Œuvres SQL query to MS SQL Server 2008, but not when you use the database kit

    I have this SQL query:

    DECLARE TABLE (@DataTypeTable)
    Name varchar (128).
    TypeID INT)

    -Add comma delimeted type data in the temporary table names
    INSERT INTO @DataTypeTable (name)
    SELECT * from WhatWeShouldDoRead.func_Split (@DataTypeTrimmed, ',')

    SELECT the name OF @DataTypeTable

    That takes a comma delimited by the string and returns the string as a table.  It works correctly in Microsoft SQL Server Management Studio.  When I run this as a stored procedure I return nothing.  There are no errors, SQL or otherwise.  I checked that I am connected to the correct database and the stored procedure is responsible without changing any error chain which is reported of this stored procedure (that code is not shown in the example above).  Has anyone seen this problem before, or have experience with SQL/Labview interfaces to tell me what I am doing wrong?

    Thanks in advance.


  • LabVIEW sql query

    HI HI... I'm a student doing a project related to labview. My task is to create a vi, type a user name and password to continue the whole VI.

    As I am a newbie to SQL query language, can anyone help me this?... This isn't like the VI with password lock

    There is a connection of the user called button in my main façade... u by clicking on it, a pop-up window will come out asking you a user name and a password. If the user name and the password is correct, then you can proceed. The problem is that I'm stuck with database...
    Help me pls!

    with respect,

    Ray

    Hello

    You have two cases:

    (1) connect to the database with string (link a string of connection information), and then type something like this:
    Driver is SQL Native Client;. Server = IP. Add.re.SS; UID = username; PW = *** ; Database = MyDatabase (depends on your database)

    (2) use a UDL file (you can configure it to connect to your database, with specific format). Remember that the connection is successful with test button.

    There is a UDL file that you can edit here: C:\Program NIUninstaller Instruments\LabVIEW 2010\examples\database\Labview.udl

    Edit: The connection dropped, you can set the path to an mdb file, and I think you can give the path of your accdb file.

    Kind regards

  • Calculation of the time wall of a SQL query.

    Hello

    While trying to discover the time of running a SQL query (wall time) I read in one place that CPU_TIME/EXECUTIONS of v$ SQLAREA, is the precise runtime we can come close to.

    I can't use "set timing on ' or 'DBMS_UTILITY. GET_TIME' that I need to extract the execution time of the story because the query will be drawn to an end, and I need to know how long it took to DB level and compare it with the end time before calculating the % of time used in the DB level total.

    Maybe another way to track sessions and the user TKPORPOF but now I donot want to take the help of the ADMINISTRATOR at this initial stage.

    Is CPU_TIME/EXECUTIONS of v$ SQLAREA where (SQL_TEXT) AS "SELECT... OF... %'; should be enough?

    user2925917, yes as Brian already answered your understanding as posted above seems correct.  Except in the case where there has been only a running query you will download an average time.  The problem with averages is that one or two unusual executions that can skew the average, but in most cases the average will be probably fairly accurate.

    - -

    HTH - Mark D Powell.

  • SQL query for the region of the tree

    Hello

    I was wondering if someone is able to help me work on a SQL query, to format the data in the table required in a part of the tree... I've never used a tree and I'm fighting to get the right data (if possible).

    The data in the table looks like this:

    data.PNG

    I want to put it in a tree, using level 1 level6 with a final layout that would look like this:

    tree.PNG

    As you can see, the data are formatted in level6 down in the tree, but are filled in the table from level 1. Not all of the columns will be filled, so level2 for anyone 4 (France) is the equivalent of level in the tree like level6 to person 1 (Spain).

    This is Apex 4.2.5

    Oracle 11.2.0.3.0

    Sample data:

    CREATE TABLE employees
       ( employee VARCHAR2(100),
         level1 VARCHAR2(100),
         level2 VARCHAR2(100),
         level3 VARCHAR2(100),
         level4 VARCHAR2(100),
         level5 VARCHAR2(100),
         level6 VARCHAR2(100)   
       );
    
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person1','Team One','Recruitment','Human Resources','Fictituous Company','Murcia','Spain');
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person2','Team Four','Testing','IT','Big Corporate','Hanover','Germany');
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person3','Big Corporate','Hanover','Germany', null, null, null);
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person4','Brittany','France', null, null, null, null);
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person5','Team Three','Testing','IT','Big Corporate','Hanover','Germany');
    INSERT INTO employees (employee, level1, level2, level3, level4, level5, level6) VALUES ('Person6','Public Relations','Government Agency','Brittany','France', null, null);
    
    

    Added example given.

    Hello

    Apex-user wrote:

    Thanks Frank, this is a good example, I can work with that! Your assumptions are correct.

    A question I came, however, is that I have a data segment that comes across poorly formatted so to speak... where only the lower levels (1-2, etc.) have been filled from the bottom up.

    An example of this data would be:

    1. INSERT INTO employees (employee, level 1, 2, level3, level4, level5, level6) VALUES ('Person7', 'One Team', 'Test', null, null, null, null);

    As you can see that if you rerun the select, the test team is now duplicated, both at the level of the root in the tree as it should.

    You are not sure if the sql can be adjusted to account for this, or if it's too hard?

    It is obviously a question of data and I am trying to solve this separately (extracted data from another system out of my control).

    Thank you!

    Sorry, I'm confused.

    You say that my assumptions were correct.  What includes supported that "If test ' occurs under 'IT' in a row, then the extent of the 'Testing' occurs, it must be under"IT "?  Right after you say that assumptions are correct, you give an example where 'Testing' occurs under 'IT' to a single line, but it is not less 'IT' to another line and where is 'One Team' under 'Testing' in a line, but is 'One Team' under 'Recruitment' in another row.

    When a situation like this occurs, how you cope?  Whenever you have a problem, please post the exact results you want from the given sample data, and an explanation of how you get these results.  If you don't know about what would be the ideal results, or if you are flexible on the exact results, then at least give an example and explain your reasons.

    Maybe you want to change the got_parent of subquery like this:

    WITH unpivoted_data AS

    (

    SELECT *.

    Employees

    UNPIVOT (node_name

    FOR lvl (level1 AS 1

    level2 AS 2

    level3 AS 3

    level4 AS 4

    level5 AS 5

    level6 AS-6

    )

    )

    )

    got_parent AS

    (

    SELECT c.node_name

    MIN (p.node_name) AS a parent

    Of unpivoted_data c

    LEFT OUTER JOIN unpivoted_data p ON p.employee = c.employee

    AND p.lvl = c.lvl + 1

    GROUP BY c.node_name

    )

    SELECT LPAD (' ' ')

    2 * (LEVEL - 1)

    ) || Node_name AS entity

    OF got_parent

    START WITH parent IS NULL

    Parent = node_name PRIOR CONNECTION

    ;

    In this way, if 'Test' is current 'IT' in one line, but not under what in another line, whether under would consider the 'IT' request and not to be a root.  If 'One Team' sudden 'Testing' in a line, but under "Recruitment" in another line, it will be (arbitrarily) consider it under "recruitment".

  • A map of OWB (service line) SQL query

    If I trace a session, run a map OWB (base line), the trace file contains the actual SQL query?

    The problem with me is that when I execute this rank - based OWB card, is throw me an error CursorFetchMapTerminationRTV20007, BUT (most time consuming) when I take on the intermediate SQL insert query, it works very well (and also in a very short time)

    The executing State = COMPLETE

    message = text ORA-06502: PL/SQL: digital or value error: character string buffer too small

    CursorFetchMapTerminationRTV20007 = message text

    N ° of task errors = 0

    N ° task warnings = 2

    N ° errors = 1

    Since this card OWB (truncate insert) is the line in function of where I can't back-end of the generated pl/sql package request OWB so I was wondering if I trace the session, check the trace file, maybe I'll able to see the exact SQL query generated. But I wanted to confirm the same.

    Yes, the real run SQL in session will be in the trace file.

Maybe you are looking for

  • After FireFox automatically updated my version of 19.0.2, I can't go to any page!

    I turn on firefox normally like I did thoundsand times before, I type Google.com, press on enter, he comes from loading for a second and then keep your stay on the start page. No matter what link I try to connect, firefox keep loading for a second an

  • Why Aurora has deleted find on page feature?

    Aurora I installed on my HTC Flyer with 3.2.1 honeycomb, I prefer Firefox 9, but I can find is more the text only a web page and bookmarks, we used to be able to hold to remove know that option went to. I can only delete if I go to the bookmark page,

  • Cannot find video message path of Vod in SQLite Database Browser

    Hello! Today, I downloaded SQ Lite Database Browser and open C/user /(Windows Name)/Appdata/Roaming/Skype /(Skype Name)/main.db. I found the video message that I want to save, but I found the path of vod column it was empty, there was no link. Why? H

  • cluster + case help

    Hello I'm learning clusters and unbundle by function name using a structure of matter. For some reason, my lead of the cluster is broken and he says the error is of the wrong data type, but I'm multiplication by a scalar, I do not understand why the

  • Resolution problem (W500) window

    Hi people, I used this computer for about 2 and a half years now.There is a curious problem now on my laptop, everytime I open specific files or open a Setup screen, it is always screwed up as if there is a problem of resolution. Here is an example.