Beginner: Get on the WHERE clause syntax error in SELECT

I am very new to php and mySQL.  Use DW master/detail to generate Basic code I need.  One thing I have to do is to modify a select statement in the master to include a WHERE clause to limit the selection to a particular value in a field.

I get a syntax error with the select statement in the WHERE clause, I add to the map.

It's the part of the error message showing the location of the error:

"WHERE group = 'Community' LIMIT 0, 10'"

Php that generated the select is:

$query_maps = "SELECT * FROM tblmaps ORDER BY tblmaps.» DispSeq ';

$query_limit_maps = sprintf ("%s WHERE group =' LIMIT %s %d, %d", $query_maps, $selectGroup, $startRow_maps, $maxRows_maps);

This approach to create the select statement is on the generated code for the master page.  He added the LIMIT clause.  I didn't add the ' WHERE group = '%s' and the variable $selectGroup, which comes from the old code.»  You can see that the $selectGroup variable is equal to the "community: group.»

I scanned the web to see what syntax error, I could do, but haven't found anything that explains it.

The resolved full select statement is:

SELECT * FROM tblmaps ORDER BY tblmaps. WHERE DispSeq = 'Community' LIMIT 0,10 group

What I don't see?

Tom

The group is a reserved word in MySQL. You could probably put single quotes around it, but I suggest to rename this column. Do not use reserved words for column names.

Tags: Dreamweaver

