In a SQL statement, the SELECT clause is used to

In a SQL statement, the SELECT clause is used to select
(a) columns
(b) rows
(c) tables
(d) none of the above
can any one help Immediately

Is used to select rows of specified column...
SELECT column_name(s) FROM table_name

Similar Messages

  • Merge can't accept a variable in the select clause?

    oracle 10.2
    I have a stored procedure.
    I have a variable, vseq, which I set a sequence variable. With all other sql statements I can do
    insert into table a
    select vseq
    from dual;
    Apparently a merge can't handle variables in the select clause. I get an error. I can get it to work when I hard code a value.
    this is ridiculous...

    merge can't handle variables in the select clauseCare to prove?
    sql> DECLARE
      2   v_first_name varchar2(20) := 'BOSS';
      3  BEGIN
      4  MERGE INTO sun_employees se
      5  USING (SELECT * FROM employees WHERE department_id = 20) e
      6  ON (e.employee_id = se.employee_id)
      7  WHEN MATCHED THEN
      8    UPDATE SET salary = e.salary
      9  WHEN NOT MATCHED THEN
    10  INSERT(employee_id, first_name, last_name, department_id)
    11  VALUES (e.employee_id, v_first_name, e.last_name, e.department_id);
    12  END;
    13  /
    PL/SQL procedure successfully completed.
    sql> select first_name from sun_employees;
    FIRST_NAME
    BOSS
    BOSS

  • SQL statement with union clause

    Hi,
    I have a scenario where i need to generate a sql statement with UNION .
    Eg:
    SELECT B.YY_ID,
    FROM XXXX.YY B
    WHERE (B.YY_TY= 'as')
    UNION
    SELECT B.YY_ID
    FROM XXXX.YY_ALT_NAME A, XXXX.YY B
    WHERE (A.YY_TY= 'zx'
    AND (B.YY_ID=A.YY_ID)"
    I tried ns1:table1() union ns3:table2() in XQuery.
    But it is pushdown as 2 seperate sqls.
    Is it possible to create XQuery that pushdown as SINGLE SQL statement with union clause ?
    Thanks

    No. See 3.1.1.5 in the document I referenced in your previous post.

  • Subquery in the Select Clause

    Can a subquery in the select clause return more than one field?
    Something like this:
    select ename,
    (select dname, loc from dept where e.deptno = deptno) as (dname,loc)
    from emp e

    A simple way to find out is to test it. In my tests below, the original query produces an error that says it didn't find FROM where it expected. Eliminating "as (dname,loc)" produces an error about too many values. Putting only one value in the subquery in the select clause works, whether it is dname or loc. Concatenating the two columns as dname || ' ' || loc to produce one value in the subquery in the select clause works. Using two separate subqueries, one for dname and one for loc works. And, lastly, a cursor statement with both values works, although the output is a little hard to read. This may be different in newer versions. I am using Oracle 8.1.7. It may be different in 9i. I was unable to locate any documentation on the cursor statement or cursor operator which I have also heard it called. I only knew to try it because I have seen it used. I looked up the SELECT syntax in the 9i SQL Reference and there was no mention of cursor in the select clause. Can anyone provide a link to some documentation on this? I vaguely recall reading something that said that, other than outputting from SQL*Plus as below, it wasn't yet compatible with anything else, like you can't use it in PL/SQL, but I can't remember where I read it.
    SQL> -- 2 values in subquery in select clause:
    SQL> select ename,
      2  (select dname, loc from dept where e.deptno = deptno) as (dname,loc)
      3  from emp e
      4  /
    (select dname, loc from dept where e.deptno = deptno) as (dname,loc)
    ERROR at line 2:
    ORA-00923: FROM keyword not found where expected
    SQL> select ename,
      2  (select dname, loc from dept where e.deptno = deptno)
      3  from emp e
      4  /
    (select dname, loc from dept where e.deptno = deptno)
    ERROR at line 2:
    ORA-00913: too many values
    SQL> -- 1 value in subquery in select clause:
    SQL> select ename,
      2  (select dname from dept where e.deptno = deptno)
      3  from emp e
      4  /
    ENAME      (SELECTDNAMEFR                                                      
    SMITH      RESEARCH                                                            
    ALLEN      SALES                                                               
    WARD       SALES                                                               
    JONES      RESEARCH                                                            
    MARTIN     SALES                                                               
    BLAKE      SALES                                                               
    CLARK      ACCOUNTING                                                          
    SCOTT      RESEARCH                                                            
    KING       ACCOUNTING                                                          
    TURNER     SALES                                                               
    ADAMS      RESEARCH                                                            
    JAMES      SALES                                                               
    FORD       RESEARCH                                                            
    MILLER     ACCOUNTING                                                          
    14 rows selected.
    SQL> select ename,
      2  (select loc from dept where e.deptno = deptno)
      3  from emp e
      4  /
    ENAME      (SELECTLOCFRO                                                       
    SMITH      DALLAS                                                              
    ALLEN      CHICAGO                                                             
    WARD       CHICAGO                                                             
    JONES      DALLAS                                                              
    MARTIN     CHICAGO                                                             
    BLAKE      CHICAGO                                                             
    CLARK      NEW YORK                                                            
    SCOTT      DALLAS                                                              
    KING       NEW YORK                                                            
    TURNER     CHICAGO                                                             
    ADAMS      DALLAS                                                              
    JAMES      CHICAGO                                                             
    FORD       DALLAS                                                              
    MILLER     NEW YORK                                                            
    14 rows selected.
    SQL> select ename,
      2  (select dname || ' ' || loc from dept where e.deptno = deptno)
      3  from emp e
      4  /
    ENAME      (SELECTDNAME||''||LOCFROMDEP                                        
    SMITH      RESEARCH DALLAS                                                     
    ALLEN      SALES CHICAGO                                                       
    WARD       SALES CHICAGO                                                       
    JONES      RESEARCH DALLAS                                                     
    MARTIN     SALES CHICAGO                                                       
    BLAKE      SALES CHICAGO                                                       
    CLARK      ACCOUNTING NEW YORK                                                 
    SCOTT      RESEARCH DALLAS                                                     
    KING       ACCOUNTING NEW YORK                                                 
    TURNER     SALES CHICAGO                                                       
    ADAMS      RESEARCH DALLAS                                                     
    JAMES      SALES CHICAGO                                                       
    FORD       RESEARCH DALLAS                                                     
    MILLER     ACCOUNTING NEW YORK                                                 
    14 rows selected.
    SQL> select ename,
      2  (select dname from dept where e.deptno = deptno),
      3  (select loc from dept where e.deptno = deptno)
      4  from emp e
      5  /
    ENAME      (SELECTDNAMEFR (SELECTLOCFRO                                        
    SMITH      RESEARCH       DALLAS                                               
    ALLEN      SALES          CHICAGO                                              
    WARD       SALES          CHICAGO                                              
    JONES      RESEARCH       DALLAS                                               
    MARTIN     SALES          CHICAGO                                              
    BLAKE      SALES          CHICAGO                                              
    CLARK      ACCOUNTING     NEW YORK                                             
    SCOTT      RESEARCH       DALLAS                                               
    KING       ACCOUNTING     NEW YORK                                             
    TURNER     SALES          CHICAGO                                              
    ADAMS      RESEARCH       DALLAS                                               
    JAMES      SALES          CHICAGO                                              
    FORD       RESEARCH       DALLAS                                               
    MILLER     ACCOUNTING     NEW YORK                                             
    14 rows selected.
    SQL> -- cursor statement:
    SQL> select ename,
      2  cursor (select dname, loc from dept where e.deptno = deptno)
      3  from emp e
      4  /
    ENAME      CURSOR(SELECTDNAME,L                                                
    SMITH      CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    RESEARCH       DALLAS                                                          
    1 row selected.
    ALLEN      CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    SALES          CHICAGO                                                         
    1 row selected.
    WARD       CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    SALES          CHICAGO                                                         
    1 row selected.
    JONES      CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    RESEARCH       DALLAS                                                          
    1 row selected.
    MARTIN     CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    SALES          CHICAGO                                                         
    1 row selected.
    BLAKE      CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    SALES          CHICAGO                                                         
    1 row selected.
    CLARK      CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    ACCOUNTING     NEW YORK                                                        
    1 row selected.
    SCOTT      CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    RESEARCH       DALLAS                                                          
    1 row selected.
    KING       CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    ACCOUNTING     NEW YORK                                                        
    1 row selected.
    TURNER     CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    SALES          CHICAGO                                                         
    1 row selected.
    ADAMS      CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    RESEARCH       DALLAS                                                          
    1 row selected.
    JAMES      CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    SALES          CHICAGO                                                         
    1 row selected.
    FORD       CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    RESEARCH       DALLAS                                                          
    1 row selected.
    MILLER     CURSOR STATEMENT : 2                                                
    CURSOR STATEMENT : 2
    DNAME          LOC                                                             
    ACCOUNTING     NEW YORK                                                        
    1 row selected.
    14 rows selected.

  • Fetching a value from a select statement inside select clause

    hello all,
    I have a problem executing a procedure it gives me a runtime error, what am doing is i have multiple select statement inside a select clause. am using the entire select statement for a ref cursor. when running the query seperately am able to get the records but it's not getting compiled.
    here is the piece of code which am working with
    create or replace procedure cosd_telecommute_procedure
    (p_from_date in date,
    p_to_date in date,
    p_rset in out sys_refcursor)
    as
    p_str varchar2(10000);
    begin
    p_str := 'select personnum, '||
    'fullname, '||
                   'personid, '||
         'hours, '||
         'applydtm, '||
    'paycodeid, '||
         'laborlev2nm, '||
         'laborlev3nm, '||
         'laborlev2dsc, '||
    'adjdate, '||
         'timeshtitemtypeid, '||
         '(select max(eff_dt) from cosd_telecommute_info_tbl '||
         'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt between ''01-aug-2005'' and ''30-aug-2005'') thisyreffdt, '||
                   '(select elig_config7 from cosd_telecommute_info_tbl '||
                   'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt = (select max(eff_dt) from cosd_telecommute_info_tbl '||
                   'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt between ''01-aug-2005'' and ''30-aug-2005'')) thisyrmiles,'||
    '(select max(eff_dt) from cosd_telecommute_info_tbl '||
                   'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt between trunc(p_from_date) and trunc(p_to_date)) fiscalyreffdt, '||
         '(select elig_config7 from cosd_telecommute_info_tbl '||
                   'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt = (select max(eff_dt) from cosd_telecommute_info_tbl '||
                        'where emplid = cosd_vp_telecommute.personnum and '||
    'eff_dt between trunc(p_from_date) and trunc(p_to_date))) fiscalyrmiles '||
    'from cosd_vp_telecommute '||
    'where trunc(applydtm) '||
    'between p_from_date and p_to_date '||
                   'and personnum = ''029791''';
                   open p_rset for p_str;
    end cosd_telecommute_procedure;
    and here is the piece of error am getting
    ERROR at line 1:
    ORA-00904: invalid column name
    ORA-06512: at "TKCSOWNER.COSD_TELECOMMUTE_PROCEDURE", line 40
    ORA-06512: at line 5

    Did you run the query in SQL plus? Check whether all the column are valid in your database. Below is the query which i got from your procedure just run and check it out. It is really hard for us to tell you the problem without knowing the table structure
    select personnum, fullname, personid, hours, applydtm, paycodeid, laborlev2nm, laborlev3nm,
    laborlev2dsc, adjdate, timeshtitemtypeid,
    (select max(eff_dt) from cosd_telecommute_info_tbl
      where emplid = cosd_vp_telecommute.personnum
      and eff_dt between '01-aug-2005' and '30-aug-2005') thisyreffdt,
      (select elig_config7 from cosd_telecommute_info_tbl where emplid = cosd_vp_telecommute.personnum
      and eff_dt = (select max(eff_dt)
                    from cosd_telecommute_info_tbl
                    where emplid = cosd_vp_telecommute.personnum
                    and eff_dt between '01-aug-2005' and '30-aug-2005'
       ) thisyrmiles,
      (select max(eff_dt)
       from cosd_telecommute_info_tbl
       where emplid = cosd_vp_telecommute.personnum
       and eff_dt between trunc(p_from_date) and trunc(p_to_date)
       ) fiscalyreffdt,
       (select elig_config7 from cosd_telecommute_info_tbl where emplid = cosd_vp_telecommute.personnum
       and eff_dt = (select max(eff_dt)
                     from cosd_telecommute_info_tbl
                     where emplid = cosd_vp_telecommute.personnum
                     and eff_dt between trunc(p_from_date) and trunc(p_to_date)
       ) fiscalyrmiles
    from cosd_vp_telecommute
    where trunc(applydtm) between p_from_date and p_to_date
    and personnum = '029791'

  • Using @Prompt in the SELECT clause (?)

    Post Author: faltinowski
    CA Forum: Semantic Layer and Data Connectivity
    Product:  Business Objects
    Version:  6.5 SP3 
    Patches Applied:  MHF11 and CHF48
    Operating System(s):  Windows
    Database(s):  Oracle
    Error Messages:  "Parse failed: Exception: DBD, ORA-00903 invalid table name  State N/A"
    Hi!  I'm bewildered -- we have an object that parses but when I try to reproduce this object, it does not.
    We have a universe that's been in production for several years using an object developed by another designer who's no longer with the company.  This object is a dimension, datatype is character, and there's no LOV associated.  The SELECT statement in this object is
    decode(@Prompt('Select Snapshot Month','A','Object Definitions\CY Month Snapshot',MONO,CONSTRAINED),'00-Previous Month',to_number(to_char(add_months(sysdate,-1),'MM')),'01-Current Month',to_number(to_char(add_months(sysdate,0),'MM')),'01-January','1','02-February','2','03-March','3','04-April','4','05-May','5','06-June','6','07-July','7','08-August','8','09-September','9','10-October','10','11-November','11','12-December','12')
    This object parses. The client uses the object in the select clause to capture the "month of interest" for the report.  So the report may be for the entire year's data which is graphed to show trends, but there's a table below the graph which is filtered to show just the month of interest.  Typically they use the value "00-Previous Month" so they can schedule the report and it will always show the last month's data.
    Problem
    The original object parses.
    If I copy the object within the same universe, it parses.
    If I copy the code into a new object in the same universe, it doesn't parse
    If I copy the code into a new object in a different universe, it doesn't parse
    If I copy the object to a different universe, then edit the LOV reference, it doesn't parse
    If I create any new object having @Prompt in the SELECT statement, it doesn't parse.
    If another designer tries - they get the same thing.
    What am I missing?  Obviously someone was able to create this successfully.
    On the brighter side
    The object I created in a new universe (which doesn't parse in the universe) seems to work fine in the report.

    Seems that, the prompt syntax is correct.
    But the condition is not correct.
    You are taking the prompt value and not doing anything. That could be one issue for this error.
    I believe that, you just want to capture the prompt value use it in report level and do not want to apply as a filter.
    So, use the condition as follows.
    @Prompt('Select Grouping','A',{'A','B','C'},mono,constrained) = @Prompt('Select Grouping','A',{'A','B','C'},mono,constrained)
    Hope this helps!

  • Problems with query with more than 20 values in the select clause

    I have a region based on a function returning a SQL query. It needs to have more than 20 values in the select clause. When I run the page I get a no data found error in the region. I managed to reproduce this behavior with just the following as the select returned by the function:
    select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21
    from dual
    I am running the 1.3.9.00.15 release of Marvel on 9.2.0.2 of the db on Solaris.

    Hello Raju,
    I will email you the connection settings when I return to the office.
    One thing I should have mentioned: The sql string is returned from a package in the db, so the query region text I originally posted isn't quite correct.
    it is something like:
    declare
    begin
    return my_pkg.my_fnc;
    end;
    the stored package is nothing more than:
    package my_pks is
    funtion my_fnc(i_test_param in varchar2) is
    begin
    return 'select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 21 from dual';
    end;
    end;
    Sorry for the inaccurate info in the first post, but I am away from the server in question right now.

  • Using Native Query to run a SQL statement, the "getResultList" throws excep

    I run the following code and I get an exception, can someone tell me what I'm doing wrong? I tried debugging, but as soon as I try even stepping into the "getResultList" line, it throws the exception.
    public void setData(EntityManager emgr) {
    System.err.println(m_sqlStatement);
    Query q = emgr.createNativeQuery(m_sqlStatement);
    @SuppressWarnings("unchecked")
    List<List<Object>> c = q.getResultList();
    for (List<Object> d : c) {
    if (d == null || d.isEmpty()) {
    continue;
    addRow(d.toArray());
    }I took this sql statement and created a test view and ran it against my database and I get the data that I want the way that I want it. So, I feel pretty confident that the problem is not with my sql statement.
    m_sqlStatement =
    SELECT TimeSubmitted AS "Time Completed", ActivityName AS "Activity", PN AS "Part Number", OpNum AS "Op Num", isConforming AS "Conforming?", SetupHrs AS "Expected Setup Time (Hrs.)", RunHrs AS "Expected Run Time (Hrs.)" FROM CellManager INNER JOIN Routings ON Routings.ID=CellManager.RoutingsRef INNER JOIN PNTable ON PNTable.ID=Routings.PNRef INNER JOIN ActivityType ON ActivityType.ID=CellManager.ActivityTypeRef INNER JOIN Activity ON Activity.CellManagerRef=CellManager.ID WHERE CellManager.OperatorLogRef=15 Order BY TimeSubmitted
    Exception thrown:
    SEVERE: Application class productionefficiencyviewergui.ProductionEfficiencyViewerGUIApp failed to launch
    Local Exception Stack:
    Exception [TOPLINK-6132] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.QueryException
    Exception Description: Query argument " not found in list of parameters provided during query execution.
    Query: DataReadQuery(){code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I run the following code and I get an exception, can someone tell me what I'm doing wrong? I tried debugging, but as soon as I try even stepping into the "getResultList" line, it throws the exception.
    public void setData(EntityManager emgr) {
    System.err.println(m_sqlStatement);
    Query q = emgr.createNativeQuery(m_sqlStatement);
    @SuppressWarnings("unchecked")
    List<List<Object>> c = q.getResultList();
    for (List<Object> d : c) {
    if (d == null || d.isEmpty()) {
    continue;
    addRow(d.toArray());
    }I took this sql statement and created a test view and ran it against my database and I get the data that I want the way that I want it. So, I feel pretty confident that the problem is not with my sql statement.
    m_sqlStatement =
    SELECT TimeSubmitted AS "Time Completed", ActivityName AS "Activity", PN AS "Part Number", OpNum AS "Op Num", isConforming AS "Conforming?", SetupHrs AS "Expected Setup Time (Hrs.)", RunHrs AS "Expected Run Time (Hrs.)" FROM CellManager INNER JOIN Routings ON Routings.ID=CellManager.RoutingsRef INNER JOIN PNTable ON PNTable.ID=Routings.PNRef INNER JOIN ActivityType ON ActivityType.ID=CellManager.ActivityTypeRef INNER JOIN Activity ON Activity.CellManagerRef=CellManager.ID WHERE CellManager.OperatorLogRef=15 Order BY TimeSubmitted
    Exception thrown:
    SEVERE: Application class productionefficiencyviewergui.ProductionEfficiencyViewerGUIApp failed to launch
    Local Exception Stack:
    Exception [TOPLINK-6132] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.QueryException
    Exception Description: Query argument " not found in list of parameters provided during query execution.
    Query: DataReadQuery(){code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • I cant get my youtube account to work on my new apple tv. States the account cant be used or the password and such is wrong. I noticed that after google bought youtube it all became complicated. Tried all trouble shooting, Any ideas?

    States the account cant be used or the password and such is wrong. I noticed that after google bought youtube it all became complicated. Tried all trouble shooting, Any ideas?

    That would indicate an issue with the local network, not internet. This can impact devices differently and will likely be more obvious on a streaming only device.
    If you are on wifi try ethernet
    Make sure DNS is set to auto (settings - general - network)
    Go to istumbler, netstumbler or similar to get a report of the network, look for signal strength and noise.

  • After specifying a DSN, and an sql statement to SELECT data I can run the Complete SQL

    Session VI in the SQL toolkit. The query results return the requested data, and no errors are produced. When I depress the run arrow a second time, I get an illegal operation message and have to shut down Labview. Have you had problems like this before?

    Session VI in the SQL toolkit. The query results return the requested data, and no errors are produced. When I depress the run arrow a second time, I get an illegal operation message and have to shut down Labview. Have you had problems like this before?Hello,
    You may want to see if there is an update for the ODBC driver of the database you are using. Many times, a crash is caused because of a problem with the driver. You may also want to search the NI website for more information (search for +SQL +Sybase for example, if you are using a Sybase database.)
    Good luck!
    Sincerely,
    Darren Nattinger
    Applications Engineer
    National Instruments
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Dividing the SELECT clause to understand

    Hi All,
    I am given a code which has very complicated SELECT clause which I am not able to break in understandable form.
    Its like this:
    for i in (select 'select ROWIDTOCHAR(rowid) rid, studyid, '''||db_link||''' db_link, rowid || '':'' || studyid || '':'' || '''||db_link||''' as text from consolidated.cp_queue_tbl'||decode(db_link,null,null,'@'|| db_link|| ' where process_start_time is null') stat from (select distinct db_link from cp_study_metadata_tbl))
    I am not able to understand which are actual column and which are aliases among this. Neither I can understand where oen query ends and other begins.
    Please help
    Aashish S.

    Are you sure that the parenthesis that stands immediatly before "stat" is well placed?
    You're adding the where clause only if selecting through database link, seems strange...
    Maybe it should be
    FOR i IN
    (SELECT 'select ROWIDTOCHAR(rowid) rid, studyid, '''||
             db_link||''' db_link, rowid || '':'' || studyid || '':'' || '''||
             db_link||''' as text from consolidated.cp_queue_tbl'||
             DECODE(db_link,null,null,'@'||db_link)||' where process_start_time is null' stat
    FROM (SELECT DISTINCT db_link
           FROM cp_study_metadata_tbl)
    )Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]

  • SQL statement for selecting multiple partitions

    Hi All,
    May i know how to Select data from a table having multiple partitions ?
    Example : Owner = Scott, Table= Emp, Partitions (P1,P2,P3,P4,P5)
    Thanks

    no...
    SQL>
      1  create table partition_test
      2  (owner, object_name, object_id)
      3  partition by list(owner)
      4  (partition part_1 values ('SYS'),
      5   partition part_2 values ('SYSTEM'),
      6   partition part_3 values ('OUTLN')
      7  ) as select owner, object_name, object_id from all_objects
      8* where owner in ('SYS', 'SYSTEM', 'OUTLN')
      9  /
    Table created.
    SQL> select count(*) from partition_test partition(part_1, part_2);
    select count(*) from partition_test partition(part_1, part_2)
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> select count(*) from partition_test partitions(part_1, part_2);
    select count(*) from partition_test partitions(part_1, part_2)
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> select count(*) from partition_test partitions(part_1 + part_2);
    select count(*) from partition_test partitions(part_1 + part_2)
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> select count(*) from partition_test partitions(part_1 between part_2
    select count(*) from partition_test partitions(part_1 between part_2)
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> select count(*) from partition_test partitions("part_1 part_2");
    select count(*) from partition_test partitions("part_1 part_2")
    ERROR at line 1:
    ORA-00933: SQL command not properly endedand this is the documented behavior:
    "partition_extension_clause
    For PARTITION or SUBPARTITION, specify the name or key value of the partition or subpartition within table from which you want to retrieve data.
    For range- and list-partitioned data, as an alternative to this clause, you can specify a condition in the WHERE clause that restricts the retrieval to one or more partitions of table. Oracle Database will interpret the condition and fetch data from only those partitions. It is not possible to formulate such a WHERE condition for hash-partitioned data."
    from:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_10002.htm#i2076542
    Amiel

  • Calling a function in the select clause.

    I am using Oracle 11g.
    I am trying to write a query like this
    select name,age, sal, avg = avg_salary(age)
    from customer
    where sal >= avg;
    However, I am not able to do so. What the query is trying to do is print the name, age and salary of every customer as well as the average salary for the customer's age where the customer's salary is greater than the average salary for his age.
    Please help. Thanks.

    Hi,
    The way to assign a column alias is to put the alais after the expression. It makes your code clearer if you put the keyword AS after the expression and before the alias, but this is not required.
    SELECT     name
    ,     age
    ,     sal
    ,     avg_salary (age)     AS avg_salary_age
    FROM     customer
    WHERE     sal     >= avg_salary (age)
    ;You can't reference a column alais in the same query where it is defined (except in an ORDER BY clause). If you want to reference the alias anywhere else (e.g., in the WHERE clause) you have to define it in a sub-query; then you can use it anywhere you want in the super-query, liek this:
    WITH     got_avg_salary_age     AS
         SELECT     name
         ,     age
         ,     sal
         ,     avg_salary (age)     AS avg_salary_age
         FROM     customer
    SELECT     *
    FROM     got_avg_salary_age
    WHERE     sal     >= avg_salary_age
    ;Since AVG is the name of a built-in function, there could be problems using it as a column alias. You could call it average, if you don't like avg_salary_age.

  • SQL*LOADER, the WHEN clause and WILDCARDS

    has anybody ever used wildcards in a WHEN clause in the SQL*LOADER control file?
    WHEN string_2_load = 'GOOD' , all 'good' rows load
    WHEN string_2_load = 'GO%', all rows fail the WHEN clause and end up in the discard file.
    thanks in advance - if i don't go crazy first
    burt

    I have also faced a similar problem like this. Try this control file
    LOAD DATA
    INFILE 'DATA.dat'
    BADFILE 'MLIMA.bad'
    INTO TABLE Brok_Gl_Interface
    APPEND
    WHEN record_type = '10'
    FIELDS TERMINATED BY ","
    OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    record_type CHAR ,
    currency CHAR ,
    entity CHAR ,
    cost_centre CHAR ,
    usd_account CHAR ,
    amount CHAR
    INTO TABLE Brok_Gl_Interface
    WHEN record_type = '99'
    FIELDS TERMINATED BY ","
    OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    record_type POSITION(1) CHAR ,
    record_count CHAR
    INTO TABLE Brok_Gl_Interface
    WHEN record_type = '00'
    FIELDS TERMINATED BY ","
    OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    record_type POSITION(1) CHAR,
    run_date CHAR,
    effective_date CHAR
    )Regards,
    Mohana

  • Date comparison in the select clause

    I want to have comparison as if date1 >= date2 then select as 1 or select as 2. This should be in the select clause

    select greatest (date1, date2)
    from table
    ~
    pascal

Maybe you are looking for