How to compare the first and last characters of strings?

lets say we have a name column with values;
c1
Antu Anamentu
Steven Smith
Since A=A and U=U for the first value we need a TRUE and FALSE for the second value SQL. Is this possible to do with REGEXP functions on 10gR2.
Thank you.

Hi Frank,
Just minor correction: REGEXP_LIKE (Name1, '^(.).*(.) \1.*\2$') ;
Explanation: ^(.) =>^ specifies the next char is first char
                            . dot specifies single character
                           ()  defines group which can be backrferenced
                   .* => Any number of characters as we want only first and last character
                  (.)  => (.)space The space signifies that we want to remember last char of first word or char before space
                   \1 => It recalls first group which we saved for backreference using (.)
                   .* => Any number of chars
                  \2 =>  It recalls first group which we saved for backreference using (.)
                   $ => It specifies the char before this is last charHope it clarifies :)
SQL> WITH t AS
SELECT 'Antu Anamentu' Name1 FROM DUAL UNION ALL
SELECT 'Steven Smith' Name1 FROM DUAL
SELECT Name1
FROM t
WHERE REGEXP_LIKE (Name1, '^(.).*(.) \1.*\2$')  ;
NAME1
Antu Anamentu

Similar Messages

  • Swapping the first and last characters in a column

    Hi,
    Fairly new to T-SQL and i want to swap the first and last characters in a column.
    Thanks
    Umar Javed

    Likewise i have also tried your suggestion and i still seem to be getting errors:
    IF (@TYPE = 'SCRAMBLE')
    BEGIN
    DECLARE @SQLCOMMAND VARCHAR(2000)
    SET @SQLCOMMAND = 'UPDATE ' + @TABLENAME + ' SET ' + @VALUE +
    STUFF(STUFF(@VALUE,1,1,RIGHT(@VALUE,1)),LEN(@VALUE),1,LEFT(@VALUE,1))
    EXECUTE(@SQLCOMMAND)
    END
    Umar Javed
    Please post the errors.
    EDIT: Actually looking at your code this will bring errors:
    IF (@TYPE = 'SCRAMBLE')
    BEGIN
    DECLARE @SQLCOMMAND VARCHAR(2000)
    SET @SQLCOMMAND = 'UPDATE ' + @TABLENAME + ' SET ' + @VALUE + ' = STUFF(STUFF('+@VALUE+',1,1,RIGHT('+@VALUE+',1)),LEN('+@VALUE+'),1,LEFT('+@VALUE+',1))'
    PRINT @SQLCOMMAND
    EXECUTE(@SQLCOMMAND)
    END
    I've also added a print command so it will show you what the code looks like upon concatenation. It's much easier to debug this way.

  • How to show the First and Last name of the user instead of user name

    Gurus,
    We have the full email id of the user as the portal user name. Right now we are using the "Item Attributes - Current User" to show the user name. We don't want to show this anymore. We would like to show the First and Last name of the user on the Portal page. How can i do this. Please post a reply if you have some idea about it.
    Thanks
    Raj
    ---------

    I believe this is possible using the security APIs. See http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/PLSQL/DOC/PLDOC_9026/INDEX.HTML and look for person_info (Returns user information, given a user name)
    under wwsec_api
    Suggest posting any follow-up questions to the Security forum - http://forums.oracle.com/forums/forum.jsp?forum=6

  • How to get the first and last record

    Hai All
    I have table called T1 and there are more than 8 lakhs records and i have a column called Timestamp so i need to get the first record value and time stampvalue and last record and time stamp value so that i can conclude that For Example
    form 13 june to 15 june data are here
    Kind Regards
    SrikkanthM

    Something like this can also indicate the first and last rows as you query...
    SQL> select empno, ename, hiredate
      2        ,case row_number() over (order by hiredate)
      3           when 1 then 'First Row'
      4           when count(*) over () then 'Last Row'
      5         end as flag
      6  from emp;
         EMPNO ENAME      HIREDATE            FLAG
          7369 SMITH      17/12/1980 00:00:00 First Row
          7499 ALLEN      20/02/1981 00:00:00
          7521 WARD       22/02/1981 00:00:00
          7566 JONES      02/04/1981 00:00:00
          7698 BLAKE      01/05/1981 00:00:00
          7782 CLARK      09/06/1981 00:00:00
          7844 TURNER     08/09/1981 00:00:00
          7654 MARTIN     28/09/1981 00:00:00
          7839 KING       17/11/1981 00:00:00
          7900 JAMES      03/12/1981 00:00:00
          7902 FORD       03/12/1981 00:00:00
          7934 MILLER     23/01/1982 00:00:00
          7788 SCOTT      19/04/1987 00:00:00
          7876 ADAMS      23/05/1987 00:00:00 Last Row
    14 rows selected.
    SQL>

  • How  we claculate the first and last date of the month

    hi,
    I have a requirement, if i have the any date of a month like today date 02/13/2008. So i want the first date of this month and the last date of this month.
    Is there any FM for this..or if you have nay prorgam pls send to me.
    thanks.

    Hi Vipin,
    Try
    HR_JP_MONTH_BEGIN_END_DATE FM will return both first day and last day
    LAST_DAY_OF_MONTHS  for getting last day of month.
    Reward if helpful.
    Regards,
    Mandeep

  • How to view the first and the last frame of a clip or a selected range in the time line?

    How to view the first and the last frame of a clip directly or in a selected range in the time line ? Up arrow and down arrow keys changes only between the first frame of the consecutive clips. Even ; and ' does the same. I mean what is the shortcut keys for first to last and last to first frame of a clip? Help please.

    SELECT PurOrderNum,
    OrderDate
    FROM
    SELECT PurOrderNum,
    OrderDate,
    MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
    MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'
    )t
    WHERE OrderDate = MaxDate
    OR OrderDate = MinDate
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, how do I select the first and last message and delete everything in between?

    How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, what do I select if I mark the first and last email to delete everything in between? Thanks.

    I have this same issue. I have over 100 email addresses that I need to add to a group. The issue is not making the group, it's getting the email addresses from Mail to Contacts.
    Dragging the email addresses does nothing. You can copy the addresses, but there's nowhere to put them. You can make a VCF for an email address, but then you have to find all of them to add them to the group. How do you automate this?!
    I'm astounded that there's so little support for such a common issue for which people have been asking for years.

  • How can I display the first and last name using a paramater as employee ID?

    Hi SAP,
    I have a parameter that is called {? Employee ID}.   What I want to do is display the first and last name based on the employee ID value entered in {? Employee ID} in the page header of the report.  Right now, when I put the following formula in the page header only some pages get the right result while other pages dont....
    if table.employeeid = {? Employee ID} then
    table.firstname" "table.lastname
    It appears as though if the first record in the details section on the beginning of each page happens to be the employee under {? Employee ID} then it prints it correctly, if it isn't I get a null value in the page header.
    Anyone have any ideas?
    Z

    Hi Try this,
    Whileprintingrecords;
    if ={?EmpID} then
    Also check the option "Default values for null" in the formula editor.
    Regards,
    Vinay

  • Chunk expressions: Need the first and last char position from member.word[x]?

    I need to build a linear list of the string positions of the
    first and last character of each word in a string. For example if I
    have the string myPet = “DOG CAT FISH” then myList =
    [[1,3],[5,7],[9,12]]
    myPet.word[x] will let me access the individual words but
    I’m not sure how to get the char position of the beginning
    and end of each. Please help, it’s Friday and my brain has
    left for the weekend.

    Touche, Sean.
    "Sean Wilson" <[email protected]> wrote in
    message
    news:fqa8ap$bga$[email protected]..
    > Hi Craig,
    >
    > Your's fails if any word is repeated. Try it with "DOG
    CAT FISH DOG"
    >
    > This one seems to work, although there are probably more
    efficient ways to
    > go about it. A regular expression and the PRegEx xtra
    would certainly be
    > quicker, especially as the string gets longer
    >
    > on mGetWordBoundaries aString
    > -- basic error check
    > if stringP(aString) = 0 then return []
    > if length(aString) = 0 then return []
    >
    > lWhitespace = [SPACE, TAB, RETURN, numToChar(10)]
    > tStart = 1
    > tChar = aString.char[tStart]
    > repeat while lWhitespace.getPos(tChar)
    > tStart = tStart + 1
    > tChar = aString.char[tStart]
    > end repeat
    >
    > lPositions = []
    > repeat with w = 1 to aString.word.count
    > tEnd = tStart + aString.word[w].char.count - 1
    > lPositions.append([tStart, tEnd])
    > tStart = tEnd + 1
    > tChar = aString.char[tStart]
    > repeat while lWhitespace.getPos(tChar)
    > tStart = tStart + 1
    > tChar = aString.char[tStart]
    > end repeat
    > end repeat
    > return lPositions
    > end

  • I've bought the season 1 of "The Wire" (7episodes), when I synchronize with my PC, it only charge the first and last episodes and not the 5 episodes in between ??

    I've bought the season 1 of "The Wire" (7episodes), when I synchronize with my PC, it only charge the first and last episodes and not the 5 episodes in between ??

    Hello spinozette,
    I am sure you are eager to download and watch Season 1 of The Wire.  I found a couple of resources that might help with downloading this purchase.
    First, I recommend checking to see if the download was interrupted.  You can use the steps in this article:
    iTunes: How to resume interrupted iTunes Store downloads
    http://support.apple.com/kb/HT1725
    If the episodes do not download after following the steps in that article, I recommend trying to download the episodes from the list of past purchases. You can find the steps to do this in the section titled "Apps, Books, Music, Movies, or TV shows on a computer" in the following article:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    http://support.apple.com/kb/HT2519
    If you are still not able to download the rest of the season, I recommend reporting this issue to the iTunes Store:
    How to report an issue with your iTunes Store, App Store, Mac App Store, or iBooks Store purchase
    http://support.apple.com/kb/HT1933
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • SQL Selecting the first and last entries for each day

    Hello SQL experts,
    I hope you can help with this.. I have a table (could have 1M or more rows in it) see structure below. I am looking to get the first and last date/times for each employee for each day. I also need the location GUID for the first read.
    EmployeeGUID (uniqueidentifier datatype)
    LocationGUID (uniqueidentifier datatype)
    DateTime (DateTime datatype)
    12345678-0000-0000-0000-000000000000
    11111111-0000-0000-0000-000000000000
    04/12/2014 07:00:01
    12345678-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/12/2014 10:40:05
    12345678-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/12/2014 17:04:02
    44422222-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/14/2014 08:00:00
    44422222-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/14/2014 14:00:03
    44422222-0000-0000-0000-000000000000
    33333333-0000-0000-0000-000000000000
    04/15/2014 07:49:00
    44422222-0000-0000-0000-000000000000
    11111111-0000-0000-0000-000000000000
    04/15/2014 09:00:01
    This would be the ideal output (I can do without the TotalTimeInHours):
    EmployeeGUID (uniqueidentifier datatype)
    LocationGUID (uniqueidentifier datatype)
    FirstRead (DateTime datatype)
    LastRead (DateTime datatype)
    TotalTimeInHours
    12345678-0000-0000-0000-000000000000
    11111111-0000-0000-0000-000000000000
    04/12/2014 07:00:01
    04/12/2014 17:04:02
    Total in hours between the first and last read.
    44422222-0000-0000-0000-000000000000
    22222222-0000-0000-0000-000000000000
    04/14/2014 08:00:00
    04/14/2014 14:00:03
    44422222-0000-0000-0000-000000000000
    33333333-0000-0000-0000-000000000000
    04/15/2014 07:49:00
    04/15/2014 09:00:01
    I would post what I have tried so far but I have been trying many different types of queries over the last few days. In short I need the employees first and last reads for each date. They could have many entries per date or just 1. I am certain that this
    is a trivial thing for a SQL expert but not trivial for me :).
    Thank you in advance!

    Thank you!
    This is almost what I need. The LocationGUID has to be included in the output. When I include it, I have to put it in the Group By clause. When I do that the reads are based on the LocationGUID (see below).
    ** I added a few more data entries and included the LocationGUID in the output.
    ***** SQL ***********
    CREATE TABLE test(  EmployeeGUID  uniqueidentifier, LocationGUID  uniqueidentifier, DateTimeCol  DateTime )Insert into test values
    ('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/12/2014 07:00:01')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 10:40:05')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 17:04:02')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/12/2014 19:00:00')
    ,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 08:00:00')
    ,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/14/2014 14:04:03')
    ,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 07:49:00')
    ,('44422222-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/15/2014 09:00:01')
    ,('12345678-0000-0000-0000-000000000000','11111111-0000-0000-0000-000000000000','04/13/2014 10:40:05')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 17:04:02')
    ,('12345678-0000-0000-0000-000000000000','22222222-0000-0000-0000-000000000000','04/13/2014 19:00:00')
    ;with mycte as (
    SELECT *, row_number() OVER(partition by EmployeeGUID, Cast(DateTimeCol as date)  Order by  DateTimeCol) rnASC,
     row_number() OVER (partition by EmployeeGUID, Cast(DateTimeCol as date)  Order by  DateTimeCol DESC) rnDESC
    FROM    test)
    Select EmployeeGUID ,Cast(DateTimeCol as date) dt,LocationGUID,
    Max(Case when rnASC=1 Then DateTimeCol End) minDateTimeCol
    ,Max(Case when rnDESC=1 Then DateTimeCol End ) maxDateTimeCol
    ,Datediff(minute, Max(Case when rnASC=1 Then DateTimeCol End) ,Max(Case when rnDESC=1 Then DateTimeCol End ) )/60.0  TotalTimeInHours
    from mycte
    Group by EmployeeGUID, LocationGUID,Cast(DateTimeCol as date)
    Order by dt,EmployeeGUID
    drop TABLE test
    **** OUTPUT **********
    EmployeeGUID
    dt
    LocationGUID
    minDateTimeCol
    maxDateTimeCol
    TotalTimeInHours
    12345678-0000-0000-0000-000000000000
    2014-04-12
    11111111-0000-0000-0000-000000000000
    2014-04-12 07:00:01.000
    NULL
    NULL
    12345678-0000-0000-0000-000000000000
    2014-04-12
    22222222-0000-0000-0000-000000000000
    NULL
    2014-04-12 19:00:00.000
    NULL
    12345678-0000-0000-0000-000000000000
    2014-04-13
    11111111-0000-0000-0000-000000000000
    2014-04-13 10:40:05.000
    NULL
    NULL
    12345678-0000-0000-0000-000000000000
    2014-04-13
    22222222-0000-0000-0000-000000000000
    NULL
    2014-04-13 19:00:00.000
    NULL
    44422222-0000-0000-0000-000000000000
    2014-04-14
    22222222-0000-0000-0000-000000000000
    2014-04-14 08:00:00.000
    2014-04-14 14:04:03.000
    6.066666

  • How to get the first and the last record of every month within a time range in sql

    I am trying to get the first record and the last record of each and every month in a given date range using sql. I have a sample code
    where i have just selected everything within the date range now i have to extract the first and the last records of each and every month.
    SELECT PurOrderNum,
    OrderDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'

    SELECT PurOrderNum,
    OrderDate
    FROM
    SELECT PurOrderNum,
    OrderDate,
    MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
    MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'
    )t
    WHERE OrderDate = MaxDate
    OR OrderDate = MinDate
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • When was the first and last login of a db user

    Hi @ all,
    I'm trying to find out the first and the last login of a special db user at an Oracle 10g (10.2.0.1.0) Instance.
    How can I do that?
    Thanks and best regards,
    David

    What Nicholas said is true, but depending what you are looking for, you may also search/review audit files created by everytime a sysdba or sysoper session was created by looking in your audit directory.
    From within sqlplus, "show parameter audit"
    Then, go to that directory and you will see hundreds/thousands of audit files for each time a sysdba or sysoper session was started.
    Within those logs are entries such as:
    Tue Mar 12 16:00:00 2013 -04:00
    LENGTH : '155'
    ACTION :[7] 'CONNECT'
    DATABASE USER:[1] '/'
    PRIVILEGE :[6] 'SYSDBA' <=========== sysdba or sysoper (I believe this is all that is captured.)
    CLIENT USER:[6] 'oracle' <=========== shows the OS user that connected to the database
    CLIENT TERMINAL:[0] ''
    STATUS:[1] '0'
    DBID:[10] '1321231341'

  • Find the first and last day of week giving a certain date

    Hi,
    i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?
    Many thanks in advance,
    Nuno Almeida

    nfalmeida wrote:
    i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?First step is being sure that you know what a 'week' is.
    For example does it really start on monday? And will it always start on monday?
    And what day does the 'week' end on for 2010-12-29? In some businesses it will end on 2010-12-31 (friday)

  • How to get the first and second quarter from CRT

    Dear Freinds,
                    I have one scenario , the Functional SPEC says Read the payroll results and from the CRT  get all the 4 quaters
    for the wage type /5UH  and sum them and then pass on the to field in the main strucutre.
    Iam using the FM HR_GET_PAYROLL_RESULTS
      CALL FUNCTION 'HR_GET_PAYROLL_RESULTS'
        EXPORTING
          pernr                         = fp_v_pernr
          permo                         = fp_v_permo
          pabrj                         = fp_v_pabrj
          pabrp                         = fp_v_pabrp
          actual                        = 'A'
        TABLES
          result_tab                    = i_payresult
        EXCEPTIONS
          no_results                    = 1
          error_in_currency_conversion  = 2
          t500l_entry_not_found         = 3
          period_mismatch_error         = 4
          t549q_entry_not_found         = 5
          internal_error                = 6
          wrong_structure_of_result_tab = 7
          OTHERS                        = 8.
    Iam collecting all the Actual Result (current result) values
    on the selection screen iam passing for month april (04 2008)
    so this falls in the second quater .
    the internal table   i_payresult is picking up only the second quater (01-04-2008 to 30/04/2008 )  ,but since on the selection screen iam pasing as other period (04 2008) the internal table  i_payresult  returing from the FM  (HR_GET_PAYROLL_RESULTS) only   picks the second quater,
    could any one let meknow how i can pick up the first quarter as well and add the first and second quater to mee the requirement .
    Please help me in this regard
    Thanks & regards
    maduri

    Hi Manoj,
                 Thank you for giving me idea for going further  regarding this problem , so my final question for this is
    as per FS they said they are going to enter the payroll
    area and the other selection as 04 2008 
    In order to achieve the first quarter , because 04 2008 means they are going to enter for the second quarter , the payroll results will come only for second quarter and not for the first quater , if they want to sum all the two quarters then they shouldnt pass on the selection screen   the dates as 04 2008, instead they has to pas
    01 01 2008 to 30 06 2008 , as there is no point in they passing as 04 2008 as we are going to consider from 01 2008 to 062008 .   Please correst me if am correct regarding the dates passing on teh selection screen
    or if the user enters on theslection screen still enter 04 2008 and will be  able to acheive the first quarter ??
    Please answer me this point before i can change the logic of the code and tell to my FO regarding this point.
    thanks & regards
    Madhuri

