How to format a value by using reg expression

Please, I need to format a value using regular expressions.
9911223344, 9911223344
9911223344
  11223344
Result
(99) 1122-3344, (99) 1122-3344
(99) 1122-3344
1122-3344
Some tips on how I can do this?

Kind regards

Hello

You were close.
The first 2 digits are optional, so add a '?' in the model.
This means that you will get results like ' ((1122-3344'), so use REPLACE to get rid of unwanted brackets.

SELECT  REPLACE ( REGEXP_REPLACE ( val
                            , '(\d{2})?'     -- ? added here
                           || '(\d{4})(\d{4})'
                            , '(\1) \2-\3'
                     )
          , '() '
          )       AS formatted_val
FROM    t
;

This assumes that "()" does not happen in the raw val. If so, use the REGEXP_REPLACE calls; a search of numbers with eactly 8 digits and the other looking for numbers with exactly 10 digits.

Tags: Database

Similar Questions

  • How to format a flash drive using windows 7?

    question: how to format a flash drive using windows 7 OS?

    Hello

    1. Connect the drive to a computer
    2. Click on the button - computer and locate the flash drive,
    3. Right-click on the Flash drive and select "Format".
    4. Click on 'start '.

    Note: Do not forget to save files you want to keep from a flash drive before formatting.

    It will be useful.

  • using reg expression

    I have a table called test with the names of column col1, col2.

    col1 value: 1234. col2 value: 1547

    I need o/p as 14 digits IE common present in the two columns.how to find it using reg expressions.

    Hello

    Here's another way, according to your needs:

    SELECT ename, empno, mgr

    , REGEXP_REPLACE (REGEXP_REPLACE ("0123456789")

    , '[^' || To_char (empno) | ] »

    )

    , '[^' || To_char (mgr). ] »

    ) AS common_digits

    FROM scott.emp

    ORDER BY ename

    ;

    The output does not include duplicate numbers, and the numbers will be in the order 0, 1, 2,..., 9, like this:

    ENAME, EMPNO, MGR COMMON_DIG

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

    7876 7788 78 ADAMS

    7499 7698 79 ALLEN

    7698 7839 789 BLAKE

    7782 7839 78 CLARK

    7902 7566 7 FORD

    7900 7698 79 JAMES

    7566 7839 7 JONES

    KING 7839

    7654 7698 67 MARTIN

    7934 7782 7 MILLER

    7788 7566 7 SCOTT

    SMITH, 7369 7902 79

    7844 7698 78 TURNER

    DISTRICT 7-7698-7521

    You can get the same results without regular expressions, perhaps more effectively.

  • By using only the keyboard, how can I create an email using Outlook Express, have the files of "painting" in the body of the email

    original title: only the keyboard

    By using only the keyboard, how can I create an email using Outlook Express, have the files of 'paint' in the body of the email, also registered another Web page?

    Hi r. Gull,.

    You can view using Outlook Express keyboard shortcuts, documented in:

    http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/mail_hotkeys.mspx?mfr=true

    I hope this helps.

  • How to swap two values without using the third variable using the procedure

    How to exchange the two values without using the third variable using the procedure?

    In a procedure using two mode we pass two values A = x and B = y, and let us pass parameters to receive the output has A = y and B = x without using the third variable

    Published by: Millar on August 19, 2012 11:23

    Your question doesn't seem wise. As written, there is no reason to a third variable, just

    CREATE OR REPLACE PROCEDURE(
      x IN number,
      y IN number,
      a OUT number,
      b OUT number
    )
    AS
    BEGIN
      a := y;
      b := x;
    END;
    

    If it's an interview question, I suspect that the intention was that you had two settings IN OUT and you wanted to swap the values without the help of a third variable.

    Justin

  • Qosmio F20 - how to format only C: partition using the recovery disk

    Hello

    My laptop is Qosmio F20

    After installing my OS using the recovery CD, I created more partitions... now, I have 5 partitions.
    Now I want to reinstall my OS on the C: where there already exist right now but I would like to format the C: partition until I use the "expert installation"...
    How can I do?

    Also, if I used the 'expert' facility that gives me the option to choose which partition I like to use. He reformatted the partition before installing or it is it will be overwritten?

    Thank you some much in advance.

    As far as I know the partition will be formatted quickly at first and then the recovery image is installed.

  • How to get all values when using IN paragraph?

    Hi all

    create the table test_case

    as

    Select ' AB-101' ord_no, to_date('06/17/2015','mm/dd/yyyy') dr_date, dr_type 'AB', 'ABC' double dr_name.

    Union of all the

    Select ' AB-100', to_date (' 17/04/2015 ',' mm/dd/yyyy'), 'AB', ' ABC' of the double

    Union of all the

    Select '124', to_date (' 06 / 07/2015 ', ' dd/mm/yyyy'), 'BB', 'BBA' from dual

    Union of all the

    Select '123', to_date (' 06 / 07/2015 ', ' dd/mm/yyyy'), 'BB', 'BBA' from dual

    Union of all the

    Select '145', to_date (' 06 / 07/2015 ', ' dd/mm/yyyy'), 'CC', "CCA" to double

    Union of all the

    Select '144', to_date (' 06 / 07/2015 ', ' dd/mm/yyyy'), 'CC', "CCA" to double

    Getting output

    AB-10117/06/2015ABABC
    AB-10017/04/2015ABABC
    12406/07/2015BBBBA
    12306/07/2015BBBBA
    14506/07/2015CCCOMMON COUNTRY ASSESSMENT
    14406/07/2015CCCOMMON COUNTRY ASSESSMENT

    Expected O/p

    Select max (ord_no), max (dr_date), max (dr_type), max (dr_name) of

    where test_case

    and dr_type in('AB','BB','CC')

    I have to use dr_type in ('AB', 'BB', 'CC')

    AB-10117/06/2015ABABC
    12406/07/2015BBBBA
    14506/07/2015CCCOMMON COUNTRY ASSESSMENT

    Are there opportunities to use CASE?

    Hello

    Rajesh123 wrote:

    Hi all

    create the table test_case

    as

    Select ' AB-101' ord_no, to_date('06/17/2015','mm/dd/yyyy') dr_date, dr_type 'AB', 'ABC' double dr_name.

    Union of all the

    Select ' AB-100', to_date (' 17/04/2015 ',' mm/dd/yyyy'), 'AB', ' ABC' of the double

    Union of all the

    Select '124', to_date (' 06 / 07/2015 ', ' dd/mm/yyyy'), 'BB', 'BBA' from dual

    Union of all the

    Select '123', to_date (' 06 / 07/2015 ', ' dd/mm/yyyy'), 'BB', 'BBA' from dual

    Union of all the

    Select '145', to_date (' 06 / 07/2015 ', ' dd/mm/yyyy'), 'CC', "CCA" to double

    Union of all the

    Select '144', to_date (' 06 / 07/2015 ', ' dd/mm/yyyy'), 'CC', "CCA" to double

    Getting output

    AB-101 17/06/2015 AB ABC
    AB-100 17/04/2015 AB ABC
    124 06/07/2015 BB BBA
    123 06/07/2015 BB BBA
    145 06/07/2015 CC COMMON COUNTRY ASSESSMENT
    144 06/07/2015 CC COMMON COUNTRY ASSESSMENT

    Expected O/p

    Select max (ord_no), max (dr_date), max (dr_type), max (dr_name) of

    where test_case

    and dr_type in('AB','BB','CC')

    I have to use dr_type in ('AB', 'BB', 'CC')

    AB-101 17/06/2015 AB ABC
    124 06/07/2015 BB BBA
    145 06/07/2015 CC COMMON COUNTRY ASSESSMENT

    Are there opportunities to use CASE?

    If you want a separate line of output for each distinct value of dr_type, then use GROUP BY dr_type.

    For example:

    SELECT MAX (ord_no) AS max_ord_no

    MAX (dr_date) AS max_dr_date

    , dr_type - no need to MAX here

    MAX (dr_name) AS max_dr_name

    FROM test_case

    WHERE dr_type IN ('AB', 'BB', 'CC')

    GROUP BY dr_type

    ;

  • How to increment the value by using "FORALL" instead of loop for

    declare

    VAR_TYP TYPE IS VARRAY (32767) OF VARCHAR2 (32767).

    V_DSH_CM_NUMBER VAR_TYP;
    V_DSH_DATE VAR_TYP;
    V_DSH_TIME VAR_TYP;

    V_DSD_CM_NUMBER VAR_TYP;
    V_PLU_CODE VAR_TYP;
    V_DSD_DATE VAR_TYP;
    V_str_id VAR_TYP;

    LN_ITM NUMBER: = 0;
    number of STR_ID: = 30001;

    CURSOR CUR_DBMG_SAL_HEAD
    IS
    SELECT DSH. CM_NUMBER, D_DSH_CM_DATE, D_DSH_CM_TIME
    OF DBMG_SAL_HEAD DSH
    WHERE ROWNUM < 6;

    BEGIN
    CUR_DBMG_SAL_HEAD OPEN;
    LOOP
    COLLECT FETCH CUR_DBMG_SAL_HEAD IN BULK
    BY V_DSH_CM_NUMBER,
    V_DSH_DATE,
    V_DSH_TIME;

    FOR indx IN V_DSH_CM_NUMBER. FIRST... V_DSH_CM_NUMBER. LAST
    LOOP
    SELECT CM_NUMBER, V_DSH_DATE, PLU_CODE (indx)
    TO COLLECT FEES IN BULK
    IN V_DSD_CM_NUMBER, V_PLU_CODE, V_DSD_DATE
    FROM DBMG_SAL_DETL DSD
    WHERE DSD. CM_NUMBER = V_DSH_CM_NUMBER (indx);

    -block1
    FORALL ind IN 1.V_DSD_CM_NUMBER. COUNTY
    INSERT INTO PC_ALL_TAB
    VALUES (V_DSH_CM_NUMBER (indx),
    V_DSD_DATE (IND),
    V_DSD_CM_NUMBER (IND),
    V_PLU_CODE (IND),
    LN_ITM,
    STR_ID
    );

    LN_ITM: = LN_ITM + 1;
    -block2

    END LOOP;

    WHEN THE OUTPUT CUR_DBMG_SAL_HEAD % NOTFOUND;
    END LOOP;

    commit;

    CLOSE CUR_DBMG_SAL_HEAD;
    DBMS_OUTPUT. PUT_LINE('COMPLETE..!');
    END;

    o/p:-SELECT DSH_CM_NUMBER, LN_ITM FROM PC_ALL_TAB;

    DSH_CM_NUMBER LN_ITM
    4177424 0
    4177422 1
    4177426 2
    4177426 2
    4177426 2
    4177425 3
    4177427 4
    4177427 4
    4177427 4

    I need result as below, for eachdsh_cm_number, I need incrementing value of ln_itm... but using 'FORALL '.

    DSH_CM_NUMBER LN_ITM
    4177424 0

    4177422 0

    4177426 0
    4177426 1
    4177426 2

    4177425 0

    4177427 0
    4177427 1
    4177427 2

    Hello

    Why not do it in single SQL?

    As far as I can decode what you want (you seem to have too many variables), you try to do something like:

    INSERT INTO pc_all_tab (dsh_cm_number,
                            dsd_date,
                            dsd_cm_number,
                            plu_code,
                            ln_itm,
                            str_id
                           )
      SELECT dsh.cm_number,
             dsh.d_dsh_cm_date,
             dsd.cm_number,
             dsd.plu_code,
             row_number () OVER (PARTITION BY dsh.cm_number ORDER BY NULL) - 1 AS ln_itm,
             '30001' str_id
      FROM   dbmg_sal_detl dsd, dbmg_sal_head dsh
      WHERE  dsd.cm_number(+) = dsh.cm_number
             AND ROWNUM < 6;
    

    Concerning
    Peter

  • I want to format my laptop and install windows xp but I have not cd player rom. someone can tell me how to format and install without using a cd rom?

    no error yet

    Hi x zero90,

    Thanks for posting. XP is available on CD-Rom. However there are other sites this list to install with a USB key ways. It is not tested so can not be guaranteed by Microsoft. Also, please make sure that you have a recognized reliable backup before performing any format.

    I hope this helps!  Shawn - Support Engineer - MCP, MCDST
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think

  • How to capture multiple line String using regular expressions?

    Hello

    I have a simple program like this:

    What I want to accomplish is to capture everything between > start and > to end with a single regular expression matching node. It seems that the definition of multiples? true or False does not help.

    I'm using LabVIEW 2012.

    If it is impossible to capture using a single node, that's fine. But I want to assure you that I can make full use of this node without combining several others.

    Thank you!

    > start([\w\s]*) > end

    A point matches any character except line break characters.  You have two of them.

  • How to get distinct records by using the ListAgg OBIEE report function?

    Hi all

    I get a correct result as mentioned below. But I don't see duplicates in my result here, in my example, I get duplicate for the name of the employee 'Pat '. So how to get Distinct values by using the LISTAGG function?

    Data set of sample with the Department and its employees

    Service employee

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

    Marketing Michael

    Pat of marketing

    Pat of marketing

    Pat of marketing

    Purchase of Den

    Purchase of Alexander

    Purchase of Shelli

    Purchase of Sigal

    Guy of purchase

    Purchase of Karen

    Using the ListAgg function, we can convert it to:

    Employees of the Department

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

    Marketing of Pat, Pat, Pat, Michael

    Purchase of Sigal, Shelli, Karen, Guy, Den, Alexander

    I tried a lot of things, but I'm not able to understand how exactly this can be achieved, if anyone has any idea or suggestions please do share, thanks in advance.

    After much research, I found the solution & I want to share what he finds very useful, we can create SQL logic in the Advanced tab, as below and after you click Rescan, and then you will get your desired results.

    SELECT saw_0, Evaluate_Aggr T1.dept ("ListAgg(%1,'' & '') intra group (about 1%)") ("as long as VarChar (1000), T1.emp) saw_1 FROM)

    SELECT 'emp_dept '. "the Department dept,

    'emp_dept '. "' employee ' emp

    IN THE "DOMAIN".

    GROUP BY dept, emp

    ) T1 GROUP FROM T1.dept ORDER BY saw_0

    Also note here that we have good anti-aliasing for columns parent (ex: saw_0, saw_1), another by mistake oracle bi server.

  • Of-Rube my code please Reg Expression maybe?

    Hi all!

    I will avoid solutions based text, but after looking at my code, I thought I can get a chance to learn a better way to do it.

    Problem:

    In LV 8.6 there is a problem when an individual 'node' in a VRML file result LV to crash if I try to open a file containing this node.

    Solution:

    Wirte code to check the file and remove the cruelest bad 'node' of trying to open it.

    IF this code works, but screams "This could we better using Reg expression?"

    I think the picture tells the story.

    NOTE: The case of non-visalbe just do the wires.

    THEN, share your thoughts please.

    Ben

    Even better than my original.  This is the beginning of the selection followed until the first byeverything '} ' (and line break).

    Kudos to ben64 for the tip.

  • I use OUtlook Express for e-mail. Night that suddenly disappeared from the value of a full year of emails - for example from October 2011 to the today October 2012. How can I get back them?

    I have been using Outlook Express 6 for more than 20 years without a single problem so far. Value of a full year of emails has disappeared all of a sudden my box but all e-mail messages seem to be always in place of my sent folder.

    How can I recover these e-mails Inbox?

    Two reasons the most common for what you describe is disruption of the compacting process, (never touch anything until it's finished), or bloated folders. More about that below.
     
    Why OE insists on compacting folders when I close it? :
    http://www.insideoe.com/FAQs/why.htm#compact
     
    Why mail disappears:
    http://www.insideoe.com/problems/bugs.htm#mailgone
     
    Recovery methods:
     
    If you are running XP/SP3, then you should have a backup of your dbx files in the Recycle Bin (or possibly the message store), copied as bak files.
     
    To restore a folder bak on the message store folder, first find the location of the message store.
     
    Tools | Options | Maintenance | Store folder will reveal the location of your Outlook Express files. Note the location and navigate on it in Explorer Windows or, copy and paste in start | Run.
     
    In Windows XP, the .dbx files are by default marked as hidden. To view these files in the Solution Explorer, you must enable Show hidden files and folders under start | Control Panel | Folder options | View.
     
    Close OE and in Windows Explorer, click on the dbx to the file missing or empty file, then drag it to the desktop. It can be deleted later once you have successfully restored the bak file. Minimize the message store.
     
    Open OE and, if the folder is missing, create a folder with the * exact * same name as the bak file you want to restore but without the .bak. For example: If the file is Saved.bak, the new folder should be named saved. Open the new folder, and then close OE. If the folder is there, but just empty, continue to the next step.
     
    First of all, check if there is a bak file already in the message. If there is, and you have removed the dbx file, go ahead and rename it in dbx.
     
    If it is not already in the message, open the trash and do a right-click on the file bak for the folder in question and click on restore. Open the message store up and replace the .bak by .dbx file extension. Close the message store and open OE. Messages must be in the folder.
     
    If messages are restored successfully, you can go ahead and delete the old dbx file that you moved to the desktop.
     
    If you have not then bak copies of your dbx files in the Recycle Bin:
     
    DBXpress run in extract disc Mode is the best chance to recover messages:
    http://www.oehelp.com/DBXpress/default.aspx
     
    And see:

    http://www.oehelp.com/OETips.aspx#4
     
     
     
     
    A general warning to help avoid this in the future:
     
    Do not archive mail in default OE folders. They finally are damaged. Create your own folders defined by the user for mail storage and move your mail to them. Empty the deleted items folder regularly. Keep user created folders under 300 MB, and also empty as is possible to default folders.
     
    Disable analysis in your e-mail anti-virus program. It is a redundant layer of protection that devours the CPUs, slows down sending and receiving and causes a multitude of problems such as time-outs, account setting changes and has even been responsible for the loss of messages. Your up-to-date A / V program will continue to protect you sufficiently. For more information, see:
    http://www.oehelp.com/OETips.aspx#3 
     
    And backup often.
     
    Outlook Express Quick Backup (OEQB Freeware)
    http://www.oehelp.com/OEBackup/default.aspx  
  • Windows 7 don't recognize the existence of the second drive hard unformated. How can I format drive's system does not recognize that there is so I can format the drive to use for backup?

    The two HDD are identical, WD750GB. Cannot find how to format a drive unreconized in help.
    First HARD drive is SATA and using 64-bit format and want to use the same for the second.

    Run Disk Manager , format the drive and it assign a drive letter:

    1. press the Windows Logo + R , type diskmgmt.msc in the box, and then click OK .
    2. right click on the drive and click format .
    3 right-click the disk, and then click change drive letter and paths .

    I don't know what you mean by "using the 64 bit format".

  • How to retrieve the values of character without using single quotes

    Hi all

    How to retrieve the values of character without the use of single quotes. Its Possible in Oracle SQL

    Please answer me...

    For example

    Is actual query-> Select * from employees where name like in("SCOTT", "JAMES", "ALBERT",...);

    I want to--> Select * from employees where name like(SCOTT, JAMES, ALBERT...); -without the use of single quotes.

    Why I need this application, I need to retrieve the records more than 200 employees in a select statement by using name in where clause.

    shagarmahabubjan wrote:

    Hi all

    How to retrieve the values of character without the use of single quotes. Its Possible in Oracle SQL

    Please answer me...

    For example

    Actual query is---> Select * from employees where name like in("SCOTT", "JAMES", "ALBERT",...);

    I want to---> Select * from employees where name like(SCOTT, JAMES, ALBERT...); -without the use of single quotes.

    Why I need this application, I need to retrieve the records more than 200 employees in a select statement by using name in where clause.

    In short... you can't.  The channels are channels, and SQL and PL languages dictate that the string literals are provided within single quotes.

    I don't see how trying to retrieve more than 200 records of employees in the select statement means that you must get rid of the quotes.

    Be clear in what you ask: Re: 2. How can I ask a question on the forums?

    and take note of the FAQ link davidp provided the solution "variable IN the list.

Maybe you are looking for

  • Re: Satellite Pro L870-172 keyboard Intermittent behavior

    I experience strange behavior with my keyboard mainly intermittent when using excel spreadheets where the screen zoom in and out, several cells are highlighted by trying to enter data, the data is copied to separate sheets & different characters are

  • iMac to start speaker crackles

    HelloI have an imac 21.5 "mid 2011 with OS 10.11.3is a few months to start the iMac, the speakers make a Crackle noise. It seems like an electrical interference independent of the volume of the speaker. I'd like to understand what depends on it and h

  • WRT54G in Australia

    I bought a Wireless Linksys WRT54G Router in the United States and am now decided to move to Australia.  Will it work here?  Someone he me Telestra "says that you can only use equipment approved by their Department. Thank you.

  • HP Officejet 7612 pilot error issues.

    I recently bought a HP Officejet 7612 all-in-one printer and it connects to my wireless network and when plugged directly into the computer with a USB cable, the computer recognizes it as a 7610 and then windows search for drivers, unless a driver is

  • White screen coming out of hibernation

    Have Windows 7 Home Premium on a Dell E1505 laptop. Coming from hibernation, the screen is a black screen with a flashing cursor in the upper left of the screen. By pressing the power button / power off then back on starts the laptop bios checks take