Similar Questions

  • Lexical parameters in the WHERE clause in error

    Hello

    Based on the settings, I need to change the place where the clause of the sql query in the data in the report model. After report params, I added the code as

    : p_where1: = 'conditions...' » ;

    and in the select clause

    Select table.name
    where & p_where1

    I added the p_where1 as the parameter to use.

    But when I say OK to the query in the data model. I am getting error like

    ORA-00936: lack of expression
    WHERE == >

    Can someone help me why I get this error...

    Thank you
    HC

    Hello

    Set the initial value of the parameter as 1 = 1 try.

    -Clément

  • Try adding conditions to clause "and" stored in the table for the where clause, unknown syntax

    I am trying to add additional segments to the 'where' clause, and I don't know exactly how to proceed. I am currently using another table to search for keywords and sometimes there aren't everything. I use this table containing the key words to search the description and associate a symbol with a path.

    The code loops through the keywords with the keywords most associated and try to find links to a symbol then excludes those and search for symbols that correspond to those with less keywords and all. I am able to do this with 6 queries and manually changing the arguments, but I want to loop together so that if the changes need to be made in the future, I won't need to go digging in the code.

    Thanks, but that's ok. I already have a solution for this.

  • T/t with the WHERE clause using a list breaks

    Hello, all,.

    I have a project where I need to use a list as part of the WHERE clause for a t/t, and it is breaking.  I don't know what I'm doing wrong.

    For some pseudo-code, do I have a complete query of a database called 'people '.  A list of values for the t/t with the first query; the second query is my t/t:

    <cfquery name="getDIR" datasource="#request.THISDSN#">
        SELECT thisName dir FROM orgs WHERE thisID in (<cfqueryparam value="#form.org#" cfsqltype="cf_sql_varchar" list="yes" />)
    </cfquery>
    
    <cfquery name="people" database="people">
        SELECT colA, colB, colC, colD
        FROM people
        WHERE 1=1
            AND (
                div IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />)
                OR dir IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />)
                )
    </cfquery>
    
    
    

    I get the error message is "t/t syntax error: encountered" div IN \'thisValue\' ".»  Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition. »

    Can support _not_ QoQ lists of WHERE clauses?

    V/r,

    ^_^

    SMH - so much... I just found.

    I forgot to give the lists in the second query bracket.


    (The pseudocode was manually typed, since my dev system is isolated from the internet, and I added the in my pseudo code when they were not in my original code.)

    * headdesk * headdesk * headdesk * headdesk *.

    V/r,

    ^_^

  • Execution of statement of UPDATE for the whole table even when the WHERE Clause is presentation

    Hi friends,

    I have a problem in a stored procedure where I wrote an update with a where clause clause statement. At some point only one line should be updated according to the unique identifier in where clause.

    But what is happening is that the Update statement is getting executed for all rows in the table to neglect the WHERE clause. I don't get any idea of why this is happening. Here is the stored procedure and the update statement is BOLD:-

    CREATE OR REPLACE PROCEDURE MDMADM.proc_MDM_InsertCntryDetails
    (
    CntryMasterCode IN VARCHAR2,
    CntryName IN VARCHAR2,
    MDMUser IN VARCHAR2,
    Exists IN ITS ENTIRETY,
    status in VARCHAR2,
    Inserted_By IN VARCHAR2 default NULL,
    Modified_By IN VARCHAR2 default NULL,
    Mdm_Code IN the DEFAULT NUMBER 0.
    Action in VARCHAR2 DEFAULT 'Add ',.
    XGenAttNames IN VARCHAR2 default NULL,
    XGenAttValues IN VARCHAR2 default NULL,
    MirusAttNames IN VARCHAR2 default NULL,
    MirusAttValues IN VARCHAR2 default NULL,
    GenisysAttNames IN VARCHAR2 default NULL,
    GenisysAttValues IN VARCHAR2 default NULL,
    XGenModify IN VARCHAR2 default NULL,
    MirusModify IN VARCHAR2 default NULL,
    GenisysModify IN VARCHAR2 default NULL
    )

    IS

    strSQLXGen VARCHAR (1000);
    strSQLMirus VARCHAR (1000);
    strSQLGenisys VARCHAR (1000);
    nMaxMDMCode INTEGER.
    ifExist INTEGER;

    /******************************************************************************
    NAME: proc_MDM_InsertCntryDetails
    PURPOSE:

    REVISIONS:
    Worm Date Description of the author
    --------- ---------- --------------- ------------------------------------
    1.0 03/07/2009 1. Created this procedure.

    NOTES:

    Keywords to replace automatically available Auto:
    Object name: proc_MDM_InsertCntryDetails
    SYSDATE: 03/07/2009
    Date and time: 03/07/2009, 19:11:20 and 03/07/2009-19:11:20
    User name: (put in TOAD Options, editor of the procedure)
    Name of the table: (defined in the dialog box "New PL/SQL object")

    ******************************************************************************/
    BEGIN

    COUNT (*) of SELECT INTO ifExist OF MDM_COUNTRY_MASTER;

    IfExist IF = 0 THEN
    SELECT 1 INTO nMaxMDMCode FROM DUAL;
    ON THE OTHER
    SELECT MAX (MDM_CODE) + 1 IN MDM_COUNTRY_MASTER nMaxMDMCode;
    END IF;


    IF Action = "add" THEN

    INSERT INTO MDM_COUNTRY_MASTER(MDM_CODE,MDM_MASTER_CODE,MDM_DESCRIPTION,MDM_USER,MDM_EXIST,MDM_STATUS,MDM_ACTION,DAT_INSERT_DATE,DAT_INSERTED_BY)
    VALUES(nMaxMDMCode,CntryMasterCode,CntryName,MDMUser,exist,Status,action,sysdate,Inserted_By);

    strSQLXGen: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) XGenAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    "VALUES (' |)" nMaxMDMCode | ',' || '''' || "XGen | '''' || ',1,' || XGenAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLXGen;

    strSQLMirus: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) MirusAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    "VALUES (' |)" nMaxMDMCode | ',' || '''' || "Mirus | '''' || ',2,' || MirusAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLMirus;

    strSQLGenisys: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) GenisysAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    "VALUES (' |)" nMaxMDMCode | ',' || '''' || "Genisys | '''' || ',3,' || GenisysAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLGenisys;

    ON THE OTHER



    UPDATE MDM_COUNTRY_MASTER
    SET MDM_DESCRIPTION = CntryName, DAT_MODIFIED_BY = Modified_By, DAT_MODIFY_DATE = SYSDATE.
    MDM_USER = MDMUser, MDM_ACTION = Action, MDM_STATUS = status MDM_EXIST = exist WHERE MDM_CODE = Mdm_Code;




    COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 1 AND MDM_CODE = Mdm_Code;

    IfExist IF = 0 THEN

    strSQLXGen: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) XGenAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    ' VALUES(' ||) Mdm_Code | ',' || '''' || "XGen | '''' || ',1,' || XGenAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLXGen;

    ON THE OTHER
    strSQLXGen: = "UPDATE MDM_COUNTRY_MAPPING SET | XGenModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 1';

    EXECUTE IMMEDIATE strSQLXGen;

    END IF;


    COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 2 AND MDM_CODE = Mdm_Code;

    IfExist IF = 0 THEN

    strSQLMirus: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) MirusAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    ' VALUES(' ||) Mdm_Code | ',' || '''' || "Mirus | '''' || ',2,' || MirusAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLMirus;

    ON THE OTHER
    strSQLMirus: = "UPDATE MDM_COUNTRY_MAPPING SET | MirusModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 2';

    EXECUTE IMMEDIATE strSQLMirus;

    END IF;


    COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 3 AND MDM_CODE = Mdm_Code;

    IfExist IF = 0 THEN

    strSQLGenisys: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) GenisysAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
    ' VALUES(' ||) Mdm_Code | ',' || '''' || "Genisys | '''' || ',3,' || GenisysAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';

    EXECUTE IMMEDIATE strSQLGenisys;

    ON THE OTHER
    strSQLGenisys: = "UPDATE MDM_COUNTRY_MAPPING SET | GenisysModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 3';

    EXECUTE IMMEDIATE strSQLGenisys;

    END IF;



    END IF;



    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHILE OTHERS THEN
    -Consider recording the error and then re-raise
    LIFT;
    END proc_MDM_InsertCntryDetails;
    /


    Thank you

    >
    WHERE mdm_code = mdm_code
    >

    This will always be value true - similar to WHERE 1 = 1.

    You typed it wrong or is the same as the variable column name? If they are the same test rename one of them.

  • Outer joins and null in the 'where' clause condition

    Hi people,

    Please help me on this.

    Here's my query.

    with x

    (select 'a' as a dual union all col1)

    Select 'b' as col1 of union double all the

    Select 'c' as double col1

    ),

    y as

    (

    Select 'b' as col2 from dual Union all the

    Select 'c' as col2 from dual Union all the

    Select would be "as col2 from dual Union all the"

    Select 'e' as col2 from dual

    )

    Select * x y right outer join

    on x.col1 = y.col2 and y.col2 is null

    Get all the lines of 'COL1' as null. Why like this?

    Just add the condition to the WHERE clause for example

    WITH x AS
    (SELECT 'a' AS col1 FROM dual UNION ALL
    SELECT 'b' AS col1 FROM dual UNION ALL
    SELECT 'c' AS col1 FROM dual
    ),
    y AS
    (
    SELECT 'b' AS col2 FROM dual UNION ALL
    SELECT 'c' AS col2 FROM dual UNION ALL
    SELECT 'd' AS col2 FROM dual UNION ALL
    SELECT 'e' AS col2 FROM dual
    )
    SELECT * FROM x LEFT OUTER JOIN y
    ON x.col1=y.col2                     ----want to add "and y.col2 is null " condition to get value "a"
    where y.col2 is null
    
  • In the WHERE clause string variable

    I have the procedure

    CREATE OR REPLACE PROCEDURE proc1 (p_1 IN varchar2)
    IS
    BEGIN

    DELETE FROM TABLE1
    WHERE
    Col1 = '@p_1. '
    ;

    Dbms_output.put_line (number of rows sql %);

    COMMIT;

    EXCEPTION
    WHILE OTHERS THEN
    ROLLBACK;
    RAISE_APPLICATION_ERROR (-20000, SQLERRM);
    Proc1 END;
    /


    You will need to pass a string input parameter to the procedure. This string is applied to the WHERE clause. The foregoing does not work correctly the value of @p1 is in the WHERE clause. The value passed to the stored procedure does not run.

    Please let me know the solution. I have to use BIND variables only.

    Thank you

    user12038051 wrote:
    Thank you all. Yes, the underside of the works.

    DELETE FROM TABLE1
    WHERE
    Col1 = p_1
    ;

    PS: Both COL1 and p_1 are string values. Would like to know how it works with out the quotes because it is a string.

    In addition I would like to follow the number of lines executed in each statement. Preference will have to use sql % rowcount. Are there other alternatives. Please let me know. Thanks in advance.

    Oracle 'knows' that the variable p_1 is a varchar2 data type and that col1 is a varchar2 data type, so he makes a comparison between them strinf. This is how variables work in any programming language that I am aware. The only time that you must provide a value is when you use a literal value (for example in an assignment variable, or as a parameter of a procedure).

    If you need to know the number of deleted rows, then sql % rowcount is the only sensible option. Just be aware that you need to get the value before committing yourself ot other options of SQL.

    John

  • DECODE inside the WHERE clause

    Hi all:

    I can't get the DECODE statement to work inside my WHERE clause. I have read the information on
    Tahiti.Oracle.com
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions049.htm#i1017437

    But still can not get it to work. Initially, I had he works as dynamic SQL and then run that string, but I am not allowed to use dynamic SQL statements and to do 'Real' PL/SQL.

    I have the following WHERE clause (more info after the WHERE clause)
    WHERE 
         a.ebiz_asn_no(+) = te.ebiz_cntrl_no
         AND w.ebiz_work_no(+) = te.ebiz_cntrl_no
         AND o.ebiz_ord_no(+) = ebiz_cntrl_no
         AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no
         AND ms.ebiz_sku_no(+) = te.ebiz_sku_no 
         AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1))
         AND tl.ebiz_lp_no(+) = te.ebiz_lp_no 
         AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1))
         AND eu.ebiz_user_no(+) = te.act_ebiz_user_no 
         AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1))
         AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~')) 
         AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~')) 
         AND te.comp_id = p_CompID 
         AND te.site_id = p_SiteID 
         AND INSTR('' || p_TaskType || '', te.task_type) > 0 
         AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1)) 
         AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL
                           (te.ebiz_cntrl_no,-1)))
         AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~'))
         AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1)) 
         || whereClauseStatus 
         || whereClauseFromDate 
         || whereClauseToDate;
    As you can see, initially I was adding values of "whereClauseStatus, whereClauseFromDate, whereClauseToDate" and it has been defined with the following PL/SQL code:
         IF(p_TaskStatus = 'C') THEN
              -------------------------------------------------------------------------------------------
              --     Set From Date Clause
              -------------------------------------------------------------------------------------------
              IF(p_FromShipDate IS NOT NULL) THEN
                   whereClauseFromDate := ' AND TRUNC(te.act_end_date) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
              -------------------------------------------------------------------------------------------
              --     Set To Date Clause
              -------------------------------------------------------------------------------------------
              IF (p_ToShipDate IS NOT NULL) THEN
                   whereClauseToDate := ' AND TRUNC(te.act_end_date) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
         ELSE
              -------------------------------------------------------------------------------------------
              --     Incomplete and All statuses are filtered on the currdate
              -------------------------------------------------------------------------------------------
              -------------------------------------------------------------------------------------------
              --     Set From Date Clause
              -------------------------------------------------------------------------------------------
              IF(p_FromShipDate IS NOT NULL) THEN
                   whereClauseFromDate := ' AND TRUNC(te.currdate) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
              -------------------------------------------------------------------------------------------
              --     Set To Date Clause
              -------------------------------------------------------------------------------------------
              IF (p_ToShipDate IS NOT NULL) THEN
                   whereClauseToDate := ' AND TRUNC(te.currdate) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
         END IF;
         
    
         IF (p_TaskStatus = 'I') THEN
              whereClauseStatus := ' AND act_end_date IS NULL ';
         ELSIF (p_TaskStatus = 'C') THEN
              whereClauseStatus := ' AND act_end_date IS NOT NULL ';
         ELSE
              whereClauseStatus := '';
         END IF;
    I have serious problems getting the DECODE statement to replace the three variables in the annex.

    Any help would be greatly appreciated.

    Thank you
    Andy

    Published by: BluShadow on August 2, 2011 15:11
    addition of {noformat}
    {noformat} tags for clarity. Please read {message:id=9360002} and learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    I'll take a wild shot in the dark, and suggests that it is perhaps what you are looking for...

    WHERE
         a.ebiz_asn_no(+) = te.ebiz_cntrl_no
         AND w.ebiz_work_no(+) = te.ebiz_cntrl_no
         AND o.ebiz_ord_no(+) = ebiz_cntrl_no
         AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no
         AND ms.ebiz_sku_no(+) = te.ebiz_sku_no
         AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1))
         AND tl.ebiz_lp_no(+) = te.ebiz_lp_no
         AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1))
         AND eu.ebiz_user_no(+) = te.act_ebiz_user_no
         AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1))
         AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~'))
         AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~'))
         AND te.comp_id = p_CompID
         AND te.site_id = p_SiteID
         AND INSTR('' || p_TaskType || '', te.task_type) > 0
         AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1))
         AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL
                           (te.ebiz_cntrl_no,-1)))
         AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~'))
         AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1))
         AND TRUNC(te.act_end_date) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.act_end_date))
            AND TRUNC(te.act_end_date) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(tw.act_end_date))
            AND TRUNC(te.currdate) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.currdate))
         AND TRUNC(te.currdate) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(te.currdate))
            AND (  (act_end_date IS NULL AND p_TaskStatus = 'I')
                OR (act_end_date IS NOT NULL AND p_TaskStatus = 'C')
                OR p_TaskStatus NOT IN ('I','C')
                )
    

    Published by: BluShadow on August 2, 2011 16:27
    spleen the last clause. Oops.

  • Tuning - using the CASE statement in the WHERE clause of the query

    Hi all

    My request has been changed to use a CASE statement in the WHERE clause to examine the data to some columns based on a parameter value. This modified request is made a full table and constantly running scan. Please suggest what can be done to improve its performance:

    Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND get_date_timestamp(os.requestdatetime)  BETWEEN 
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' AND os.entry_createddate  BETWEEN 
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    END = 1
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND os.entry_CreatedDate BETWEEN 
    TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' THEN 1
    END = 1
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;
    Description of the table:
    (Number of lines: approx. > amount 600 000 000)
    Name                           Null     Type       
    ------------------------------ -------- ------------
    ARTICLEID                      NOT NULL NUMBER(20) 
    USERKEY                                 NUMBER(10) 
    AVIEWORIGIN_REFID                       VARCHAR2(10)
    SUCCESS_IND                             VARCHAR2(2)
    ENTRY_CREATEDDATE                       DATE       
    CREATED_BY                              VARCHAR2(10)
    FILENUMBER                              NUMBER(10) 
    LINENUMBER                              NUMBER(10) 
    ACCTNUM                                 VARCHAR2(10)
    AUTOCOMPLETEDTERM                       NUMBER(2)  
    REQUESTDATETIME                         VARCHAR2(19)
    Explain Plan
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 2224314832
    
    ----------------------------------------------------------------------------------------------------------
    | Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    ----------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT     |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   1 |  HASH GROUP BY       |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   2 |   PARTITION RANGE ALL|                   |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    |*  3 |    TABLE ACCESS FULL | TABLE1 |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    ----------------------------------------------------------------------------------------------------------
    
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE  WHEN ('FULL'='FULL' AND
                  "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
                  'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE  WHEN ('FULL'='FULL'
                  AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
                  2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                  2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
                  "OS"."AVIEWORIGIN_REFID" IS NOT NULL)
    Published by: Chaitanya on June 9, 2011 02:44

    Published by: Chaitanya on June 9, 2011 02:47

    When it is executed individually, MERGE LOGIC 1 and LOGIC of MERGE 2 take about ten for a daterange of 30 days data.

    BUT FULL is to get the scores of APR - JUN, INCR becomes partitions for MAY so not both 30 days.
    Are compare us like with like?

  • DECODE does not work in the WHERE clause when subquery returns more than one line

    Hi gurus,

    I want to write a query against the table CCENTERS (Script given below) and wait for the following result:

    1. in the transition from a value of 0 for the ID, it returns all the rows in the table.
    2. in the passage of one value other than 0, it returns the row corresponding to the given value and all its records of the child.

    CCENTER has parent-child relationship in the column ID and the BASE. I use a query with the DECODE function. but the function in the WHERE clause is not capable of managing the subquery with multiple lines of DECODE.

    *************************************************
    VARIABLE ParaCCenter NUMBER

    BEGIN
    : paraccenter: = 0;
    END;
    /

    CREATE TABLE ccenters
    (id NUMBER,
    name VARCHAR2 (20).
    number base);

    INSERT INTO ccenters VALUES(1,'NUST',null);
    INSERT INTO ccenters VALUES(2,'SEECS',1);
    INSERT INTO ccenters VALUES(3,'NBS',1);
    commit;

    SELECT * from ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,)
    (SELECT id FROM ccenters
    START WITH basic =: ParaCCenter
    ID of CONNECTION BY PRIOR = base
    UNION
    SELECT: ParaCCenter OF double
    )
    )
    /
    BEGIN
    : paraCCenter: = 1;
    END;
    /

    SELECT * from ccenters
    WHERE id IN DECODE(:ParaCCenter, 0, id,)
    (SELECT id FROM ccenters
    START WITH basic =: ParaCCenter
    ID of CONNECTION BY PRIOR = base
    UNION
    SELECT: ParaCCenter double))
    /
    The result is
    (SELECT id FROM ccenters
    *
    ERROR at line 3:
    ORA-01427: einreihig subquery returns multiple rows

    How this query can be rewritten for the given feature. Any response will be appreciated.

    Thank you

    Try something like this:

    SELECT * FROM ccenters
    WHERE :ParaCCenter = 0
    OR id in
      (SELECT id FROM ccenters
       START WITH base=:ParaCCenter
       CONNECT BY PRIOR id = base
       UNION
       SELECT :ParaCCenter FROM dual
      )
    
  • Trouble using a function in the where clause

    Hello

    I use a function that is located at ask.tom.oracle.com, which converts a long data type in a character. The function returns an error when it is placed in the where clause. The sql statement, the error message and the function of asking tom are listed below. Does anyone know how to fix this?


    < pre >

    SELECT A.FLDPHYSICAL,
    A.FLDEXPOSURE,
    A.FLDDATEDUE,
    A.FLDDATELAST,
    A.FLDEMPLOYEE,
    B.FLDBDATE,
    B.FLDMAILSTOP,
    B.FLDREC_NUM,
    B.FLDLNAME,
    B.FLDMI,
    B.FLDFNAME,
    B.FLDBDATE,
    B.FLDDEPT,
    B.FLDSTATUS,
    B.FLDSSN,
    B.FLDHOMEPHON,
    B.FLDWORKPHON,
    B.FLDID,
    B.FLDDIVISION

    OF REQEXAM,.
    B OF THE EMPLOYEE,
    C EMPLOYEE_MEMO
    WHERE A.FLDEMPLOYEE = B.FLDREC_NUM
    AND b.flduserstr = c.fldrec_num
    AND OHM_PKG. GET_LONG ('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) AS ' % CDL YES % '.
    "AND A.FLDDATEDUE > 1 January 1900"
    AND A.FLDPHYSICAL = 'COP '.
    ORDER OF B.FLDDIVISION,
    B.FLDLNAME,
    B.FLDFNAME,
    B.FLDMI,
    A.FLDDATEDUE

    -------------------------------------------------------------------------
    The error message

    Error in the command line: 26 column: 4
    Error report:
    SQL error: ORA-00904: "OHM_PKG." "" GET_LONG ": invalid identifier
    00904, 00000 - '% s: invalid identifier '.



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

    create or replace
    PACKAGE OHM_PKG AS

    / * TODO type (types, exceptions, methods etc.) package declarations here * /.
    getlong function (p_tname in varchar2, p_cname in varchar2, p_rowid in rowid) return varchar2;

    END OHM_PKG;

    create or replace
    PACKAGE BODY OHM_PKG AS

    getlong function (p_tname in varchar2, p_cname in varchar2, p_rowid in rowid) return varchar2 as
    whole l_cursor default dbms_sql.open_cursor;
    number of l_n;
    l_long_val varchar2 (4000);
    number of l_long_len;
    number of l_buflen: = 4000;
    l_curpos number: = 0;
    Start
    DBMS_SQL. Parse (l_cursor,
    "select" | p_cname | 'from ' | p_tname |
    ' where rowid =: x',.
    DBMS_SQL.native);
    DBMS_SQL.bind_variable (l_cursor, ': x', p_rowid);

    DBMS_SQL.define_column_long (l_cursor, 1);
    l_n: = dbms_sql.execute (l_cursor);

    If (dbms_sql.fetch_rows (l_cursor) > 0)
    then
    DBMS_SQL.column_value_long (l_cursor, 1, l_buflen, l_curpos,)
    (l_long_val, l_long_len);
    end if;
    DBMS_SQL.close_cursor (l_cursor);
    Return l_long_val;
    getLong end;

    END OHM_PKG;

    < / prev >

    Remove the '_' in the name of the function as below:

    AND OHM_PKG. GETLONG('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) AS "CDL % YES % '.

  • by the way check box values in the WHERE clause

    Hello

    I created a data block - 'CONTACT' (block of data in database)

    and has an element of database - 'Code', 'Descr '.

    The number of records displayed has the value 5.

    When enabled - value 'Y '.

    Value when disabled - n

    Box mapping of other values - "unchecked."


    I write the code inside "WHEN the BUTTON PRESS. My main goal is to return the number of records from

    According to several conditions and one among them is the CODE which can be single or multiple based on the checked checkbox.

    The requirement is when I check one or more boxes, I should pass the "Code" element values in the WHERE clause.

    I tried to use the simple loop but things havmt worked as shown below.

    The next_record refers to the COCHEE BOX as well, and thus return all the eventhough lines if it is not checked.

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

    -LOOP

    IF: contact.cb = 'Y' THEN

    LOOP

    IF p_where is null then

    p_where: =: contact.code;

    on the other

    p_where: = p_where | «, » || : contact.code;

    end if;

    When the output: system.last_record = "TRUE";

    next_record;

    END LOOP;

    end if;

    -END LOOP;

    MESSAGE ("p_where :'|| p_where);

    MESSAGE (' ');

    END;


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

    And even if I write the LOOP before the first CASE, it returns me the current value and move to the last record.

    Please suggest

    Try something like this:

    FIRST_RECORD;
    
    LOOP
    
      IF :contact.cb = 'Y' THEN
        IF p_where is null then
           p_where := :contact.code;
         else
           p_where := p_where ||','||:contact.code;
         end if;
       END IF;
      exit when :system.last_record = 'TRUE';
      next_record;
    END LOOP;
    
    -- END LOOP;
    MESSAGE ( 'p_where :'||p_where);
    MESSAGE (' ');
    
    END;
    
  • Session variable in the WHERE clause of the SQL statement

    Hey all,.

    I was wonering just if there is a way to set the WHERE clause of the query that the session variable?  I have the following so far and have tried to go through a ton of tutorials, but it doesn't seem to work.  Is it still possible?  I don't know what follows is wrong, but can someone help me with changing the following code, or pointing me to a good tutorial?  (I write it with PHP)

    $query = "SELECT * from members where user_id = ' $_SESSION ['members']";

    Thanks for your help.

    $member = "-1";
    If (isset($_SESSION['members'])) {}
    $member = $_SESSION ['members'];

    }
    $query = "SELECT * from members where user_id = $member;

  • Setting in the WHERE clause of the query

    Hi all

    I have 2 tables.

    TABLE_A contains 10 million documents.
    TABLE_B contains 100 records.

    I associate myself with these 2 tables

    Here's a.ID left
    SELECT A.*, B.*
    FROM TABLE_A a, TABLE_B b
    WHERE a.ID = b.ID;
    Here's b.ID left
    SELECT A.*, B.*
    FROM TABLE_A a, TABLE_B b
    WHERE b.ID = a.ID;
    My question is what query will give better performance? I thought that, if we put the column in the table with a lower number of lines on the left, then it will be faster than the other.

    In current versions of Oracle, it does not matter in what order you sum-up your predicates in the WHERE clause of a query: they will be optimized/executed in a way even.

  • Binds a parameter in WHERE clause throws error (ORA-00920)

    Good day to you all.  Hope everything goes well.

    Ok.  Here's the deal.  I am trying to bind a parameter in a where clause clause, but I continue to get the error invalid relational operator (ORA-00920).  It seems as if Oracle is looking for a correct syntax before you pass the variable (bind value).

    For example:

    SELECT LAST_NAME, FIRST_NAME FROM MYTABLE
    WHERE OBSOLETE IS NULL
    and :P_MY_BIND_VALUE
    

    What is the right way to get around this?

    Thanks for all your help!

    AquaNX4 wrote:

    Thank you for the reply.

    I use simple SQL.  The variable binding will be used in the APEX and an item that is based on a LOV with where condition stored there.  Make sense?

    Logic you want... doesn't have a sense of how you try to do.

    Bind variables are for the passage of the 'values' to a question, only not for the passage of the SQL statements or sections of objects such as the names of tables etc.  It is not a substitution string such as the use of '&' in SQL * more and should not be treated this way.

    If you could provide more details on exactly what you're trying to do (some data would help) then perhaps we could tell how best to go about this.

Maybe you are looking for

  • Location sensor drivers

    Hi, I used the troubleshooter of lenovo to solve a problem and 1 thing he showed, is that in Device Manager position sensor was not working properly can not load the driver, I uninstalled by using the Device Manager as I was advised that on next boot

  • HP Scan &amp; Capture app can't find USB printers

    I have a HP Photosmart Premium c410a and with success use application all-in-one HP and HP Scan and Capture app, with the printer using wireless on Windows 8.1. I currently trying to clear up the office and have a lot of scanning to make and have a n

  • Need a quick fix for Windows can't see the CD-Rom drive

    Windows can not see my CD player!

  • Samsung BD Player reports HTTP port is disabled.

    As the subject says, I hung a Samsung BD player on a BEFSR41 router. The router has the current version of the firmware. When I run the test connection to the player, the local connection is good but the Internet connection fails and the message is "

  • How can I send a video attachment of 50 MB using Windows Live Mail?

    Original title: Video accessories in Windows Live Mail. How can I send a video attachment of 50 MB using Windows Live Mail?  I know that skydrive stores the photos but not videos.  In addition, why my spell checker doesn't work?  Word count, works et