Basic SQL question

CREATE TABLE test_table_1
AS
   (    SELECT ROWNUM col
          FROM DUAL
    CONNECT BY ROWNUM <= 10);

CREATE TABLE test_table_2
AS
   (    SELECT ROWNUM col2
          FROM DUAL
    CONNECT BY ROWNUM <= 10);

DELETE FROM test_table_1
      WHERE col IN (SELECT col                      ---------------------- There is no such column called col in test_table_2
                      FROM test_table_2);

10 rows deleted!

COMMIT;

The column inside the subquery has never existed...

SELECT col FROM test_table_2;                                ---  ORA-00904: "COL": invalid identifier

How is it possible that a non-existent column is not followed while the application is being analyzed

Can someone explain this if you please...

Thanks for reading!

Oracle version: 11.2.0.3.0

See you soon,.

Manik.

  1. DELETE FROM test_table_1
  2. WHERE col IN (SELECT col - there is no such column called col in test_table_2
  3. OF test_table_2);

Quite expected behavior.  Cervical in your subquery refers to the same pass in your outer query.

If you called your columns with a table alias (or the name of the entire table if you wish) the error would have been taken:

SQL > DELETE FROM test_table_1 T1

2. WHERE T1.col IN (SELECT T2.col

3 test_table_2 T2);

