Question on using Distinct operator and avoiding ORA-00936 error

I may have answered my own question, by searching the OTN forums, but I just want to confirm what I've learned.
I'm trying to use a distinct on one of my columns, where I am pulling multiple columns, and trying to avoid duplicate entries. From most of my textbook example, when an example is using a distinct, they were only pulling one column.
From my example below, when I try to use a distinct, I get the following error: ORA-00936: missing expression:
select p.list_id, distinct(p.associate_id), d.first, d.last, c.street1, c.street2, c.city, c.state, c.country, c.postal_code, c.email
from sf.profiles p, demographics d, contact_info c
where p.entity_id = d.entity_id
and p.entity_id = c.entity_id
and p.list_id = 111
and associate_id in (insert associate_id in here
);Once I searched OTN, I saw some examples, where they had the distinct operator as the first column. So I switched it with p.list_id, and the query ran find.
select distinct p.associate_id, p.list_id, d.first, d.last, c.street1, c.street2, c.city, c.state, c.country, c.postal_code, c.email
from sf.profiles p, demographics d, contact_info c
where p.entity_id = d.entity_id
and p.entity_id = c.entity_id
and p.list_id = 111
and associate_id in (insert associate_id in here);So, does the distinct operator have to go first, if using multiple columns?
thanks
Message was edited by:
cmmiller

With or without parenthesis, it's a distinct clause for all columns in select statement:
SQL> select * from tt1;
        ID T
     10203 1
     10203 2
SQL> select distinct(id), text from tt1;
        ID T
     10203 1
     10203 2
SQL> select id, text from tt1;
        ID T
     10203 1
     10203 2
SQL> Nicolas.

