SQL LIKE statement help

Hi all,
I want to select all values from prps-usr00 where the field contains XXX-XXXX...where X is any letter or number. How in the world do I do that?
Thanks,
Mat

Hi,
SELECT SOMETHING INTO VARIABLE FROM TABLE
                                     WHERE PARAM1 LIKE '%-%'.
Or
If you know that there will be exactly 2 char in front of '-' and 2 char after. then use.
SELECT SOMETHING INTO VARIABLE FROM TABLE
                                 WHERE PARAM1 LIKE '__-__'.
Regards
madhu
Edited by: madhu tatikonda on Jun 27, 2008 9:08 PM

Similar Messages

  • Complex query using 'sql like' statement.

    Given the following basic class structure.
    public class Project {
         private String name;
         private Architecture architecture;
         private Resources resources;
         public Architecture getArchitecture();
         public void setArchitecture(Architecture architecture);
         public Resources getResources();
         public void setResources();
         public String getName();
         public void setName(String name);
    public Architecture {
         private String name;
         public String getName();
         public void setName(String name);
    public Resources {
         private String name;
         public String getName();
         public void setName(String name);
    we want to be able to do a query like:
         find all Projects where (Project.name.indexOf("a") > 0) &&
    (Project.architecture.name.indexof("b") > 0)
    In essence a "like" comparison across String properties of the JDO objects.
    Is it supported in KODO?? Anyone tried it out? Also, is it possible to
    generate SQL type query in KODO?
    rgds
    NK

    Note that this relies on a current bug in Kodo -- we should escape out the
    '%' character, but we don't.
    Some day, we'll fix that bug. But, before then, we will introduce a proper,
    supported mechanism for finding records that have a string field that
    contains some substring.
    -Patrick
    On 5/30/02 6:12 PM, "Andrew" <[email protected]> wrote:
    Hi,
    I wanted to perform a LIKE statement to get records where the partial string
    existed in a field -> eg. select a where a.field LIKE "SPRING" - 2 records,
    SpringSteen & MindSprings
    I did it like this:
    setFieldName("Spring");
    String sFilter = "field.startsWith(%\" + getFieldName() + \"%)"; -
    Extent anExtent = pm.getExtent(this.getClass(), true);
    Query aQuery = pm.newQuery(this.getClass(), anExtent, sFilter);
    return (Collection) aQuery.execute();
    Hope it helps. oh, don't know about the generating sql query.
    Nitin Kanani wrote:
    Given the following basic class structure.
    public class Project {
    private String name;
    private Architecture architecture;
    private Resources resources;
    public Architecture getArchitecture();
    public void setArchitecture(Architecture architecture);
    public Resources getResources();
    public void setResources();
    public String getName();
    public void setName(String name);
    public Architecture {
    private String name;
    public String getName();
    public void setName(String name);
    public Resources {
    private String name;
    public String getName();
    public void setName(String name);
    we want to be able to do a query like:
    find all Projects where (Project.name.indexOf("a") > 0) &&
    (Project.architecture.name.indexof("b") > 0)
    In essence a "like" comparison across String properties of the JDO
    objects.
    Is it supported in KODO?? Anyone tried it out? Also, is it possible to
    generate SQL type query in KODO?
    rgds
    NK
    Patrick Linskey [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • SQL LIKE statement in JSP

    I tried to write a query in jsp page using LIKE statement. However, Apache Tomcat report back an error in the query string. I tried to run the same query style in MS Access and it works. Can someone please tell me where is the error in jsp code:
    JSP Code:
    sql = "SELECT tblStudent.firstName, tblStudent.lastName, tblStudent.studentID FROM tblStudent WHERE (((tblStudent.firstName) LIKE '%" + g_firstNameInput + "%')) ORDER BY tblStudent.firstName";
    MS Acccess:
    SELECT tblStudent.firstName, tblStudent.lastName, *
    FROM tblStudent
    WHERE (((tblStudent.firstName) Like '*e*'))
    ORDER BY tblStudent.firstName;
    PS: I tried changing from '%' to '*' already, but still does not work
    Thanks

    Don't use JSP for SQL querries... to complicated.
    1) Write a Java application that does what you want (as far as interacting with the database
    2) Isolate the database access code into its own class/classes
    3) Double check that you can then use those isolated classes inside a command line application
    4) Adapt the code you used in 3) to use those same classes from a JSP - preferrably using Java Beans and DTOs

  • Sql Like statement

    how can i get all records starting with % ?

    Something that I found here (
    SQL Tutorial) might
    help:
    The optional ESCAPE sub-clause specifies an escape character for
    the pattern, allowing the pattern to use '%' and '_' (and the
    escape character) for matching. The ESCAPE value must be a single
    character string. In the pattern, the ESCAPE character precedes any
    character to be escaped.
    For example, to match a string ending with '%', use:
    x LIKE '%/%' ESCAPE '/'
    ..or here
    Using
    SQL Escape Sequences
    ... or here
    How
    to escape a wildcard in an SQL order with ORACLE.
    Phil

  • SQL "LIKE" statement isn't working right -- help please!

    Good day everyone,
    I thought about putting this in the "SQL on Oracle" forum, but it looked like those messages were geared more toward the Oracle platform itself, so here I am.  I apologize if this isn't the best forum.
    I have the following SQL statement:
      SELECT zzreporting_ut1
             zzreporting_ut2
             zzreporting_ut3
             zzreporting_ut4
             zzreporting_ut5
          UP TO 1000 ROWS
          INTO TABLE it_gmia_gmgrresp_data
            FROM gmspprogram
       WHERE ( ( zzreporting_ut1 LIKE '4011%'   OR
                 zzreporting_ut1 LIKE '4012%'   OR
                 zzreporting_ut1 LIKE '4013%' ) OR
               ( zzreporting_ut2 LIKE '4011%'   OR
                 zzreporting_ut2 LIKE '4012%'   OR
                 zzreporting_ut2 LIKE '4013%' ) OR
               ( zzreporting_ut3 LIKE '4011%'   OR
                 zzreporting_ut3 LIKE '4012%'   OR
                 zzreporting_ut3 LIKE '4013%' ) OR
               ( zzreporting_ut4 LIKE '4011%'   OR
                 zzreporting_ut4 LIKE '4012%'   OR
                 zzreporting_ut4 LIKE '4013%' ) OR
               ( zzreporting_ut5 LIKE '4011%'   OR
                 zzreporting_ut5 LIKE '4012%'   OR
                 zzreporting_ut5 LIKE '4013%' ) ).
    All I want to do is bring back the rows where one of those 5 "ut" fields begins with 4011, 4012, or 4013.  However, when I run it, it brings back anything:  rows where all 5 "ut" fields are empty, where the ut1 field begins with 4014, etc.
    Does anyone know what I'm doing wrong in my SQL statement?
    Thank you!  And as always, points awarded for ALL HELPFUL answers!
    Dave
    Edited by: Dave Packard on Jul 1, 2008 2:18 PM

    Hi Dave,
    because I don't know such a table named gmspprogram I'm not sure what to say.
    According to boolean expression syntax you do not need any of the brackets because the only operator used is OR.
    I'd suggest.
    data: lt_pattern_range type range of gmspprogram-zzreporting_ut2.
    perform insert_range using 'ICP':
      '4011*' '' changing lt_pattern_range,
      '4012*' '' changing lt_pattern_range,
      '4013*' '' changing lt_pattern_range.
    SELECT
      zzreporting_ut1
      zzreporting_ut2
      zzreporting_ut3
      zzreporting_ut4
      zzreporting_ut5
      UP TO 1000 ROWS
      INTO CORRESPONDING FIELDS OF TABLE it_gmia_gmgrresp_data
      FROM gmspprogram
      WHERE zzreporting_ut1 in lt_pattern_range
         OR zzreporting_ut2 in lt_pattern_range
         OR zzreporting_ut3 in lt_pattern_range
         OR zzreporting_ut4 in lt_pattern_range.
    * need form
    *&      Form  insert_range
    *       insert selection range - handles any range type "CLI20061218
    FORM insert_range  USING    p_signopt     TYPE c            "#EC CALLED
                                p_low         TYPE any
                                p_high        TYPE any
                       CHANGING pt_range      TYPE table.
      FIELD-SYMBOLS:
        <range>                               TYPE ANY,
        <sign>                                TYPE ANY,
        <option>                              TYPE ANY,
        <low>                                 TYPE ANY,
        <high>                                TYPE ANY.
      DATA:
        lv_ref                                TYPE REF TO data.
      CHECK NOT (
                  p_low     IS INITIAL AND
                  p_high    IS INITIAL ).
      CREATE DATA lv_ref                      LIKE LINE OF pt_range.
      ASSIGN lv_ref->* TO <range>.
      CHECK sy-subrc                          = 0.
      ASSIGN COMPONENT 'SIGN' OF STRUCTURE <range> TO <sign>.
      CHECK sy-subrc                          = 0.
      ASSIGN COMPONENT 'OPTION' OF STRUCTURE <range> TO <option>.
      CHECK sy-subrc                          = 0.
      ASSIGN COMPONENT 'LOW' OF STRUCTURE <range> TO <low>.
      CHECK sy-subrc                          = 0.
      ASSIGN COMPONENT 'HIGH' OF STRUCTURE <range> TO <high>.
      CHECK sy-subrc                          = 0.
      <sign>                                  = p_signopt(1).
      <option>                                = p_signopt+1(2).
      <low>                                   = p_low.
      <high>                                  = p_high.
      READ TABLE pt_range WITH KEY table_line = <range> BINARY SEARCH
        TRANSPORTING NO FIELDS.
      CHECK sy-subrc                          <> 0.
      INSERT <range> INTO pt_range INDEX sy-tabix.
    ENDFORM.                    " insert_range
    At least - I think - this looks better. And you may reuse the FORM insert_range whereever you want.
    Regards,
    Clemens

  • SQL LIKE statement to text field fomr CF MX 6.1

    Hi.
    Here's my scenario. I am running SQL Server 2000 SP4 on a
    Windows 2003 Server running IIS 6. Using ColdFusion MX 6.1 Updater
    version.
    I am storing HTML page code (some complete, some just clips)
    in a text type field.
    I need to check to see if someone has already saved that
    exact code already before. So I do the following query:
    <cfquery name="checkforexisting"
    datasource="mydatasource">
    SELECT smallfieldtogetareturn
    FROM MyTable
    WHERE MyTextField LIKE '%#mystringoflongdata#%'
    </cfquery>
    Then to see if it posted:
    <cfif checkforexisting.RecordCount GT 0>
    do the don't clip optional processing
    </cfif>
    What is killing me is that it finds the match SOMETIMES. Just
    not ALL the time. I have tried no percent signs when passing the
    ColdFusion variable, only one on the right (which has solved these
    types of problems before).
    If I pull the record back OUT of the database in a page by
    itself (retrieving it by key field), it finds every other copy of
    the code EVERY time.
    I have put this into a stored procedure, which seemed to help
    I even have resorted to creating a temp table first with the
    clip, then running a query to retrieve the record that was just put
    in, and comparing THAT to my primary table (both have text type
    fields). The reason for this, is that if I write a single page that
    has just the retrieval of the temp record, and that compare is run,
    it finds EVERY copy of it in the primary table. I also thought that
    maybe there was a strong problem (I had tried HTMLEditFormat,
    HTMLCodeFormat, JavaCast since it was coming from a java program on
    the browser end).
    I am not terribly familiar with using large text fields, or
    dealing with these large pieces of HTML code as something to
    compare!
    - Mike

    MichaelSJudd wrote:
    As Dan indicated your most likely issue is slight differences
    in
    capitalization and|or white space or other 'invisible'
    difference
    between your strings. One can have nearly infinite variety in
    HTML code
    that will display identically in a browser, the standard is
    very
    forgiving of formatting differences.
    Something I have done in the past to compare HTML content is
    to use the
    hash() function. It will not help you eliminate the
    differences but it
    would show when something is different then it appears to be.
    #hash(mystringoflongdata)# will return a hexadecimal number
    representing
    the string. Two *exactly* the same strings will produce the
    same
    number. Then it is very easy to compare these numbers to see
    if two
    long strings are the same.
    To use this with your database data, you would probably have
    to store
    the hash value of the string in a field when you store the
    HTML data.
    HTH
    Ian

  • SQL select statement help

    Say i have a table that has the following fields...
    ID    field1    field2   field3  field4   field5   field6   field7
     1        1           2         E         NW     SW  
         n         n
     2        1           2         E         NE      SW  
         n          n 
     3        1           3         W        NE      SE  
          n          n 
    10,000 plus entries in this table:  it is state quarter quarter data if it helps... 
    So i was handed a list on paper that has about 500 of these quarters from the above said table but there is no ID. I am having a someone build an excel spread
    sheet in the fashion above but the only fields will be as follows
    ID(NOT THE SAME AS ABOVE)  field1   field2  field3 field4  field5
    1                                                  
    1           1         W      NW    NE
     500 or so entries in this table
    no field 6 or 7
    how would i go about selecting all the fields from the top table that match exactly fields 1-5 in the excel sheet?
    and no there are no duplicate entries in the top table.
    thanks,
    james
    dogdaynoon

    Is field6 and field7 nullable fields in yourtable?
    If yes you can simply ignore them in your insert statements
    If you're directly dumping the contents of excel to table then it would be like
    INSERT YourTable (field1,field2,field3,field4,field5)
    SELECT field1,field2,field3,field4,field5
    FROM OPENROWSET(....) AS f
    if you're populating a tsgaing table you can do like this
    INSERT YourTable (field1,field2,field3,field4,field5)
    SELECT field1,field2,field3,field4,field5
    FROM StagingTable s
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • SQL insert statement help please

    alternative is to have the table with field dateadd with default value of getdate()   - then do not include in your insert statement - then the modify date use and update - starting point - my two cetns

    Hi all I'm trying to go a little out of my comfort level here and was hoping for some advice. I have a sql table that has 2 date fields. an add and a modified. If the modified date is null then I want to calculate on the date added. Otherwise I'd like to calculate on the modified date.
    Here is a simplified version of what I'm trying to accomplish.
    Hope it makes sense what I'm trying to do.
    SQLSELECT field1,field2.... ,dateAdded , dateModifiedINTO tblOutputFROM tblInput/* some pseudo code here */WHERE (if dateModified not null then ( dateModified

  • SQL Case statement Help....

    Hi , I have to Compare two columns to see if they are matching or not....and give the count() of overrides if they are not matching/
    I have got that with the below SQL:
    Count of Overrides =
    select count(Case when Col_1 != Col_2 then 1 else null end) Overrides
    from table_1, table_2
    where table_1.id = table_2.id
    But now i have to look at two columns and get the count()
    I have
    col_1 and col_2 in table_1 and
    col_3 and col_4 in table_2
    (I have to compare col_1 with col_2 and...... col_3 with col_4 and if either of them is not matching.... count it as an override
    Will the following SQL return correct values?
    Count of Overrides =
    Select
    Count( Case when (col_1 ! = col_2) or (col_3 != col_4) then 1 else null end) Overrides
    from table_1, table_2
    where table_1.id = table_2.id
    Thanks

    "yes, it can be rewritten as a decode. but why bother?"
    Well, although I do like Sy's code better, the decode version does naturally handle NULLs unlike the case.
    SQL> WITH t AS (
      2     SELECT 1 col_1, 1 col_2, 2 col_3, 2 col_4 FROM dual UNION ALL
      3     SELECT 1, 1, 2, 3 FROM dual UNION ALL
      4     SELECT 1, 2, 3, 3 FROM dual UNION ALL
      5     SELECT null, 1, 2, 2 FROM dual UNION ALL
      6     SELECT 1, 1, 2, null FROM dual UNION ALL
      7     SELECT 1, 2, 3, 4 FROM dual)
      8  SELECT col_1, col_2, col_3, col_4,
      9         CASE WHEN (col_1 ! = col_2) or (col_3 != col_4) then 1 else null end Ocase,
    10         DECODE(col_1, col_2, DECODE(col_3, col_4, NULL, 1), 1) odecode
    11  FROM t;
         COL_1      COL_2      COL_3      COL_4      OCASE O
             1          1          2          2
             1          1          2          3          1 1
             1          2          3          3          1 1
                        1          2          2            1
             1          1          2                       1
             1          2          3          4          1 1John

  • Regex help for SQL update statement

    Hello,
    need help from IPS regex guru - trying to build the signature to detect SQL update statement in HTTP requests.
    1) Am I correct with regex below specified as Request-Regex?
    [Uu][Pp][Dd][Aa][Tt][Ee]([%]20|[+])[\x20-\x7e]+[Ss][Ee][Tt]([%]20|[+])[\x20-\x7e]+=
    2) How do I make sure that it detects 'Update' in URI and Arguments only and not in the body on entire webserver response (currently looks like the case)?

    1) It looks correct to me
    2) Typically, the "service HTTP" engine is used to inspect requests and the "TCP string" engine is used to inspect HTTP server responses. If you only want to inspect requests, use the service HTTP engine.

  • Help with TYPE and LIKE statements

    HI guys,
    I know this is really novice stuff, but I am a little confused.
    Can anyone please explain the exact difference between TYPE and like with the help of a program, to understand it.
    What situation would demand the use of each of the LIKE statement, since I can do all these things using the TYPE ?

    Hi Akhil,
    I summarized the info in SDN posts and SAP Help, to make it easier for you to understand. I also included some code snippets. Hope these prove to be helpful to you.
    The following is from SAP Help:
    The Additions TYPE and LIKE
    The additions TYPE type and LIKE dobj are used in various ABAP statements. The additions can have various meanings, depending on the syntax and context.
    ·        Definition of local types in a program
    ·        Declaration of data objects
    ·        Dynamic creation of data objects
    ·        Specification of the type of formal parameters in subroutines
    ·        Specification of the type of formal parameters in methods
    ·        Specification of the type of field symbols
    A known data type can be any of the following:
    ·        A predefined ABAP type to which you refer using the TYPE addition
    ·        An existing local data type in the program to which you refer using the TYPE addition
    ·        The data type of a local data object in the program to which you refer using the LIKE addition
    ·        A data type in the ABAP Dictionary to which you refer using the TYPE addition. To ensure compatibility with earlier releases, it is still possible to use the LIKE addition to refer to database tables and flat structures in the ABAP Dictionary. However, you should use the TYPE addition in new programs.
    The LIKE addition takes its technical attributes from a visible data object. As a rule, you can use LIKE to refer to any object that has been declared using DATA or a similar statement, and is visible in the current context.  The data object only has to have been declared. It is irrelevant whether the data object already exists in memory when you make the LIKE reference.
    ·        In principle, the local data objects in the same program are visible. As with local data types, there is a difference between local data objects in procedures and global data objects. Data objects defined in a procedure obscure other objects with the same name that are declared in the global declarations of the program.
    ·        You can also refer to the data objects of other visible ABAP programs. These might be, for example, the visible attributes of global classes in class pools. If a global class cl_lobal has a public instance attribute or static attribute attr, you can refer to it as follows in any ABAP program:
    DATA dref TYPE REF TO cl_global.
    DATA:  f1 LIKE cl_global=>attr,
           f2 LIKE dref->attr.
    You can access the technical properties of an instance attribute using the class name and a reference variable without first having to create an object. The properties of the attributes of a class are not instance-specific and belong to the static properties of the class.
    Example
    TYPES: BEGIN OF struct,
             number_1 TYPE i,
             number_2 TYPE p DECIMALS 2,
           END OF struct.
    DATA:  wa_struct TYPE struct,
           number    LIKE wa_struct-number_2,
           date      LIKE sy-datum,
           time      TYPE t,
           text      TYPE string,
           company   TYPE s_carr_id.
    This example declares variables with reference to the internal type STRUCT in the program, a component of an existing data object wa_struct, the predefined data object SY-DATUM, the predefined ABAP type t and STRING, and the data element S_CARR_ID from the ABAP Dictionary.
    The following info is from various posts:
    --> Type: It is used when userdefined object link with SAP system data type.
    Local types mask global types that have the same names. When typing the interface parameters or field symbols, a reference is also possible to generic types ANY, ANY TABLE,INDEX TABLE, TABLE or STANDARD TABLE, SORTED TABLE and HASHED TABLE.
    --> Like: It is when data object link with the other data object.
    --> TYPE, you assign datatype directly to the data object while declaring.
    --> LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.
    you can refer to all visible data objects at the ABAP program's positon in question. Only the declaration of the data object must be known. In this case it is totally irrelevant whether the data object already exists physically in
    memory during the LIKE reference. Local data objects mask global data objects that have the same name.
    --> Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object.
    Types: var1(20) type c.
    data: var2 type var1. ( type is used bcoz var1 is defined with TYPES and it
    does not occupy any memory spce.
    data: var3 like var2. ( like is used here bcoz var2 is defined with DATA
    so it does occupy space in memory ).
    data: material like mara-matnr. ( like is used here bcoz mara-matnr is stored in memory)
    --> Type refers the existing data type
    --> Like refers the existing data object
    Please Reward Points if any of the above points are helpful to you.
    Regards,
    Kalyan Chakravarthy

  • Download Oracle SQL*Plus help related like word help

    Hello all
    I just wanna ask if where i can download Oracle SQL*Plus help related like word help.?
    ty

    <p>You can access SQL*Plus help from the command line in a SQL*Plus session by typing 'help index'. If you want more information than that, take a look at the SQL*Plus Quick Reference located <b>here</b> or the SQL*Plus User's Guide and Reference located <b>here</b>. These docs are all for Oracle 10g. Other version documentation can be found <b>here</b>.</p>
    Tom

  • T-sql case statement in a select

    When I execute the following t-sql 2012 statement, the "NO Prod' value is not
    being displayed from the sql listed below:
    SELECT DISTINCT
    IsNull(cs.TYPE,'') as type,
    CASE IsNull(Course.TYPE,'')
    WHEN 'AP' then 'AP Prod'
    WHEN 'IB' then 'IB Prod'
    WHEN 'HR' then 'HR Prod'
    WHEN '' then 'NO Prod'
    END AS label
    FROM CustSection cs
    INNER JOIN dbo.Person p on P.personID = cs.personID
    Left join customCustomer cs564 on cs564.personID = p.personID and
    cs564.attributeID ='564'
       where ( cs.type is null and cs564.attributeID = null)    
         or
        (cs.type IN ('HR','AP') OR
          (cs.type='IB' AND SUBSTRING(cs.code,1,1)='3'))  
    ORDER BY label
    What I want is for 'NO Prod' to be displayed when
    cs.type is null and cs564.attributeId  is null.
    Thus can you tell me how to fix query above so the 'NO Prod'  value is displayed in the
    select statement listed above?

    There is no CASE statement in SQL; we have a CASE expression. We do not use the old 1970's Sybase*- ISNULL(); we have  COALESCE().
    There is no such thing as a magic generic “type” in RDBMS. There is no such thing as a generic “code” in RDBMS. They have to to be “<something in particular>_type” and “<something in particular>_code” in a valid data model. How about blood_type
    and postal_code?? 
    There is no such thing as a generic “person” table in RDBMS. First of all, do you really have only one person, as you said?? But the important point is that these persons play a role in the data model – customers, students, etc. You are doing the wrong thing
    and doing it badly.  This table should not exist any more than a  table of “Things” such exist. 
    And the reason you are beyond any real help is “attribute_id” which tell us that your schema is a total disaster of data and meta data mixed together in a non-RDBMS written in awful SQL. Based on cleaning up bad SQL for 30 years, it looks like you are an OO
    programmer who never unlearned his prior mindset. 
    Why did you allow an encoding schema with blanks? Why do you have so many NULL-able columns? 
    SELECT DISTINCT is very rare in a properly designed schema. The DRI references assure that rows cam be matched. To get you started, look at this skeleton:
    CREATE TABLE Products
    (product_gtin CHAR(15) NOT NULL PRIMARY KEY, 
     product_type CHAR(2) DEFAULT 'XX' NOT NULL
      CHECK (product_type IN ('AP', 'IB', 'HR', 'XX'))
    The table name is a plural noun because it models a set (NOT an OO class).
    The GTIN is an industry standard identifiers, and not have to invent our own.
    The product_type (not blood_type, not automobile_body_type!) has a constraint that assures it is never NULL and never blank; I invented 'XX' as a default. 
    You need more help than you can get in a forum, but if you will follow Netiquette and post the DDL, we can get you started.
    --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

  • Java.sql.SQLException: Statement cancelled, probably by transaction timing

    Hi all,
    I have a problem with transaction handling over 2 applications. I have 2 EAR files (*A.ear* and B.ear) which are deployed on a WLS 12.1. The WLS contains a XA datasource which is connected to a Oracle XE database. Both applications are using the same datasource. The datasource is configured to use the driver oracle.jdbc.xa.client.OracleXADataSource.
    EAR A contains a Remote EJB which is is calling a local EJB. The local EJB calls a Remote EJB from EAR B.
    Here is an example how the code looks like:
    @Remote
    @Stateless(mappedName = "AnyRemote", name = "AnyRemote")
    public class AnyRemoteBean implements AnyRemote {
        @EJB
        private AnyLocal anyLocal;
        @Override
        public void doIt() {
            anyLocal.doSomething();
    @Local
    @Stateless(mappedName = "AnyLocal", name = "AnyLocal")
    public class AnyLocalBean implements AnyLocal {
        @PersistenceContext(unitName = "A")
        private EntityManager entityManager;
        @EJB(mappedName = "AnyCompositeService")
        private AnyCompositeService anyCompositeService;
        @Override
        @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
        public boolean doSomething() {
                try {
                     // do some stuff and save to database within another local EJB
                    anyCompositeService.doSomethingOnEAR_B();
                    return true;
                } catch (final AnyException e) {
                    LOGGER.error("doSomething failed", e);
                    return false;
        @Override
        @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
        public boolean stayOnEar_A() {
                // do some stuff and save to database within another local EJB
                return true;
    }AnyCompositeService located in EAR B looks like this:
    @Remote
    @Stateless(mappedName = "AnyCompositeService ", name = "AnyCompositeService ")
    public class AnyCompositeServiceBean implements AnyCompositeService {
        @Override
        public boolean doSomethingOnEAR_B() throws AnyException {
            // do some calls to some local EJBs and some other remote EJBs and save something to database
            return true;
    }In this process of EAR B I'm using the entitiy manager:
        @PersistenceContext(unitName = "B")
        private EntityManager entityManager;persistence.xml for EAR A looks like this
        <persistence-unit name="A" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>MyDatasource</jta-data-source>
           <!-- some entities -->
            <properties>
                <property name="hibernate.transaction.jta.platform"
                    value="org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform" />
                <property name="hibernate.max_fetch_depth" value="3" />
                <property name="hibernate.connection.characterEncoding" value="UTF-8" />
                <property name="hibernate.connection.charSet" value="UTF-8" />
                <property name="hibernate.connection.useUnicode" value="true" />
                <property name="hibernate.default_batch_fetch_size" value="20" />
            </properties>
        </persistence-unit>
    </persistence>persistence.xml for EAR B looks like this
        <persistence-unit name="B" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>MyDatasource</jta-data-source>
           <!-- some entities -->
            <properties>
                <property name="hibernate.transaction.jta.platform"
                    value="org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform" />
                <property name="hibernate.max_fetch_depth" value="3" />
                <property name="hibernate.connection.characterEncoding" value="UTF-8" />
                <property name="hibernate.connection.charSet" value="UTF-8" />
                <property name="hibernate.connection.useUnicode" value="true" />
                <property name="hibernate.default_batch_fetch_size" value="20" />
            </properties>
        </persistence-unit>
    </persistence>As you can see the method doSomething() defines the transaction attribute TransactionAttributeType.REQUIRES_NEW.
    When I execute AnyRemote.doIt() I get the following exception:
    Caused By: java.sql.SQLException: Statement cancelled, probably by transaction timing out
         at weblogic.jdbc.wrapper.Statement.postInvocationHandler(Statement.java:69)
         at weblogic.jdbc.wrapper.PreparedStatement_oracle_jdbc_driver_OraclePreparedStatementWrapper.clearBatch(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
         at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
         at $Proxy452.clearBatch(Unknown Source)
         at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.releaseStatements(AbstractBatchImpl.java:163)
         at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.release(AbstractBatchImpl.java:197)
         at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:139)
         at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.close(TransactionCoordinatorImpl.java:276)
         at org.hibernate.internal.SessionImpl.close(SessionImpl.java:349)
         at org.hibernate.ejb.EntityManagerImpl.close(EntityManagerImpl.java:137)
         at weblogic.persistence.TransactionalEntityManagerProxyImpl.close(TransactionalEntityManagerProxyImpl.java:117)
         at weblogic.persistence.BasePersistenceContextProxyImpl$PersistenceContextCloser.afterCompletion(BasePersistenceContextProxyImpl.java:213)
         at weblogic.transaction.internal.ServerSCInfo.doAfterCompletion(ServerSCInfo.java:1068)
         at weblogic.transaction.internal.ServerSCInfo.callAfterCompletions(ServerSCInfo.java:1012)
         at weblogic.transaction.internal.ServerTransactionImpl.callAfterCompletions(ServerTransactionImpl.java:3074)
         at weblogic.transaction.internal.ServerTransactionImpl.afterRolledBackStateHousekeeping(ServerTransactionImpl.java:2954)
         at weblogic.transaction.internal.ServerTransactionImpl.setRolledBack(ServerTransactionImpl.java:2930)
         at weblogic.transaction.internal.ServerTransactionImpl.globalRetryRollback(ServerTransactionImpl.java:3172)
         at weblogic.transaction.internal.ServerTransactionImpl.globalRollback(ServerTransactionImpl.java:2920)
         at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:374)
         at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:268)
         at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:332)
         at weblogic.ejb.container.internal.BaseLocalObject.__WL_postInvokeTxRetry(BaseLocalObject.java:202)
         at weblogic.ejb.container.internal.SessionLocalMethodInvoker.invoke(SessionLocalMethodInvoker.java:44)As long as the process only calls EJBs from EAR A only there is no issue. But if the process calls the method doSomethingOnEAR_B() on EAR B the call fails with above exception. If the process throws AnyException the rollback takes place as expected for transaction in EAR B and EAR A.
    Does anybody know what is the issue here? Is there any configuration I have overseen?

    That is a WLS internal message. The statement did get cancelled,
    probably as a part of the process of rolling back the transaction it
    was involved in. If you don't find your core problem, open an
    Oracle support SR, and we could help debug this further.

  • Convert sql select statement to oracle

    Hi All,
    Can anyone help me converting this Sql select statement to oracle ....
    -----------------------------------------Query--------------------------------------------------------------
    select emp_master.emp_code ,
    emp_master.dept_cd ,
    attendance_master.daily_attn_code ,
    attendance_master.linked_column ,
    case when location.payroll_status <> 'N' and eDocsNetEmployeesLeave.StartDate < dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))     
    then
    dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
    when eDocsNetEmployeesLeave.StartDate < convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01')     
    then convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01') else eDocsNetEmployeesLeaveDetails.StartDate           
    end ,
    eDocsNetEmployeesLeaveDetails.NoOfDays,          
    case when eDocsNetEmployeesLeave.StartDate > location.next_pay_date     
    then convert(datetime , convert(varchar, dateadd(ss,-1, dateadd(mm, 1, convert(datetime , datename(yy,eDocsNetEmployeesLeave.StartDate)+ '/' + datename(mm,eDocsNetEmployeesLeave.StartDate)+ '/01') )),106) )     
    else      
    case when location.payroll_status <> 'N'
    then dateadd(mm,1,location.next_pay_date)      
    else location.next_pay_date
    end      
    end as PaymentDate               ,
    isnull(grade_master.leave_type,'C') ,
    eDocsNetEmployeesLeave.StartDate ,          
    eDocsNetEmployeesLeaveDetails.LeaveType
    from eDocsNetEmployeesLeave ,
    eDocsNetEmployeesLeaveDetails ,
    eDocsNetLeaveTypes ,
    emp_master ,
    grade_master ,
    attendance_master ,
    location
    where eDocsNetEmployeesLeaveDetails.RequestID     = eDocsNetEmployeesLeave.RequestID and
    eDocsNetEmployeesLeave.EmployeeID = emp_master.emp_code and
    eDocsNetEmployeesLeaveDetails.LeaveType = eDocsNetLeaveTypes.LeaveTypeID and
    eDocsNetLeaveTypes.loc_cd = emp_master.loc_cd and
    location.loc_cd = emp_master.loc_cd and
    attendance_master.loc_cd = emp_master.loc_cd and
    attendance_master.linked_column = eDocsNetLeaveTypes.LinkedAttendance and
    grade_master.loc_cd = emp_master.loc_cd and
    grade_master.grade_cd = emp_master.grade_cd and
    eDocsNetEmployeesLeaveDetails.RequestID      = @RequestID
    order by eDocsNetEmployeesLeaveDetails.StartDate
    Thanks in Advance
    Smiley

    Seems like you want to convert a SQL statement from the ??? dialect to the Oracle dialect. *(It would be useful to indicate the non-ANSI standard SQL you are starting with.)
    Part of the problem is that you use several date related functions. Some are unnecessary in Oracle and some need to translated into Oracle functions as found in the Functions section (chapter 5) of the SQL Reference manual at http://www.oracle.com/pls/db102/homepage
    Note that columns and expressions of type 'date' in ORacle always contain all of "yyyy mm dd hh mi ss" and you need to format and trauncate as necessary.
    Also note that '09-JAN-31' is NOT an Oracle date, but rather a character representation of a date which must be converted to/from a date expression. You will often need to use the to_date() and to_char() functions with a format mask as the second parameter. This is also descreibed in the first 2 chapters of the SQL Reference manual.

Maybe you are looking for

  • Ipod touch second gen not charging or connecting to ITunes / Computer?

    I have an Ipod Touch second generation about two or three years old that has not been charged for a few eeks - tried to charge and reconnect to Computer / Itunes and it will not charge or be recognised on the Computer / ITunes - can anyone help?

  • ITunes wont recognize music files

    Windows 7 Dell Inspiron PC Much to my regret, I moved music files and now itunes cant find them. They are simply transparent to itunes; not listed in the songs list.  I tried to change the iTunes advanced settings for file location to no avail. I man

  • Oracle Terminal settings form Magic menu items

    Dear Oracle Developer Community! Is there any possibility to define any 'Hot Keys' for Magic menu items via Oracle Terminal such as 'Cut', 'Paste' or 'Copy'? Sincerely yours, Elias null

  • Safari Right Click Menu Options

    Ever since I updated to Safari 5.0.3 at home, I no longer have all of the numerous drop-down options for saving images when I right click with my Wacom Stylus or my mouse. I only get 3 options. I also have Safari 5.0.3 on my Mac at work, but I still

  • TOC doesn't synchronize in merged HTMLHelp project

    This issue had been discussed several times. Peter Grainge offered a solution for WebHelp projects. Though I'm still looking for a solution on HTML Help projects with CHM output format. Situation: As the help file growed tremendously over time we'd l