Regular Expression.  Select Statement.  Carriage Return

Oracle 9i
Using SQLPLUS
I've read about regular expression and need some translation/explanation.
I have a large table containing a varchar2 (free text) column. Users may have inserted carriage returns when they entered the data. I need to locate rows that contain carriage returns, select and display them. Later I'll need to update those rows to replace the carriage returns with a space.
Can you assist with syntax. I believe use of a regular expression is required.
Thanks

for single characters like <CR> TRANSLATE() Doh. Never post at the end of a long day.
As the other posters have pointed out, one-for-one single character substitution is normally done with REPLACE(), although TRANSLATE() also works. The more normal role for TRANSLATE() is situations where you want to substitute multiple characters, e.g.
SQL> update <your table> set <your column> = replace (<your column> , chr(13)||chr(10), ' ');This substitutes a space for a carriage return and line feed combination.
Cheers, APC

Similar Messages

  • Howto create 'select statement' that returns first row? (simple table)

    quick question that drives me crazy:
    Say I have the following table:
    ID....car_model....point_A....total
    1........333.............NY..........54
    2........333.............NJ..........42
    3........333.............NH...........63
    4........555.............NJ...........34
    5........555.............PA...........55
    I would like to create a select statement that return car_model which the starting point is NJ - in this example it's only 555.
    thanks for any tips

    fair enough.
    the problem is this: given the table below, I need to create a report that reflects car rentals from specific location. you can rent a car from different locations; a car has a starting point (like a flight itinerary) so consider this:
    Mark rent a car with the following itinerary:
    NY--> NJ
    NJ--> PA
    PA-->FL
    FL-->LA
    the end user would like to see all car that were rented between X and Y and start point was NJ, so in the example above, the starting point is NY so it doesn't match the end users' criteria.
    The table is organized in the following manner: ID....car_model....point_A....total
    * I don't know whey the someone choose point_A as a column description as it just suppose to be 'location'
    so, back to my first example:
    ID....car_model....point_A....total
    1........333.............NY..........54
    2........333.............NJ..........42
    3........333.............NH...........63
    4........555.............NJ...........34
    5........555.............PA...........55
    if I do this:
    Select car_model from myTable where point_A='NJ'
    the return result will be 333 and 555 but that is in correct because 333 starting point is NY.
    I hope I provided enough information, thanks

  • I want a select statement to return two values, sum of one column and customer number

    I have two columns one called invoice_number and the other invoice_amount. I want a select statement to return two columns.... invoice_number and then the sum of the invoice_amount(s) for each unique invoice number.
    SELECT sum(invoice_amount) AS Totalinvoice_amount FROM InvoiceTB where invoice_number = 'INV102'
    This is where I've started, which returns:
    Totalinvoice_amount
    500.00
    Any help is appreciated.
    Please mark my post as helpful or the answer or better yet.... both! :) Thanks!

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • SELECT statement not returning NULL records

    I have the following SELECT statement:
    SELECT *
    FROM RPT_DS1_CNT_CAT
    WHERE DUPS_SAME <> 'N/A';
    I also tried:
    SELECT *
    FROM RPT_DS1_CNT_CAT
    WHERE DUPS_SAME != 'N/A';
    Same results - There ARE Null DUPS_SAME values
    which are not being selected. I get NO results.
    When I execute this, I do get NULL values.
    SELECT *
    FROM RPT_DS1_CNT_CAT
    WHERE DUPS_SAME IS NULL;
    How can I ensure that I get all non - 'N/A' records
    if it won't pick up the nulls? Is there a function
    I can use or a different wording? I do want to use
    != or <> because there may be other values besides
    'N/A' such as 'YES' or 'NO' and they may be null or
    filled with spaces.

    The expression
    NVL(DUPS_SAME,'') is meaningless. You're saying "If DUPS_SAME is NULL, return the empty string, which is NULL, otherwise return DUPS_SAME." If you're going to use NVL, the string that gets returned if the column is NULL should be non-NULL, i.e.
    NVL(DUPS_SAME,'DUPS_SAME was NULL') Your query should, as others have pointed out, either be
    SELECT *
      FROM rpt_ds1_cnt_cat
    WHERE dups_same <> 'N/A' OR dups_same IS NULLor
    SELECT *
      FROM rpt_ds1_cnt_cat
    WHERE NVL(dups_same, 'DUPS_SAME is NULL') <> 'N/A' Either of these return the same results as your query but they're going to be far clearer for whoever needs to maintain the code. There may be performance differences as well if DUPS_SAME is indexed depending on the data distribution...
    Justin

  • Select statement not returning correct data

    I'm working on an application and I'm having a weird problem. The application connects to an Oracle database, pulls out some data, and does something with it. In the process of testing I've already read and dealt with some rows. On those rows the UPDATE_FLAG field was changed to a N so they wouldn't be selected again.
    I do want to select those rows again, so with SQLPlus I changed the UPDATE_FLAG back to Y. Now here's the strange part. The same select statement run from SQLPlus is returning thoe row I modified, but my application does not.
    Here's the select statement:
    SELECT * FROM MY_TABLE WHERE UPDATE_FLAG = 'Y' and USER_ID like 'B%';
    When I run this I get a row back called Brian.
    In my application I do this:
    try
                   Class.forName("oracle.jdbc.driver.OracleDriver");               
                   Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@server:port:sid", "username", "password");
                   Statement st = conn.createStatement();
                   ResultSet rec = st.executeQuery("SELECT * FROM MY_TABLE WHERE UPDATE_FLAG = 'Y' and USER_ID like 'B%'");
                   System.out.println("SELECT * FROM MY_TABLE WHERE UPDATE_FLAG = 'Y' and USER_ID like 'B%'");
                   while(rec.next())
                        System.out.println(rec.getString("USER_ID"));
                   st.close();
              } catch (Exception e)
                   System.out.println("Error -- " + e.toString());
                   e.printStackTrace();
                }When this runs it doesn't return Brian and there are no exceptions caught. It's like it does not find it.
    Assuming I explained this well enough, anyone have any ideas what the problem could be?
    Thanks,
    James

    I do want to select those rows again, so with SQLPlus I changed the UPDATE_FLAG back to Y. Last time I ran SQLPlus I explicitly had to do a commit after modifications, because it was creating a transaction around the sqlplus session. Of course running a query in that session would work on the modified data rather than the actual data.

  • Cursor Expression Select Statement

    SELECT DNAME, CURSOR(SELECT SAL,COMM FROM EMP E WHERE E.DEPTNO = D.DEPTNO) FROM DEPT D
    DNAME CURSOR(SELECTSAL,COM
    ACCOUNTING CURSOR STATEMENT : 2
    CURSOR STATEMENT : 2
    SAL COMM
    2450
    5000
    1300
    RESEARCH CURSOR STATEMENT : 2
    CURSOR STATEMENT : 2
    SAL COMM
    800
    2975
    3000
    1100
    3000
    SALES CURSOR STATEMENT : 2
    CURSOR STATEMENT : 2
    SAL COMM
    1600 300
    1250 500
    1250 1400
    2850
    1500 0
    950
    6 rows selected.
    OPERATIONS CURSOR STATEMENT : 2
    CURSOR STATEMENT : 2
    no rows selected
    Can we get rid of "CURSOR STATEMENT : 2"(Also I don't know what is its
    significance there) from the output so that the output is in a readable format.
    Thanks,
    Neeraj Goel

    I want Data in the Format Like
    deptno cnt1
    cnt2
    cntN
    deptno cnt1
    cntM
    when you have a parent table (dept) and you sometimes
    want to see the child rows (emp) but "on demand". For example, you fetch
    "select deptno, cursor( from emp ) from dept" and the user says "hmmm, I'd like
    to see the emps in deptno 20" -- great, you just fetch that cursor and display
    them -- you didn't have to bring everyone else back with that query.
    Also useful when you have more then 1:M relationship in a query
    Now you can get a result set like:
    deptno Sal Comm
    Sal Comm
    Sal
    3 Sal, 2 Comm items and one deptno -- in one "row"
    Thats why i used cursor Expression.
    Thanks
    Neeraj Goel

  • How a SELECT statement can return the results in XML format

    That's it... I want to execute a query that returns all rowset in XML format. How can I do it?
    I have Oracle 9i
    Thanks
    Jaime

    9i, or 9iR2 ?. If 9i I would recommend upgrading to 9iR2 and then using the SQL/XML operators.

  • Regular Expression - Select two words after specific string

    Hi,
    I am trying to select the two words/strings after the first word "door". I am using the search pattern (?<=door).\w+ but in this case I get the complete text after the word "door". I only want to select the two words after the first "door" in the complete text.
    Can anybody help me?
    Thanks!
    Marco Snels

    Hi Marco,
    I'm relatively handy with RegEx but this seems like a problem where I would employ a little bit of RegEx and CTL, just to make life easier.
    You can use the following RegEx (note: I didn't test this in Integrator, only in a RegEx testing tool) to extract the two words after door (but including door, unfortunately):
    (?:door)[\s]\w+[\s]\w+
    This would give you something like the following in your extracted field:
    door is brown
    You could then pass through a re-formatter to remove "door" and the whitespace and be on your way. Not the best answer but should perform reasonably well and get you up and going.
    Regards,
    Patrick Rafferty
    http://branchbird.com

  • Help with Regular Expressions and regexp_replace

    Oh great Oracle Guru can I can gets some help
    I need to clean up the phone numbers that have been entered in Oracle eBusiness per_phones table. Some of the phone numbers have dashes, some have spaces and some have char. I would just like to take all the digits out and then re-format the number.
    Ex.
    914-123-1234 .. output (914) 123-1234
    9141231234 ..again (914) 123-1234
    914 123 1234 .. (914) 123-1234
    myphone ... just null
    (914)-123-1234.. (914) 123-1234
    I really tried to understand the regular expressions statments, but for some reason I just can't understand it.

    Hi,
    Welcome to the forum!
    I would create a user-defined function for this. I expect there will be a lot of exceptions to the regular rules (for example, strings that do not contain exactly 10 digits, such as '1-800-987-6543') that can be handled, but would require lots of nested fucntions and othwer complicted code if you had to do it in a single statement.
    If you really want to do it with a regular expression:
    SELECT     phone_txt
    ,     REGEXP_REPLACE ( phone_txt
                     , '^\D*'          || -- 0 or more non-digits at the beginning of the string
                           '(\d\d\d)'     || -- \1 = 3 consecutive digits
                    '\D*'          || -- 0 or more non-digits
                           '(\d\d\d)'     || -- \2 = 3 consecutive digits
                    '\D*'          || -- 0 or more non-digits
                           '(\d\d\d)'     || -- \3 = 4 consecutive digits
                    '\D*$'             -- 0 or more non-digits at the end of the string
                     , '(\1) \2-\3'
                     )          AS new_phone_txt
    FROM    table_x
    ;

  • Introduction to regular expressions ... continued.

    After some very positive feedback from Introduction to regular expressions ... I'm now continuing on this topic for the interested audience. As always, if you have questions or problems that you think could be solved through regular expression, please post them.
    Having fun with regular expressions - Part 2
    Finishing my example with decimal numbers, I thought about a method to test regular expressions. A question from another user who was looking for a way to show all possible combinations inspired me in writing a small package.
    CREATE OR REPLACE PACKAGE regex_utils AS
      -- Regular Expression Utilities
      -- Version 0.1
      TYPE t_outrec IS RECORD(
        data VARCHAR2(255)
      TYPE t_outtab IS TABLE OF t_outrec;
      FUNCTION gen_data(
        p_charset IN VARCHAR2 -- character set that is used for generation
      , p_length  IN NUMBER   -- length of the generated
      ) RETURN t_outtab PIPELINED;
    END regex_utils;
    CREATE OR REPLACE PACKAGE BODY regex_utils AS
    -- FUNCTION gen_data returns a collection of generated varchar2 elements
      FUNCTION gen_data(
        p_charset IN VARCHAR2 -- character set that is used for generation
      , p_length  IN NUMBER   -- length of the generated
      ) RETURN t_outtab PIPELINED
      IS
        TYPE t_counter IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;
        v_counter t_counter;
        v_exit    BOOLEAN;
        v_string  VARCHAR2(255);
        v_outrec  t_outrec;
      BEGIN
        FOR max_length IN 1..p_length 
        LOOP
          -- init counter loop
          FOR i IN 1..max_length
          LOOP
            v_counter(i) := 1;
          END LOOP;
          -- start data generation loop
          v_exit := FALSE;
          WHILE NOT v_exit
          LOOP
            -- start generation
            v_string := '';
            FOR i IN 1..max_length
            LOOP
              v_string := v_string || SUBSTR(p_charset, v_counter(i), 1);
            END LOOP;
            -- set outgoing record
            v_outrec.data := v_string;
            -- now pipe the result
            PIPE ROW(v_outrec);
            -- increment loop
            <<inc_loop>>
            FOR i IN REVERSE 1..max_length
            LOOP
              v_counter(i) := v_counter(i) + 1;     
              IF v_counter(i) > LENGTH(p_charset) THEN
                 IF i > 1 THEN
                    v_counter(i) := 1;
                 ELSE
                    v_exit := TRUE;  
                 END IF;
              ELSE
                 -- no further processing required
                 EXIT inc_loop;  
              END IF;  
            END LOOP;        
          END LOOP; 
        END LOOP; 
      END gen_data;
    END regex_utils;
    /This package is a brute force string generator using all possible combinations of a characters in a string up to a maximum length. Together with the regular expressions, I can now show what combinations my solution would allow to pass. But see for yourself:
    SELECT *
      FROM (SELECT data col1
              FROM TABLE(regex_utils.gen_data('+-.0', 5))
           ) t
    WHERE REGEXP_LIKE(NVL(REGEXP_SUBSTR(t.col1,
                                         '^([+-]?[^+-]+|[^+-]+[+-]?)$'
                       '^[+-]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)[+-]?$'
    ;You will see some results, which are perfectly valid for my definition of decimal numbers but haven't been mentioned, like '000' or '+.00'. From now on I will also use this package to verify the solutions I'll present to you and hopefully reduce my share of typos.
    Counting and finding certain characters or words in a string can be a tedious task. I'll show you how it's done with regular expressions. I'll start with an easy example, count all spaces in the string "Having fun with regular expressions.":
    SELECT NVL(LENGTH(REGEXP_REPLACE('Having fun with regular expressions', '[^ ]')), 0)
      FROM dual
      ;No surprise there. I'm replacing all characters except spaces with a null string. Since REGEXP_REPLACE assumes a NULL string as replacement argument, I can save on adding a third argument, which would look like this:
    REGEXP_REPLACE('Having fun with regular expressions', '[^ ]', '')So REPLACE will return all the spaces which we can count with the LENGTH function. If there aren't any, I will get a NULL string, which is checked by the NVL function. If you want you can play around by changing the space character to somethin else.
    A variation of this theme could be counting the number of words. Counting spaces and adding 1 to this result could be misleading if there are duplicate spaces. Thanks to regular expressions, I can of course eliminate duplicates.
    Using the old method on the string "Having fun with regular expressions" would return anything but the right number. This is, where Backreferences come into play. REGEXP_REPLACE uses them in the replacement argument, a backslash plus a single digit, like this: '\1'. To reference a string in a search pattern, I have to use subexpressions (remember the round brackets?).
    SELECT NVL(LENGTH(REGEXP_REPLACE('Having  fun  with  regular  expressions', '( )\1*|.', '\1')))
      FROM dual
      ;You may have noticed that I changed from using the "^" as a NOT operator to using the "|" OR operator and the "." any character placeholder. This neat little trick allows to filter all other characters except the one we're looking in the first place. "\1" as backreference is outside of our subexpression since I don't want to count the trailing spaces and is used both in the search pattern and the replacement argument.
    Still I'm not satisfied with this: What about leading/trailing blanks, what if there are any special characters, numbers, etc.? Finally, it's time to only count words. For the purpose of this demonstration, I define a word as one or more consecutive letters. If by now you're already thinking in regular expressions, the solution is not far away. One hint: you may want to check on the "i" match parameter which allows for case insensitive search. Another one: You won't need a back reference in the search pattern this time.
    Let's compare our solutions than, shall we?
    SELECT NVL(LENGTH(REGEXP_REPLACE('Having  fun  with  regular  expressions.  !',
                                     '([a-z])+|.', '\1', 1, 0, 'i')), 0)
      FROM dual;This time I don't use a backreference, the "+" operator (remember? 1 or more) will suffice. And since I want to count the occurences, not the letters, I moved the "+" meta character outside of the subexpression. The "|." trick again proved to be useful.
    Case insensitive search does have its merits. It will only search but not transform the any found substring. If I want, for example, extract any occurence of the word fun, I'll just use the "i" match parameter and get this substring, whether it's written as "Fun", "FUN" or "fun". Can be very useful if you're looking for example for names of customers, streets, etc.
    Enough about counting, how about finding? What if I want to know the last occurence of a certain character or string, for example the postition of the last space in this string "Where is the last space?"?
    Addendum: Thanks to another forum member, I should mention that using the INSTR function can do a reverse search by itself.[i]
    WITH t AS (SELECT 'Where is the last space?' col1
                 FROM dual)
    SELECT INSTR(col1, ' ', -1)
      FROM DUAL;Now regular expressions are powerful, but there is no parameter that allows us to reverse the search direction. However, remembering that we have the "$" meta character that means (until the) end of string, all I have to do is use a search pattern that looks for a combination of space and non-space characters including the end of a string. Now compare the REGEXP_INSTR function to the previous solution:
    SELECT REGEXP_INSTR(t.col1, ' [^ ]*$')                       
      FROM t;So in this case, it'll remain a matter of taste what you want to use. If the search pattern has to look for the last occurrence of another regular expression, this is the way to solve such a requirement.
    One more thing about backreferences. They can be used for a sort of primitive "string swapping". If for example you have to transform column values like swapping first and last name, backreferenc is your friend. Here's an example:
    SELECT REGEXP_REPLACE('John Doe', '^(.*) (.*)$', '\2, \1')
      FROM dual
      ;What about middle names, for example 'John J. Doe'? Look for yourself, it still works.
    You can even use that for strings with delimiters, for example reversing delimited "fields" like in this string '10~20~30~40~50' into '50~40~30~20~10'. Using REVERSE, I would get '05~04~03~02~01', so there has to be another way. Using backreferences however is limited to 9 subexpressions, which limits the following solution a bit, if you need to process strings with more than 9 fields. If you want, you can think this example through and see if your solution matches mine.
    SELECT REGEXP_REPLACE('10~20~30~40~50',
                          '^(.*)~(.*)~(.*)~(.*)~(.*)$',
                          '\5~\4~\3~\2~\1'
      FROM dual;After what you've learned so far, that wasn't too hard, was it? Enough for now ...
    Continued in Introduction to regular expressions ... last part..
    C.
    Fixed some typos and a flawed example ...
    cd

    Thank you very much C. Awaiting other parts.... keep going.
    One german typo :-)
    I'm replacing all characters except spaces mit anull string.I received a functional spec from my Dutch analyst in which it is written
    tnsnames voor EDWH:
    PCESCRD1 = (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
                                                   (HOST=blah.blah.blah.com)
                                                   (PORT=5227)))
               (CONNECT_DATA=(SID=pcescrd1)))
    db user: BW_I2_VIEWER  / BW_I2_VIEWER_SCRD1Had to look for translators.
    Cheers
    Sarma.

  • How to get all values from an interval using select statement

    Hi,
    Is it possible to write a select statement that returns all values from an interval? Interval boundaries are variable.
    something like this:
    select (for x in 1,1024 loop x end loop) from dual
    (this, of course, doesn't work)
    The result in this example should be 1024 rows of numbers from 1 to 1024. These numbers are parameters, so it is not possible to create a table with predefined values.
    Thanks in advance for your help,
    Mia.

    For your simple case, with a lower boundary of 1, you can use:
    SELECT rownum
    FROM all_objects
    WHERE rownum <= 1024For a set of number between say 50 - 100, you can use something like:
    SELECT rownum + (50 - 1)
    FROM all_objects
    WHERE rownum <= (100 - 50 + 1)Note, that all_objects was used only because it generally has a lot of rows. Any table with at least the number of rows in your range will work.
    TTFN
    John

  • HTML DB  Select Statement in HTML HEADER

    Can I put a select statement that return a value in the HTML HEADER?
    If I can How? Would point the way.
    Second Question
    Can I call store function from HTML HEADER? Help!

    I have a report screen that has Delete button. Each record on the screen has a checkbox
    What I would like to do is:
    when the user puts a check in the checkbox and click the Delete button. a message will pop up and ask "Are you usre?" If the user click Yes then the system will check for child record. If there no No child record go head delete the record. If there is a child record then another message pop up and ask "This Schedule is currently active. Do you really want to delete this." If the user answers Yes then it will delete both parent and child records. If the user answer no then no record will be deleted.
    I have been struggle with this in HTML DB for a bit, but I did not find the solution yet. Please Help!!!!

  • Issue with Select options in select statement - ABAP Question

    Hi
    I am facing an issue with select options. Select statement is returning sy-subrc as 4.
    I wrote the program as below:
    SELECT-OPTIONS:
    s_kunnr FOR bsad-kunnr,
    s_lifnr FOR bsak-lifnr,
    s_gjahr FOR bsad-gjahr,
    s_bukrs FOR bsad-bukrs,
    s_saknr FOR bsad-saknr,
    s_budat FOR bsak-budat.
    In start of selection I have written the select statement as
    SELECT * FROM bsak INTO TABLE lt_bsak
    WHERE bukrs IN s_bukrs AND lifnr = s_lifnr AND gjahr IN s_gjahr AND budat IN s_budat AND saknr IN s_saknr.
    In selection screen I have not entered any values and executed the program. I am not getting any result. When I debug that, sy-subrc is 4 at above select statement. But table has records.
    If am removing the "lifnr = s_lifnr " condition in select then select is returning values.
    I am not getting where I made the mistake. Please suggest.
    Thank you
    Hanu

    Hi,
    The problem here with where condition select option lifnr = s_lifnr.
    Use below select query.
    SELECT * FROM bsak INTO TABLE lt_bsak
    WHERE bukrs IN s_bukrs
        AND lifnr     IN s_lifnr
        AND gjahr   IN s_gjahr
        AND budat  IN s_budat
        AND saknr  IN s_saknr.
    s_lifnr is a select option and you are passing it as parameter lifnr = s_lifnr.
    if you want to pass this s_lifnr as single vale then pass in below mentioned way.
    lifnr = s_lifnr-low
    BR,
    Vijay

  • How to put OR clause in SELECT statement

    Hi
    How to put OR clause in SELECT statement to return number_first/number_last to match records from another table's column.
    <pre>
    SELECT
    a.id ,
    flat_number ||' '|| a.number_first||' '||a.street_name||' '||a.suburb address1,
    apt_no ||' '|| street_no||' '||b.street_name||' '||b.suburb address2
    from
    a ,
    b
    where b.street_name = a.street_name
    AND b.SUBURB = a.SUBURB
    AND b.STATE = a.STATE
    </pre>
    Thsi will return this as exact match.
    ADDRESS 1
    12 TAMAN TENANG A ORCHARD 3142     
    10 RAMA YISHUN 2095
    ADDRESS2
    12 TAMAN TENANG A ORCHARD 3142     
    10 RAMA YISHUN 2095
    However this only matches number_first.
    How can I get the query work that it will match both number_first and number_last (table b)in address 1 to match street_no in address2 ( table b).My oracle version is 10GR/2.

    Hi, I have a hard time understanding your request, and below is what I thought you want:
    SELECT
        a.id ,
           flat_number ||' '|| (decode(b.street_no, a.number_first, a.number_first, a.number_last, a.number_last)||' '||a.street_name||' '||a.suburb  address1,
             apt_no ||' '|| street_no||' '||b.street_name||' '||b.suburb address2
          from
                 a ,
                 b
                where          b.street_name = a.street_name
                 AND            b.SUBURB      = a.SUBURB
                AND            b.STATE       = a.STATE
                AND  (B.street_no=a.number_first OR b.street_no=a.number_last);Not tested.
    Also, since your B.street_no will be either a.number_first OR a.number_last, you could replace
    (decode(b.street_no, a.number_first, a.number_first, a.number_last, a.number_last) with just b.street_no.
    Edited by: PhoenixBai on Aug 26, 2010 11:33 AM

  • ? on Regular Expressions

    I am trying to use a regular expression to spot an empty string but it isn't working within Oracle ... regexp_like(:P13_ADDRESS,'^$')
    Shouldn't this expression work '^$' ???????

    Justin,
    a few Oracle facts regarding the handling of null values:
    1) the empty string '' is equivalent to NULL
    2) an operation (using oracle built-in operators / functions) on a NULL value will always result in a null value
    consider the following example for illustration purposes:
    set serveroutput on
    DECLARE
       l_str   VARCHAR2 (100);
    BEGIN
       l_str := '';
       IF l_str IS NULL THEN
          DBMS_OUTPUT.put_line ('empty string is null');
       END IF;
       IF TO_NUMBER ('') IS NULL THEN
          DBMS_OUTPUT.put_line ('conversions on null will yield null as output');
       END IF;
    END;
    That's what it seems to be doing, as my example showed. I don't quite agree with this,
    NULL is a RDBMS concept, it should match a empty string (^$), but Oracle's regexp
    implementation doesn't seem to be doing this, so just NVL it.Well, regarding the logic behind (2), that all operations on a null value will result in a null value, it does indeed make sense that the regular expression applied to null returns null.
    And in a boolean context (like in the if-clause) null will be equivalent to false. This can be tricky at times!
    Thus I would use the following code (illustrated by a stored function) to check for an empty string
    CREATE OR REPLACE FUNCTION is_empty (p_str IN VARCHAR2)
       RETURN BOOLEAN IS
       l_str   VARCHAR2 (2000) := TRIM (p_str);  -- remove leading and trailing spaces
    BEGIN
       IF l_str IS NULL THEN
          RETURN TRUE;
       ELSE
          RETURN FALSE;
       END IF;
    END;
    /~Dietmar.

  • Group by week on select statement

    Hi friends,
    I have a select statement which returns me the data that i need to group it on a weekly basis. The week starts from wednesday morning to tuesday night. what should e the syntax for group by clause to get the desired result. I am using the bar chart to display the results.
    Please let me know.
    Regards,
    Pradeep

    I have moved this question to SQL/PLSQL forum.

Maybe you are looking for