Maybe you are looking for

  • Refresh data source view gets 'column' argument cannot be null

    When I try to refresh a data source view in SQL Server 2008 BIDS, I get the error: System.Data   'column' argument cannot be null.  Parameter name: column.   How to resolve this?  The underlying tables have no data yet.

  • Repairing permissions gives me tons of errors

    I've been having trouble opening some apps (i.e Activity Monitor) so I figured I should repair my permissions. When I do so, I get a HUGE amount of errors, I'll include just a very small portion of them below. Any idea how to fix it? Thanks! Repairin

  • Adobe acrobat pro DC trial download error (Mac)

    When I try to download the trial version of Adobe acrobat DC pro on my mac, it gives an error "Acrobat installer encountered an unexpected failure. Please try again. If it continues to fail contact Adobe support". I have tried doing in about 5 times,

  • Facebook and Twitter on IPOd Touch 2G?

    Does anyone know if second generation iPod Touch can be upgraded to allow facebook and twitter to be used? The latest versions of both apps will not run with iOS 4.2 and there is no way to upgrade to iOS 5 or 6.  Does this mean we have to junk our tw

  • Importing Excel or CSV fields into PDF

    Is it possible to import fields from excel files or CSV files?  I would like to have the answers and questions from my old PDF forms re-created with the new PDF 11 forms. Please help.