WHERE T1.col IN (SELECT T2.col

*

ERROR on line 2:

ORA-00904: "T2." "" COL ": invalid identifier

Tags: Database

Similar Questions

  • the basic sql question

    Hi all I have a basic sql question
    Watch below two querries
    1.  select 1 from dual where 1 in (select 1 from dual union all select null from dual) 
    
    It gives output  as 1
    
    but below one 
    
    2.   select 1 from dual where 1 not in  (select 2 from dual union all select null from dual)
    
    It gives output as no data found 
    I think as operator will not compare with all the values, but not the outcome it will compare with all values... When comparing with the value null, the result is automatically null

    I'm wrong
    Please help me on this

    and why performance wise in operator is more better than no of?

    Thanks to all in advance

    Thanks for posting your explain plan command

    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 3249215828
    
    -----------------------------------------------------------------------------
    | Id  | Operation        | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |          |     2 |     6 |     4   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS    |          |     2 |     6 |     4   (0)| 00:00:01 |
    |   2 |   FAST DUAL      |          |     1 |       |     2   (0)| 00:00:01 |
    |   3 |   VIEW           | VW_NSO_1 |     2 |     6 |     2   (0)| 00:00:01 |
    |   4 |    SORT UNIQUE   |          |     2 |       |     2   (0)| 00:00:01 |
    |   5 |     UNION-ALL    |          |       |       |            |          |
    |   6 |      FAST DUAL   |          |     1 |       |     2   (0)| 00:00:01 |
    |*  7 |      FILTER      |          |       |       |            |          |
    |   8 |       FAST DUAL  |          |     1 |       |     2   (0)| 00:00:01 |
    -----------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       7 - filter(NULL IS NOT NULL)
    
    02:12:54 SQL> select 1 from dual where 1 not in  (select 2 from dual union all select null from dual);
    Elapsed: 00:00:00.01
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 3291682568
    
    -----------------------------------------------------------------
    | Id  | Operation        | Name | Rows  | Cost (%CPU)| Time     |
    -----------------------------------------------------------------
    |   0 | SELECT STATEMENT |      |     1 |     4   (0)| 00:00:01 |
    |*  1 |  FILTER          |      |       |            |          |
    |   2 |   FAST DUAL      |      |     1 |     2   (0)| 00:00:01 |
    |   3 |   UNION-ALL      |      |       |            |          |
    |*  4 |    FILTER        |      |       |            |          |
    |   5 |     FAST DUAL    |      |     1 |     2   (0)| 00:00:01 |
    |   6 |    FAST DUAL     |      |     1 |     2   (0)| 00:00:01 |
    -----------------------------------------------------------------
    
  • Apex SQL question - weeks of the month

    I have a sql question.
    I want to create a dynamic list.

    If the user select may2009, then I want a dynamic list of show

    04/27/2009-05/03/2009
    05/04/2009-05/10/2009
    05/11/2009-05/17/2009
    05/18/2009-05/24/2009
    05/25/2009-05/31/2009

    If the user selects Jun 2009, then the list will be
    06/01/2009-06/07/2009
    06/08/2009-06/14/2009
    06/15/2009-06/21/2009
    06/22/2009-06/28/2009
    06/29/2009-07/05/2009

    Thank you.

    Using this SQL statement, you can get this list:

    SELECT w_start || ' - ' || w_end d, w_start r
      FROM (SELECT     (week_start_list + (LEVEL - 1) * 7) + 1 w_start,
                       week_start_list + (LEVEL) * 7 w_end
                  FROM (SELECT TO_CHAR (TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                               'mm'
                                              ),
                                        'IW'
                                       ) week_begin,
                               TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                      'mm'
                                     ) m_begin,
                               TO_CHAR
                                  (TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'), 'mm'),
                                   'd'
                                  ) day_month_begin,
                               TO_CHAR
                                  (TRUNC (ADD_MONTHS (TO_DATE (:my_date,
                                                               'dd.mm.yyyy'
                                                              ),
                                                      1
                                                     ),
                                          'mm'
                                         ),
                                   'IW'
                                  ) week_end,
                               TRUNC (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                                  1
                                                 ),
                                      'mm'
                                     ) m_end,
                               TO_CHAR
                                  (TRUNC (ADD_MONTHS (TO_DATE (:my_date,
                                                               'dd.mm.yyyy'
                                                              ),
                                                      1
                                                     ),
                                          'mm'
                                         ),
                                   'd'
                                  ) day_month_end,
                                 TRUNC (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                        'mm'
                                       )
                               - TO_NUMBER
                                          (TO_CHAR (TRUNC (TO_DATE (:my_date,
                                                                    'dd.mm.yyyy'
                                                                   ),
                                                           'mm'
                                                          ),
                                                    'd'
                                                   )
                                          ) week_start_list,
                                 TRUNC
                                    (ADD_MONTHS (TO_DATE (:my_date, 'dd.mm.yyyy'),
                                                 1
                                                ),
                                     'mm'
                                    )
                               + TO_NUMBER
                                    (TO_CHAR
                                        (TRUNC
                                              (ADD_MONTHS (TO_DATE (:my_date,
                                                                    'dd.mm.yyyy'
                                                                   ),
                                                           1
                                                          ),
                                               'mm'
                                              ),
                                         'd'
                                        )
                                    )
                               - 1 week_end_list
                          FROM DUAL)
            CONNECT BY LEVEL <=
                          (SELECT   TO_NUMBER
                                       (TO_CHAR
                                           (TRUNC
                                               (ADD_MONTHS (TO_DATE (:my_date,
                                                                     'dd.mm.yyyy'
                                                                    ),
                                                            1
                                                           ),
                                                'mm'
                                               ),
                                            'IW'
                                           )
                                       )
                                  - TO_NUMBER
                                          (TO_CHAR (TRUNC (TO_DATE (:my_date,
                                                                    'dd.mm.yyyy'
                                                                   ),
                                                           'mm'
                                                          ),
                                                    'IW'
                                                   )
                                          )
                             FROM DUAL))
    

    It is a question of SQL and has nothing to do with the Apex.

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    -------------------------------------------------------------------

  • SQL question on natural joins

    I am a newbie to SQL and I studied the book of Fundamentals SQL Server Oracle OCA 12 c, but a section on natural joins to confuse me.

    Basically, the author says:

    SELECT r.region_name, d.department_name, l.city, c.country_name

    DEPARTMENTS d

    NATURAL JOIN places l, c countries, regions r;

    The natural join between DEPARTMENTS and LOCATIONS creates a provisional result, consisting of 27 lines since they are implicitly attached on the column of location_id. This set is then Cartesian-joined to the table of the COUNTRY as a join condition is not implicitly or explicitly specified. 27 interim lines are attached to 25 lines in the COUNTRY table, which gives a new temp results set with 675 (27 × 25) rows and three columns: DEPARTMENT_NAME, CITY and COUNTRY_NAME. This set is then attached to the REGION table. Once more, a Cartesian join occurs because column REGION_ID is absent from any join condition. The final result set contains rows and four columns (675 × 4) 2700.

    I can understand because you evaluate joins from the left. But then he wrote:

    The JOIN... USE and JOIN... ON the syntaxes are better suited to join multiple tables. The following query joins four tables using the natural join syntax:

    SELECT country_id region_id, c.country_name, l.city, d.department_name

    DEPARTMENTS d

    NATURAL JOIN places l

    NATURAL JOIN country c

    NATURAL JOIN region r;

    This query generates correctly 27 lines in the final results set since the required join columns are listed in the SELECT clause. The following query illustrates how the JOIN... CLAUSE is used to extract the same 27 lines. A join condition can reference columns only in its scope. In the following example, the join of DEPARTMENTS slots can not reference columns in the COUNTRIES or REGIONS of tables, but the join between the COUNTRIES and REGIONS may refer to any column of four tables involved in the query.

    This second method of the part of the natural writing joined confuses me. I don't understand the logic behind the 2nd series of States of Natural Join. For me, it seems that the first series and the 2nd set look alike, but they are apparently not.

    Can someone tell me the differences?

    Thank you!!

    Hello

    The more important thing to learn more about NATURAL JOIN is: never use it.  If you add new columns, joins can get different results.  I've never heard of someone uisng NATURAL JOIN apart from a manual or a question like yours.

    There are a lot of things in Oracle that take the time to learn and are useful.  All the time you spend learning things is better spent on them.

  • What kind of pl sql questions can you expect for a customer technical interview

    Please notify all experienced professionals

    What kind of questions can I expect in the customer facing interview technical I have to a PL SQL Developer with interview of performance tuning. The customer is primarily a financial project.

    Yes of course I would essentially tell me about the projects that you been involved in based on who they ask the questions, basically I'm not very experienced 3 years and my experience involves performance limited tuning, to develop scripts to support front-end web applications.

    What kind of questions (you do not need to enumerate the issues specifically, it would be useful that you could advise the areas where I should look into, all the links where I can read about the region suggest you also face a customer interview).
    Example: Financial transaction processes much as treatment so I have to prepare for any question on the changing Table, blocking.
    Also, I am aware of the Collections, external Tables. These would be discussed.

    Any advice would be very helpful.
    My experience does not imply strongly any financial experience and job specification does not state so I got through the 2 first interview series. It would be a disadvantage if I said that I have had no experience of finanicial, I guess just by hearing from some sources that the customer is finance.
    I would be hired only if the customer agrees, so I need to deepen as much as possible, it's time to prepare for good trying to inform.

    Kind regards.

    Rider wrote:

    My experience does not imply strongly any financial experience and job specification does not state so I got through the 2 first interview series. It would be a disadvantage if I said that I have had no experience of finanicial, I guess just by hearing from some sources that the customer is finance.

    Personally, when I interview candidates PL/SQL, the least important thing for me is real business knowledge. I want to rather a competent PL/SQL Developer who knows his stuff, a person having poor skills of PL/SQL and a good knowledge of the company.

    We will pay that person for PL/SQL capabilities - and not knowledge of business (that of why we have analysts and managers of project and team leaders). Remember that the code ' + financial + "is no different code" + detail + "-the same language is used. The same concepts. The same methods to solve problems. As the problems you are dealing with a level of PL/SQL are technical - where business issues have already been processed by analysts and architects at a higher level.

    I expect, however, that such a developer will resume business over time knowledge. But I don't see it as any kind of precondition.

  • Basic PCMCIA question: where is the controller?

    Hello people,

    I have a basic question of the PCMCIA:

    The PCMCIA controller is integrated on the motherboard or does the PCMCIA device?

    Practicality: if I want to change the PCMCIA in a laptop, I can change everything (part mechanical + electronic) or simply the mechanical part?

    I have a mono-emplacement controller, and I would have a dual slot PCMCIA. If the controller is on the motherboard, I have no chance of success.

    Thank you:

    UB

    The controller is on the motherboard. Pcmcia slot unit is removable, as stated above, but it's just a cage to hold the cards... no chip is in it other than a plug-in interface on the motherboard which channels to the pcmcia controller.

  • Search SQL question

    I have install a SQL db in my application and research works really well.  I have the onTextChanged and onTextChanging the value:

    datasource.query = "Select * from items where name like searchtext.text"
    

    I'm basically the database load and charging based on the modification of search text.

    Issue I'm having is that when the user deletes a search term and that the field is empty or when I put the empty search text when he takes the object textfield visible = false.

    After that, every time I try to add or update the database my app hangs.  I tried to define the list of database to refresh / reload on closign the textfield, but that doesn't seem to help.

    Any idea what I can do?

    Found the issue to be a bit more complicated than just my search query.  It ends up being because my list of the index was out of range.  For more information consult the solution in this thread for how I solved it and answers: http://supportforums.blackberry.com/t5/Native-Development/quot-Index-out-of-range-quot-error-on-sear...

  • SQL * PLUS connects with SQL &gt; question

    People,

    I'm confused on the command. / sqlplus with Oracle database.

    According to my understanding,. / sqlplus connected with SQL > using option 3: sysdba, sysoper, sysasm.

    I connect with SQL > to run the rel853.sql script to create a table PSOPRDEFN but a field "OPERPSWDSALT" did not appear in the table PSOPRDEFN although it is in the Create Table statement.

    I connect with SQL * in the directory/home/user/OracleDB_Home/bin as below:


    $ export SYSTEM_PASS = AccessId/mypass

    $ export ORACLE_HOME = / home/user/OracleDB_Home

    $ export ORACLE_SID = HRCS90

    $. / lsnrctl start LISTENER

    $. / AccessId/mypass sqlplus as sysdba

    SQL > startup

    SQL > @/opt/PT8.53/scripts/rel853.sql

    SQL > select OPERPSWDSALT in the AccessId.PSOPRDEFN;

    It returns: "OPERPSWDSALT": invalid identifier.


    I checked the table PSOPRDEFN that the OPERPSWDSALT field did not appear in the table PSOPRDEFN.

    I tried the sysoper option as below:

    $. / sqlplus AccessId/mypass as sysoper

    SQL > startup

    SQL > @/opt/PT8.53/scripts/rel853.sql

    SQL > select OPERPSWDSALT in the AccessId.PSOPRDEFN;

    It returns: "OPERPSWDSALT": invalid identifier.

    The sysoper error is the same thing with sysdba error.

    I tried the sysasm option as below:

    $. / sqlplus AccessId/mypass as sysasm

    He returned: connection refused.


    Someone told me this connection as SYS causes this error. If not a sysdba, sysoper, or sysasm, use the command. / sqlplus AccessId/mypass cannot connect with SQL >.


    My question is:


    First of all, why is what OPERPSWDSALT did not appear in the PSOPRDEFN table while it is in the CREATE TABLE statement?


    Seocond, if not use SYS which is one of the 3 options, how to run the command. / sqlplus AccessId/mypass to connect with SQL > so that CREATE TABLE PSOPRDEFN correctly?

    Thank you.

    user8860348 wrote:

    People,

    Hello. Thanks much for the reply. I just do the commands below:

    $ export SYSTEM_PASS = AccessId/mypass

    $ export ORACLE_HOME = / home/user/OracleDB_Home

    $ export ORACLE_SID = HRCS90

    $. / lsnrctl start LISTENER

    $. / AccessId/mypass sqlplus as sysdba

    SQL > show user;

    Its release: the USER is "SYS".

    SQL > connect AccessId/mypass

    Its output:

    Error: ORA - 01034:ORACLE not available

    ORA-27101: shared memory realm does not exist

    64 - Linux_x86 error: no such file or directory.

    As we see above, unable to connect to the Oracle database AccessId.

    My question is:

    What to do on AccessId, so that it can connect to the Oracle database?

    Thank you.

    so much for the use that you refuse to actually use COPY it PASTE & so that we can see the whole session.

    In the past, you did

    > SQL > startup

    Maybe the database is out of order & must be started.

    do exactly as below (line by line)

    ID

    sqlplus

    / as sysdba

    startup

    connect AccessId/mypass

    COPY the results from above then PASTE all back here

  • Classic basic SQL report - how to disable the account to record down

    Hello

    I've created a report (type: report classic, based on sql)... basically, it shows the record number (1-3)... y at - there a way to disable

    Thanks in advance

    Hello

    There is a section in the report attributes, layout and Pagination. Set to - no enabled paging-paging system

    Concerning
    André

  • running of SQL question

    Hi expert,


    When I ran after SQL, error message reads "table or view does not exist" pointing to the table "dba_tab_cols" and "dba_all_tables". There is no other question for this statement, because if I changed table "user_tab_cols" and "user_all_tables", it works well.


    declare
    v_old_table DBA_tab_columns.table_name%type;
    v_where Varchar2 (4000);
    Boolean v_first_col: = true;
    type rc is ref cursor;
    c rc;
    v_rowid varchar2 (20);
    Val varchar2 (50): = "Test note";

    Start
    for r in)
    Select
    t.*
    Of
    dba_tab_cols t, dba_all_tables a
    where t.table_name = a.table_name
    and t.data_type like '% CHAR % '.
    and a.owner = 'QA'
    order by t.table_name loop)

    If v_old_table is null then
    v_old_table: = r.table_name;
    end if;

    If v_old_table <>r.table_name then
    v_first_col: = true;

    -dbms_output.put_line ('search' | v_old_table);

    Open c for ' select rowid from ' ' |. ' v_old_table | '" ' || v_where;

    extract the c in v_rowid;
    loop
    When the output c % notfound;
    dbms_output.put_line (' rowid: ' | v_rowid |) "in" | v_old_table);
    extract the c in v_rowid;
    end loop;

    v_old_table: = r.table_name;
    end if;

    If v_first_col then
    v_where: = 'where ' | r.column_name | "as" %' | Val | '%''';
    v_first_col: = false;
    on the other
    v_where: = v_where | "or" | r.column_name | "as" %' | Val | '%''';
    end if;

    end loop;
    end;


    But if I choose these DBA tables in the toad sql Editor, it works well, I am currently using my own credentials, not the administrator credentials. why he get different effects running in these two ways?

    Thank you very much

    >

    Hello

    When I ran after SQL, error message reads "table or view does not exist" pointing to
    Table 'dba_tab_cols' and 'dba_all_tables '. There is no other question for this statement, because

    If I changed table "user_tab_cols" and "user_all_tables", it works well.
    But if I choose these DBA tables in the toad sql Editor, it works well, I am currently using my own
    credentials, not the administrator credentials. why he get different effects running in these two ways?

    You answered your own question - you know that you have the administrator privileges when you
    Open a session under your own credentials - but your id user obviously does TOAD.

    You use SQL * for the query that fails?

    BTW, you do not give us your version of Oracle - you must always tell us what it is

    Please read the forum FAQ and also the thread "sticky" by BluShadow at the top of the list of positions
    on the forum homepage. These forums are an excellent resource - you will get the best out of them if
    you follow the instructions.

    HTH,

    Paul...

    Published by: Paulie July 24, 2012 16:40

  • Basic VMWare question

    Hello, people:

    Please forgive my very basic questions, but I'm totally new to VMWare.

    Yes, as a R & S Cisco engineer, I worked with server

    specialists to get their online environments, but my focus was on the

    network component, from the access layer.

    Anyway, when you create a virtual machine and associate a request,

    This virtual machine has an IP address assigned to its own vNIC?  So, if it

    5 virtual machines run on a physical server, the number of addresses IP are you going

    have? How the allocation of an IP address of the physical NETWORK adapter is bound to the

    others?

    Once again, thank you for your help in advance.

    Take a look at the document I linked in the previous post.

    The virtual network is based on vSwitch which are "dummy" brigde.

    So has each VM's own MAC address (which is virtual and the part of the seller is dedicated to VMware).

    A physical NETWORK card is simply an uplink to the physical switch and the physical MAC address is generally not used and not visible in your network traffic or your ARP table (think a unmaged switch, it can have a MAC address, but you don't see it on your network).

    When you have several (more than one bear on a vSwitch) uplink you can have different types of team policy.

    (For you is probably the simplest to understand) is like the etherchannel on Cisco switches (and it takes a good configuration of the physical switch).

    André

  • SQL question to get a top customer of the page

    Hi all
    I'm prasanna. I have a question about SQL, to get a customer based on name of the year and the customer. I wrote the request like this. But I got an error.

    Select calendar_year, cust_first_name, max (sum (amount_sold)) in sale, the time the customers where sales.cust_id = customers.cust_id and times.time_id = sales.time_id of the calendar_year group, cust_first_name

    The error is like this:

    * Error from the 1 in the command line:
    Select calendar_year, cust_first_name, max (sum (amount_sold)) in sale, the time the customers where sales.cust_id = customers.cust_id and times.time_id = sales.time_id of the calendar_year group, cust_first_name
    Error in the command line: 1 column: 7
    Error report:
    SQL error: ORA-00937: not a function of simple-group
    00937 00000 - 'not a single-group function. "
    * Cause:
    Action:

    Thank you inadvace
    Kind regards
    Prasanna

    865016 wrote:
    Your response, I had only one top customer with year, name of the client, amount_sold. But I need for each year

    select  calendar_year,
            cust_first_name,
            total_amount_sold max_amount_sold
      from  (
             select  calendar_year,
                     cust_first_name,
                     sum(amount_sold) total_amount_sold,
                     row_number() over(partition by calendar_year order by sum(amount_sold) desc) rn
               from  sales,
                     times,
                     customers
               where sales.cust_id=customers.cust_id
                 and times.time_id=sales.time_id
               group by calendar_year,
                     cust_first_name
            )
      where rn = 1
    / 
    

    I will give you a single customer by calendar_year.

    SY.

  • SQL question for a beginner...

    I have the following structure:

    NUMBER OF PROCESSING_ITEM_ID
    NUMBER OF PROJECT_ITEM_FK
    START_TIME DATE
    END_TIME DATE
    NUMBER OF WORKSTATION_FK

    examples of data

    81,23,10-27-2010 08:00, 27/10/2010 10:00, 3
    42,1,10-27-2010 08:00, 27/10/2010 11:00, 1
    22,23,10-27-2010 13:00, 27/10/2010 17:00, 2
    1,23,10-27-2010 15:00, 27/10/2010 16:00, 1
    23,23,10-27-2010 17:00, 27/10/2010 20:00, 2

    I'm trying to divide the data into lines of an hour. If this line we would be divided into:

    81,23,10-27-2010 08:00, 27/10/2010 09:00, 3
    81,23,10-27-2010 09:00, 27/10/2010 10:00, 3

    third row would be divided into:

    22,23,10-27-2010 13:00, 27/10/2010 14:00, 2
    22,23,10-27-2010 14:00, 27/10/2010 15:00, 2
    22,23,10-27-2010 15:00, 27/10/2010 16:00, 2
    22,23,10-27-2010 16:00, 27/10/2010 17:00, 2

    The statement that is made should display the data in this way...

    John Brewer
    City of Seattle

    Question delicate John, you should ask this in the SQL forums

    This is the query

    with temp AS
         (
          SELECT 81 PROCESSING_ITEM_ID,23 PROJECT_ITEM_FK,TO_DATE('10-27-2010 08:00','MM-DD-YYYY HH24:MI') start_date,TO_DATE('10-27-2010 10:00','MM-DD-YYYY HH24:MI') end_date,3 WORKSTATION_FK from dual
          UNION ALL
          SELECT 22 PROCESSING_ITEM_ID,23 PROJECT_ITEM_FK,TO_DATE('10-27-2010 13:00','MM-DD-YYYY HH24:MI') start_date,TO_DATE('10-27-2010 17:00','MM-DD-YYYY HH24:MI') end_date,2 WORKSTATION_FK from dual
          )
        ,time_span AS
        (
         SELECT MAX( TO_NUMBER(TO_CHAR(end_date,'HH24')) - TO_NUMBER(TO_CHAR(start_date,'HH24')) ) TIME_SPAN
         FROM temp
        )
        ,time_period_rows AS
       (
        SELECT level-1 PERIOD FROM time_span connect by level <= TIME_SPAN
       )
    SELECT T.PROCESSING_ITEM_ID,T.PROJECT_ITEM_FK,TO_CHAR(T.start_date+TR.PERIOD/24,'MM-DD-YYYY HH24:MI') start_time,TO_CHAR(T.start_date+(TR.PERIOD+1)/24,'MM-DD-YYYY HH24:MI') end_time ,T.WORKSTATION_FK
    FROM  temp T
         ,time_period_rows TR
    WHERE PERIOD <= TO_NUMBER(TO_CHAR(end_date,'HH24')) - TO_NUMBER(TO_CHAR(start_date,'HH24'))
    ORDER BY T.PROCESSING_ITEM_ID,TR.PERIOD
    

    Output

    PROCESSING_ITEM_ID     PROJECT_ITEM_FK     START_TIME     END_TIME     WORKSTATION_FK
    22     23     10-27-2010 13:00     10-27-2010 14:00     2
    22     23     10-27-2010 14:00     10-27-2010 15:00     2
    22     23     10-27-2010 15:00     10-27-2010 16:00     2
    22     23     10-27-2010 16:00     10-27-2010 17:00     2
    81     23     10-27-2010 08:00     10-27-2010 09:00     3
    81     23     10-27-2010 09:00     10-27-2010 10:00     3
    81     23     10-27-2010 10:00     10-27-2010 11:00     3
    

    I used a view inline as data source ( temp ), you can change this to your table, name (then remove the display online)

  • Sql question judging

    Sorry guys, didn't know where otherwise put this hope so much he is allowed to post here. I currently have a field in my database that stores the date and time, however, I write a statemenet sql and need to use only the date of the datetime object, which would be the correct syntext to sowould I should use to_char etc.?

    Thank you.

    Not a question of forms, but a database.

    But check this for format masks: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements004.htm

  • Newbie SQL question

    I'm new to the database and have a basic question.

    I have a table 'A' with the following contents:

    Description of the ID
    1 AR
    1 FS
    2 FS


    I want to write a query that would provide IDS that match the Description "FS" and not "AR" in any other line (for the same id).

    So the results would look like
    Description of the ID
    2 FS

    Any help would be appreciated.
    select *
    from   a outa
    where not exists
    (select 'x'
    from  a inna
    where inna.id = outa.id
    and    inna.description = 'AR')
    

Maybe you are looking for