Similar Messages

  • Do I need a sub-query and getting ORA-00937 error

    I'm writing a query where I want returned all data that is in a list 510 and all duplicate entries for the AID are eliminated.
    select *
    from entities e
    where e.list_id in
    (select aid
    from entities e
    where e.list_id = 510
    having count(e.aid) > 1);
    When I run this, I get ORA-00937: not a single-group group function.
    I google the error and see
    http://ora-00937.ora-code.com/
    Which tells me I can't have a group function and individual column expression.
    So I removed the group by, but I still get the errors, and for some reason when I put the alias e for the aid in the subquery, I still get the same error.
    Hopefully this makes sense what I'm asking...
    thanks

    if you want to select rows that eliminate duplicates then you should be using distinct. And if you want to get the duplicate rows then,
    select *
    from entities e1
    where e1.rowid <
    (select max(e2.rowid)
    from entities e2
    where e2.list_id = 510
    and e1.aid = e2.aid);

  • How to download iTunes and avoid the R6034 error?

    How do you download iTunes and avoid the R6034 error?

    Try the following user tip:
    Troubleshooting issues with iTunes for Windows updates

  • ORA 00936 error

    ORA 00936 errorI c
    reated a new object in BO  universe.
    That object picks data from app_pat.curr_det_ind
    Table is loaded with data. Domain values of that column is 0 and 1.
    When we try to include this object in the report to filter for value 1, we get the following error
    message.
    ORA 00936
    It seems it should list the values and we should select from it.
    Do u have any solution to this?

    Hi
    After i create object i am using that object in query prompt iam getting error ORA 00936.
    can any boby help me outThe object having list of values
    Thanks in advance

  • Export Results ORA-00936 Error Reported

    In an attempt to extract all of a package's source code in one file as well as work in a file-oriented fashion (which other posters have commented is not well supported), I issued a select dbms_metadata.get_ddl(...) from dual. This generated the output I wanted in the worksheet results. However, the ORA-00936 error is thrown when I try to export this as text to overwrite my (checked out from source control) file. My only recourse then becomes to copy the result, open my file (outside SQL-D) and replace what's there (which does work, by the way).
    There was another post on this issue in a prior version where the error was attributed to double quotes around aliases, but I'm still getting the error (see Re: Export query results error, v. 5 / 1343

    This is a bug with how SQL Developer does it's export (not that I could find it logged on MetaLink).
    When you export a query, SQL Developer writes a wrapper select around your query to drive the export. In an example of what you are trying to do, it converts the following query (I added an alias to see if that helped, but it didn't):
    select dbms_metadata.get_ddl('PACKAGE', 'MY_PKG') my_ddl from dual;
    to (based on the trace file with sql_trace switched on):
    select * from (select from ( select dbms_metadata.get_ddl('PACKAGE', 'MY_PKG') my_ddl from dual));
    Your immediate options are to continue with your current workaround, switch to a query on DBA_SOURCE for this export, or cope with the way SQL Developer currently does it's file based development.
    As far as getting this fixed (hopefully before 1.1), you would either need to log an SR on MetaLink or hope that one of the SQL Developer team logs a bug based on this thread.

  • Question about using 10g/11g and APEX ...

    Hi,
    I just recently learned of Oracle's APEX and have a few questions about using it.
    Can I use APEX with express, standard, and enterprise editions of 10g and 11g?
    Are all of these free to use?

    You might want to read about APEX rather than jumping into questions that are reasonably well documented. Info at http://www.oracle.com/technology/products/database/application_express/index.html
    Your specific questions:
    1) Apex is a package that can be installed into any properly licensed database.
    2) The price for the production license of the database varies by edition.
    The price for Express Edition is $0 for use in production. Part of the cost for that edition is 'no Oracle Support based support, no patches, data volume limitation, etc.'

  • Alrt with field Lelvel Info - By using Container Operation and Control step

    HI,
    I have developed File to File scenario from /people/michal.krawczyk2/blog/2005/03/13/alerts-with-variables-from-the-messages-payload-xi--updated
    I created Integration Process in IR with two BPM steps Receive and Send step.
    Since I need a filed level info on alerts...I have included Container Operation and Control steps in between receive and send like..
    Receive --- Container Operation --- Control step -
    Send
    And now I have created the Alert category in Alrtcatdef and used the same category in control step.
    I have tested the above scenario with error message ( with mapping fail )...But I am unable to find the alert in the system?!!
    ---S

    HI Stallin
    Did alert generated by BPM itself. Check with BPM workflow.
    Another thing while generating alert from BPM, standard alert element will not work with BPE engine. Create elements for the same
    Thanks
    Gaurav

  • CONTAINS clause and the ORA-29902 error.

    Hello folks,
    I am encountering the following error in APEX.
    report error:
    ORA-29902: error in executing ODCIIndexStart() routine
    ORA-20000: Oracle Text error:
    DRG-10825: stored query does not exist: employee
    DRG-10825: stored query does not exist: employee
    Here is the rest of the information :
    1. I have created the index on the column in question as specified here.
    bq. {color:#0000ff} CREATE INDEX{color} \\ {color:#0000ff} \\ emp_idx ON meta_eul (display_name){color} \\ {color:#0000ff} \\ indextype is ctxsys.context; \\ {color}
    2. I have created the sqe for the word as suggested [here |http://download-west.oracle.com/docs/cd/B19306_01/text.102/b14218/cqrypkg.htm#i997218]: employee
    bq. {color:#0000ff} begin{color} \\ {color:#0000ff} \\ ctx_query.store_sqe('employee', 'empl or emp');{color} \\ {color:#0000ff} \\ end;{color}
    3. When I execute the following sql in sql developer, I get results
    bq. {color:#0000ff} SELECT SCORE(1), A.DISPLAY_NAME \\ FROM meta_eul a \\ WHERE 1 =1 \\ AND CONTAINS(A.DISPLAY_NAME , 'sqe(employee)', 1)&gt; 0 \\ ORDER BY SCORE(1) \\ {color}
    4. I have the same query in #3 above as a region in my Page.
    When I execute it, I get the error that I have mentioned above.
    Any thoughts ? Is this a limitation ?
    I am on Apex version 3.0
    Regards,
    Atul

    Thanks, Roel.
    A similar option that worked out as an alternative is that I have changed the region code to :
    bq. {color:#0000ff}SELECT SCORE(1), A.DISPLAY_NAME \\     FROM meta_eul a \\     WHERE 1 =1 \\     AND CONTAINS(A.DISPLAY_NAME , 'emp or empl or employee', 1)&gt; 0 \\     ORDER BY SCORE(1) \\ {color}
    and have avoided the sqe part. This doesn't seem to have an issue in Apex.

  • ORA-06512 and/or ORA-00936 ... simple procedure problem probably

    I'm passing in codes like the following to the stored procedure (below):
    ",IRE,UK,FR,SCOT,WALES" (a string of words seperated by a ',')
    Problem is I get the following error:
    ORA-00936: missing expression ORA-06512: at "APPNAME.PKG_TOOL", line 132 ORA-06512: at line 1
    I googled the two ORA's but am still stumped. I'd appreciate any help at all as I'm still not overly familiar with SQL.
    PROCEDURE sp_check_code_Exist(p_CodeList IN varchar, p_cursorSMB IN OUT cursorSMB) IS
         thissql varchar(1000);
         BEGIN
              thissql := thissql || 'select * from codes_data c where ';
              thissql := thissql || 'c.code in ('|| p_CodeList ||') ';
              open p_cursor FOR thissql;
              begin
                     Execute immediate thissql;
              end;
         END sp_check_code_Exist;

    I know this is digressing a bit from the thread heading but I'd like to know if I really will be screwed if I don't optimise.
    The machine that this is being hosted on will be a top notch machine with a very fat line and will have probably only thousands of codes.
    This is the code as it stands now
    PROCEDURE sp_check_GenericCodes(p_GenericsList IN varchar, p_cursorSMB IN OUT cursorSMB) IS
         thissql varchar(1000);
         BEGIN
              thissql := thissql || 'select distinct generic_code from emc_codes_data ed where ';
              thissql := thissql || 'ed.generic_code in ('||p_GenericsList||')';
              open p_cursorSMB FOR thissql;
         END sp_check_GenericCodes;So all I'll be returning is a few thousand words which will then be sorted alphabetically and will be then compared to another string which will be sorted alphabetically, to see if there is any missing code, and if there are then those codes will be spit out to an admin who will realise he made a mistake and where the mistake is.
    This is how its all called:
    public string checkGenericCodesExist(string codesList)
                   OracleDataReader rdr = null;
                   DBConnect dbConnLocal = null;
                   OracleCommand cmd = null;
                   string sRetVal = null;
                   string CurrentFunction = "PPTEngine.clsPart.genericCodeExsists";               
                   try
                        dbConnLocal = new DBConnect(CurrentFunction, "Pkg_SMBTool.sp_check_GenericCodes", m_Stream);
                        // Pass in parameters
                        dbConnLocal.addParam(new OracleParameter("p_cursorSMB", OracleType.Cursor));                    
                        dbConnLocal.setParamDirection("p_cursorSMB",ParameterDirection.Output);
                        dbConnLocal.addParam(new OracleParameter("p_GenericsList", OracleType.VarChar));
                        dbConnLocal.setParamValue("p_GenericsList", codesList);                    
                        // Execute
                        cmd = dbConnLocal.ExecuteProcedure();
                        rdr = (OracleDataReader)cmd.Parameters["p_cursorSMB"].Value;
                        // Loop
                        if (rdr.HasRows)
                             while (rdr.Read())
                                  if (!rdr.IsDBNull(rdr.GetOrdinal("Generic_Code"))) m_GenericCode = rdr.GetString(rdr.GetOrdinal("Generic_Code"));
                        rdr.Close();
                        //remove the '
                        string[] PPTCodes = codesList.Replace( "'", null).Split("','".ToCharArray());
                   catch (Exception e)
                        Log.WriteToFile(CurrentFunction + " - " + e.Message, System.Diagnostics.TraceLevel.Error);
                        throw e;
                   finally
                        if (dbConnLocal!=null) dbConnLocal.Close();
                   return sRetVal;
              }The above function is still a work in progress, but is almost there.

  • Report Generation Toolkit (Word) : How to use correctly bookmark and cross-reference without "Error! Reference source not found"

    Hi,
    I try to generate a report using a template. In my template I use some cross-reference to refer to one bookmark. For exemple in the first page I created a bookmark for my name and in the header I created a cross-reference refer to my name. The problems is when I run my VI the bookmark actualise perfectly but the cross-reference refer to the bookmark can't actualise with the same value and generates an error : "Error! Reference source not found".
    Can somebody help me please!
    Nki
    Solved!
    Go to Solution.
    Attachments:
    01.jpg ‏72 KB

    Hi,
    When i create the word template, the bookmaks and the cross-reference referred to the bookmark update correctely. The problem is when I try to change the bookmark using "report generation from template vi" the bookmark change but not the cross-reference and the error generated is "Error! Reference source not found". 
    I make coople reasherch and i think they have no solution for this because : "if the text in a heading referred to in a cross-reference is revised, the cross-reference to the heading may no longer work" (http://office.microsoft.com/en-us/word-help/troubleshoot-cross-references-HP005189368.aspx).
    To "resolved" this problem I create an other bookmark in the template who have the same value white the principle bookmark.   
    I use Labview 2011 and Micosoft office 2010.

  • Owb beta 3 / master detail mapping with sequence ora-00936 error

    I'm not able to use sequence operator in mapping to create relationships between different record type from the same flat file. I have got an sql error ORA-00936: expression absente
    The problem seem to be the sequence is not referenced in the sql loader parameter. The sequence exists, was deployed sucessfully, the mapping is validated and successfully deployed. The problem occurs during execution

    Good afternoon "micwic",
    In general, mappings with flat files make use of data generators, not sequence operators. This is what the User Guide (10gR1 but I guess R2 works similar) says for the Data Generator Operator :
    Use a Data Generator operator to provide information such as record number, system date, and sequence values.
    For mappings with flat file sources, the Data Generator operator also provides a place to enter constant information. For mappings with Flat File sources and targets, the Data Generator operator connects the mapping to SQL*Loader to generate the data stored in the database record.
    The following functions are available:
    RECNUM
    SYSDATE
    SEQUENCE
    It is possible for Warehouse Builder to generate data by specifying only sequences, record numbers, system dates, and constants as field specifications. SQL*Loader inserts as many records as are specified by the LOAD keyword.
    Setting a Column to the Data File Record Number
    Use the RECNUM keyword to set an attribute to the number of the records that tthe record was loaded from. Records are counted sequentially from the beginning of the first data file, starting with record 1. RECNUM increments as each logical record is assembled. It increments for records that are discarded, skipped, rejected, or loaded.
    For example, if you use the option SKIP=10, the first record loaded has a RECNUM of 11.
    Setting a Column to the Current Date
    A column specified with SYSDATE gets the current system date, as defined by the SQL language SYSDATE function.
    The target column must be of type CHAR or DATE. If the column is of type CHAR, then the date is loaded in the format dd-mon-yy. After the load, you only access it in that format. If the system date is loaded into a DATE column, then you can only access it in a variety of formats including the time and the date. A new system date/time is used for each array of records inserted in a conventional path load and for each block of records loaded during a direct path load.
    Setting a Column to a Unique Sequence Number
    The SEQUENCE keyword ensures a unique value for a column. SEQUENCE increments for each record that is loaded or rejected. It does not increment for records that are discarded or skipped.
    Recommendation: For PL/SQL mappings use a Constant Operator or Mapping Sequence Operator instead of a Data Generator.
    etc.
    Good luck, Patrick

  • ORA-00936 error from SQL expression in SQL*Loader script

    I am getting the above error on the following line in my SQL*Loader script:
    DIA_CLM_RES_OID DECIMAL EXTERNAL
    "SELECT N_ORG_ENTY_ID FROM TESTG4.ORG_ENTITY
    WHERE N_USER_ID =
    (SELECT UNIQUE WSR_NT_ID FROM CONV_CLM_RESOURCE
    WHERE CLM_RES_OID = :DIA_CLM_RES_OID)",
    What I am basically trying to do is a 2-table lookup of a value:
    1. Find a row in table CONV_CLM_RESOURCE where the value in column CLM_RES_OID matches the value in the input file in field DIA_CLM_RES_OID.
    2. Take the value of field WSR_NT_ID from that row and use it to find a row in table TESTG4.ORG_ENTITY.
    3. Take the value of field WSR_NT_ID from that row and set it in the target table in field DIA_CLM_RES_OID.
    In other words, I am essentially trying to translate the input value by using two other tables to lookup the value to translate to. However, no matter how I arrange it, I keep getting the "ORA-00936: missing expression" error on this statement.
    Can anyone see what I am doing wrong, or perhaps suggest a better way of accomplishing a two-table translation of a value?
    Thanks!

    Still not sure why this doesn't work, but I was able to create and use a function to do this instead, which is probably a better approach anyway.

  • I can't not use spatial operator and index .

    Dear all,
    I create following spatial tales and spatial index.
    create table LHelix(
    PDB_IDcode           varchar(8) not null,
    chainID varchar(2),
    Hnum number not null,
    anum varchar(6),
    Hgeo MDSYS.SDO_GEOMETRY,
    primary key(PDB_IDcode,chainId,hnum,anum))
    insert into user_sdo_geom_metadata values(
    'LHELIX','HGEO',
    mdsys.sdo_dim_array(
    mdsys.sdo_dim_element('X',-400,400,0.05),
    mdsys.sdo_dim_element('Y',-400,400,0.05),
    mdsys.sdo_dim_element('Z',-400,400,0.05)),0);
    create index LhI on Lhelix(hgeo) indextype is MDSYS.spatial_index
    PARAMETERS ('SDO_level=12 sdo_numtiles=100 sdo_maxlevel= 32')
    After that, I perfomed following query.
    select distinct l1.pdb_idcode, l2.pdb_idcode,l1.hnum, l2.hnum
    from lhelix l1, lhelix l2
    where mdsys.sdo_relate(l1.hgeo, l2.hgeo, 'mask=ANYINTERACT querytype=Window')='TRUE' and
    l1.pdb_idcode != l2.pdb_idcode and l2.pdb_idcode='1wja';
    When I did this query, I got the results.
    But Now when I try query, I have following errors.
    ORA-29902: ODCIIndexStart() ·çƾÀ» ¼öÇà½Ã ¿À·ù°¡ »ý°å½À´Ï´Ù
    ORA-13208: ³»ºÎ ¿À·ù°¡ [window SRID does not match layer SRID] ¿¬»êÀÚ¸¦
    Æò°¡Çϴµ¥ »ý°å½À´Ï´Ù
    ORA-06512: "MDSYS.SDO_INDEX_METHOD", ÁÙ 84¿¡¼
    ORA-06512: ÁÙ 1¿¡¼
    Dose anybody know how can I handle this problems?
    I am so in hurry!!!
    Please help me!!!
    Thanks!!
    sung

    I would suggest two things:
    1) Do not use 0 for the SRID in the user_sdo_geom_metadata entry. There is no 0 SRID value. Look at the sdo_srid value in your geometries, and if it is NULL, specify NULL. If there is a value, match it in the user_sdo_geom_metadata entry.

  • Questions around use of thesaurus and synonyms

    Q1. Does thesaurus support Japanese/Chinese/Korean? The document didn't say no. But didn't confirm it explicitly.
    Q2. For ctxload to load a thesaurus import file, what encoding should be the file? UTF-8?
    Q3. Is synonym relation reflextive in Oracle Text? After define EUR is Euro, should I define Euro is EUR?
    Q4. From the document, when I define a synonym, I cannot specify language. If I define a synonym between 'USD' and 'US Dollar'. And when I query I use SYN(USD), will this expand into 'USD,US Dollar' no matter what language is the document?

    Here are some information which may answer your questions
    Ans1)
    We have a limitation for language specific character sets
    You can only add knowledge bases for languages with single-byte character sets.
    You cannot create a knowledge base for languages which can be expressed only in multibyte character sets.
    I think Japanese/Chinese/Korean are represented in multi byte character sets, so we cannot.
    Ans2) Supplied knowledge bases with Oracle text are in WE8ISO8859P1. You can store an extended knowledge base in another character set such as US7ASCII.
    Knowledge bases can be in any single-byte character set.
    Ans 3) No you dont need to.It is reflexive.
    you can check the following example
    create table test(id number, text varchar(20));
    insert into test values (1, 'os');
    insert into test values( 2, 'operating system');
    insert into test values(3, 'windows');
    exec ctx_thes.create_thes('my_thes',FALSE);
    exec ctx_thes.create_phrase('my_thes','os');
    exec ctx_thes.create_phrase('my_thes','operating system');
    exec ctx_thes.create_relation('my_thes','os','SYN','operating system');
    declare
    syno varchar2(50);
    begin
    syno := ctx_thes.syn('os','my_thes');
    dbms_output.put_line('the synonym of os is : ' || syno);
    end;
    --o/p is the synonym of os is : {OS}|{OPERATING SYSTEM}
    declare
    syno varchar2(50);
    begin
    syno := ctx_thes.syn('operating system','my_thes');
    dbms_output.put_line('the synonym of operating system is : ' || syno);
    end;
    --o/p is the synonym of op sys is : {OPERATING SYSTEM}|{OS}
    Ans 4) I think you are trying to say the following
    you have a thes file..say in spanish
    and you have an entry in that file for USD Syn in English...
    you want to ask whether still Oracle can return SYN(USD) = 'USD,US Dollar'
    Am I right?

  • Question on using CAST, MULTISET and TABLE

    Hi,
    I am trying to do something that is utterly meaningless, but I am studying the use of CAST with MULTISET and TABLE.
    I have created a type: a Nested Table of Number values:
    create type numTable as table of number;
    Now I perform the following query:
    select d.dname
    , ( select avg(column_value)
    from table
    ( cast( d.salaries as numTable)
    ) Department_Avg_Salary
    from ( select cast
    ( multiset
    ( select e.sal
    from emp e
    where e.deptno = d1.deptno
    ) as numTable
    ) salaries
    , d1.dname
    from dept d1
    ) d
    I had expected to see each department name and the average salary within that department. Instead, I see the same Department_Avg_Salary value for each row - the average of the first department:
    DNAME DEPARTMENT_AVG_SALARY
    ACCOUNTING 1875
    RESEARCH 1875
    SALES 1875
    OPERATIONS 1875
    However, when I change the query to the following:
    select d.dname
    , d.salaries
    from ( select cast
    ( multiset
    ( select e.sal
    from emp e
    where e.deptno = d1.deptno
    ) as numTable
    ) salaries
    , d1.dname
    from dept d1
    ) d
    I get the following result - note that each department shows the correct list of salaries, not the list of the 1st department's salaries over and over.
    DNAME
    SALARIES
    ---------------------------------------------------------ACCOUNTING
    NUMTABLE(2450, 1300)
    RESEARCH
    NUMTABLE(800, 2975, 3000, 5000, 1100, 3000)
    SALES
    NUMTABLE(1600, 1250, 1250, 2850, 1500, 950)
    OPERATIONS
    NUMTABLE()
    Can someone explain why the
    , ( select avg(column_value)
    from table
    ( cast( d.salaries as numTable)
    ) Department_Avg_Salary
    does not give an average per department but instead only the first department's average?
    thanks for your help!
    regards
    Lucas Jellema

    scott@ORA92> select d.dname,
      2           (select avg(column_value)
      3            from   table (cast (d.salaries as numTable))
      4            where d.dname = dname) Department_Avg_Salary
      5  from   (select cast (multiset (select e.sal
      6                          from   emp e
      7                          where  e.deptno = d1.deptno) as numTable) salaries,
      8                 d1.dname
      9            from    dept d1) d
    10  /
    DNAME          DEPARTMENT_AVG_SALARY
    ACCOUNTING                2916.66667
    RESEARCH                        2175
    SALES                     1566.66667
    OPERATIONS

Maybe you are looking for