How to reach below result in Oracle SQL

Hi all

How to get the result below:


database table:
COLA, COLB
112 1ST JANUARY 2012
113 FEBRUARY 2, 2012
114 MARCH 2, 2013
115 APRIL 1, 2013



Result table:


COLA, COLB TEACHERS
112. ON 1 JANUARY 2012 FEBRUARY 1, 2012
113 2 FEBRUARY 2012 1 MARCH 2012
114 2 MARCH 2013 MARCH 31, 2013
115 1ST APRIL 2013 APRIL 2, 2013

Thank you!

Spleen the last row... it's probably more like...

select cola, colb, nvl(lead(colb) over (order by cola)-1,colb+1) as colc
from basetable
order by cola

Tags: Database

Similar Questions

  • How to solve the problem of Oracle SQL Developer Connection?

    People,

    Hello. I use the Oracle 11 GR 1 material database. The database https://localhost.localdomain:1158 control console / em works correctly. I can create a database and a table with success.

    My OS is Linux and connects to the internet successfully.

    In order to execute SQL statements. We use Oracle SQL Developer. I connect Oracle SQL Developer in the following way:

    Connection name: DB1 (is my database name)
    User name: SYS (this is the user name I used to connect to the Console)
    Password: SYS (this is the password used to connect to the Console)
    Connection type: basic
    Host name: localhost
    Port: 1158
    SID: DB1 (it is created during the installation of the database)

    But the error message: "status: failed - IO exception Connection Reset."

    Can any folk tell me how to solve the problem of Oracle SQL Developer Connection?

    user8860348 wrote:
    People,

    Hello. I use the Oracle 11 GR 1 material database. database Control Panel https://localhost.localdomain:1158 / em works correctly. I can create a database and a table with success.

    My OS is Linux and connects to the internet successfully.

    In order to execute SQL statements. We use Oracle SQL Developer. I connect Oracle SQL Developer in the following way:

    Connection name: DB1 (is my database name)
    User name: SYS (this is the user name I used to connect to the Console)
    Password: SYS (this is the password used to connect to the Console)
    Connection type: basic
    Host name: localhost
    Port: 1158
    SID: DB1 (it is created during the installation of the database)

    But the error message: "status: failed - IO exception Connection Reset."

    Can any folk tell me how to solve the problem of Oracle SQL Developer Connection?

    user name: sys
    password: enter_your_correct_password given at the time of the installation of oracle

    role: select sysdba if you would connect as sysdba otherwise select normal for users other than the sys

    HostName: Enter your ip or hostname of the oracle example server address:-192.168.11.12

    to find the terminal/command prompt open hostname in oracle installed machine
    type---> hostname

    type ping hostname--->

    You can find the IP address of the server

    Port number: 1521 (default)---> I guess, otherwise check the port number in the file tnsnames.ora under your ORACLE_HOME/network/admin folder

    SID: DB1

    try it
    Good luck

  • How to write the result of a SQL query to a text file?

    I'm using Oracle 11 g and SQL Plus.

    I have a large table called side.

    Whenever I do


    SQL > select * rating.

    The output goes well beyond what can show the screen sqlplus. So, I want to store the result of this query in a text file.

    How is that possible? Help, please. Thank you.

    SQL > SPOOL results.txt
    SQL > select * rating.
    SQL > SPOOL OFF

  • How can I propose extensions to Oracle SQL / Oracle DBMS?

    Hallo

    Is there a standard process to offer extensions to the Oracle database?

    I waited for some extensions for Oracle 8 I consider as very useful and quite easy to implement compared to others who have found their way into the product. I want to put them in some sort of base of the proposal. How can I do?

    These are the extensions:

    (1) comparison of Tuple according to the lexicographic order

    Imagine a table of SALES (product_id, year, quarter, amount).

    I like question all sales of the third quarter of 2008 to the second quarter of 2009 as this:
    select *
      from sales
     where (year, quarter) >= (2008, 3)
       and (year, quarter) <= (2009, 2)
    and even
    select *
      from sales
     where (year, quarter) between (2008, 3) and (2009, 2)
    Clues are lexicographically ordered, these conditions must be easily supported by the database. If there is an index on the SALES (year, quarter), it will be easy to make a simple index range scan here.

    Note that the notation of tuple is not completely new. I can write something like
    select *
      from sales
     where (year, quarter) in (select year, quarter from some_table)
    These days, you should not set a table in the way we did above. You must set a date column year_quarter and represent each quarter - Let's say - from his first day, which is the third quarter of 2008 by July 1, 2008.
    You might even guarantee this by a check constraint 'year_quarter = (year_quarter, 'q'). The above query must be written:
    select *
      from sales
     where year_quarter between date '2008-07-01' and date '2009-04-01'
    But it's still heavy.

    If you always set a table in the way that I did at the beginning, you will end up using index based on a function on phrases such as "year * 10 + quarter" in support of these "intuitive" such as queries
    select *
      from sales
     where year * 10 + quarter between 20083 and 20092
    But imagine you want in 2008 and all you have is this a function-based index:
    select *
      from sales
     where year = 2008
    The index based on a function on SALES (year * 10 + quarter) does not help. You can write:
    select *
      from sales
     where year * 10 + quarter between 20081 and 20084
    But it's not really practical.

    The extension project allows you to query both a given year (Beach) and a specific range of quarter, effectively using the same index defined on (year, quarter).


    (2) comparison operators that deal with NULL as a normal value

    If you need to compare two columns and treat NULL values as a normal value, you need to write something like "(t1.a = t2.a ou (t1.a est null et t2.a est null)"): "
    select *
      from tab1 t1
     where not exists (
             select *
               from tab2 t2
              where (t1.a = t2.a or (t1.a is null and t2.a is null)
                and (t1.b = t2.b or (t1.b is null and t2.b is null)
           )
    It would be much easier to read and certainly much easier to optimize by the optimizer if there is an equality operator 'is' which deals with NULL as a normal value.
    select *
      from tab1 t1
     where not exists (
             select *
               from tab2 t2
              where (t1.a == t2.a
                and (t1.b == t2.b
           )
    You can even ask the same idea to >, > =, <, < = and allow such tags only 'with null max"and" min null ":
    select *
      from tab
     where x <= 7000 with null min
       and y >= 10 with null max
    null <= null with null max --> true
    null <= 1 with null max --> false;
    1 <= null with null max --> true
    1 <= 2 with null max --> true
    (3) new aggregate function to indicate that one value is expected

    Imagine there is an aggregate function called unique (...) which takes all values and checks if they are identical. If so, this single value is returned. Otherwise, an exception SQL ORA-# is raised.

    When you use the group by clauses and functionally dependent columns, you write queries as follows.
    Imagine that you have a CONTRACT table (contract_id, contract_owner_id,...) and a CONTRACT_DETAIL table (contract_detail_id, contract_id,...).
    You want to select all contracts and for each contract its owner and the number of the contract details. With 'unique', you can write:
    select c.contract_id
         , unique(c.contract_owner_id)
         , count(*) detail_cnt
      from contract c, contract_detail cd
     where c.contract_id = cd.contract_id
     group by c.contract_id
    Today, I write either
    select c.contract_id
         , max(c.contract_owner_id) -- functionally dependant on c.contract_id
         , count(*) detail_cnt
      from contract c, contract_detail cd
     where c.contract_id = cd.contract_id
     group by c.contract_id
    or
    select c.contract_id, c.contract_owner_id, count(*) detail_cnt
      from contract c, contract_detail cd
     where c.contract_id = cd.contract_id
     group by c.contract_id
            , c.contract_owner_id -- functionally dependant on c.contract_id
    Both have drawback that I need to use a comment to describe what is happening. And worse, if my assumption was wrong, the database fails with an error and doesn't force me to rethink things.

    Another use of unique (...) is in combination with analytical functions.
    For example, when I use «aggr (...)» keep (dense_rank first/last seen by...) ", in most cases, the order by clause defines a unique first or last line."
    In these cases, the aggregate function "aggr (...)" is of no real use.

    Imagine a time-stamped time table PROJECT_STATUS with the 'no temporal primary key' project and the TS timestamp column.
    Technically, (project, ts) is a unique key of the table. So, there is always only one line with the maximum timestamp TS.
    I want to choose the status ID of all projects. I can write:
    select ps.project_id
         , max(status) keep (
            dense_rank last order by  ts
           ) as status
      from project_status ps
      group by ps.project_id
    I can use 'min' instead of 'max' with the same result. Using 'unique' instead not wrongly suggests that a maximum or minimum is selected but would be only a mathematical expectation is chosen has established:
    select ps.project_id
         , unique(status) keep (
            dense_rank last order by  ts
           ) as status
      from project_status ps
      group by ps.project_id
    We have two variants of "unique":

    (1) normal 'single (x)' treats NULL as a value. Thus, it would be illegal if there were a few lines with x = NULL and a few lines with x = 5.

    (2) "single (x ignores nulls)" ignores all values null (similar to "last_value(... ignore nulls) (...)") and is less strict because x must be unique for all non-null values. He allows that x has the value NULL for some lines and 5 for the other. In this case, it returns 5.

    You open a session request for improvement through Metalink.

    The procedure is documented in Metalink document 166650.1 as follows:

    How to connect to an enhancement request:

    Create a new Service request in MetaLink.
    In creating an SR - brief Description screen, in the problem field Type, select request for development.
    Important factors to remember when to complete the Service request model requires development and create demand for services:
    Fully describe why the current functionality of product does not satisfy your needs.
    Explain in detail building wanted implemented
    If possible, describe how the product can be changed to achieve the desired results.
    Describe your expectations of the company. The dates of the step key and justifications as to why this request is so important and the benefits that your organization has everything to gain if it takes will be accepted.
    Once your Service request has been created, it will be assigned to a Support engineer who will validate your information. In some cases, your application may be a defect in the product new or known that the technical support engineer may provide a fix, workaround, or adopt Oracle development for resolution. In other cases, you can present a valuable product enhancement that can improve the functionality of the Oracle product. In all cases, the Support Engineer will be able to qualify your application and pass the information to the development of the Oracle.
    Once the technical support engineer validates your request and agreement on action plan is created, your Support Engineer will create a new development application and you provide with a request to improve tracking number. The research on MetaLink BUG tool then receive updates status.
    Please note that the technical support engineer will end the SR once the improvement was noted.

    In addition, see the document 214168.1

  • Ask... How to reach the result sets in order?

    Let me give a few examples of data first to give an idea of what I am working with:

    Oracle: 10g
    --Table xTable
    
    NAME             DESC_ID
    ALAN                   2 
    AMY                    3
    BILL                    5
    BOB                     7
    CARL                   1
    CHRIS                  8
    DAN                    4
    DEREK                 6  
    So what I try to do is right out of names (ALAN, CHRIS, DAN) in ascending order (according to out of name) and then all the names (AMY, BILL, BOB, CARL, DEREK) in ascending order (according to out name)... and I want all of this in a single result set. So basically the first set of names in alphabetical order, followed by the rest of the names in alphabetical order.

    I want the output to look exactly like this:
    NAME       DESC_ID     
    ALAN               2
    CHRIS                8
    DAN                  4
    AMY                  3
    BILL                   5
    BOB                    7  
    CARL                  1
    DEREK                6  
    I tried the following, but it doesn't seem to work
    select distinct a.name, a.desc_id
    from xTable,
    (select distinct name, desc_id
    from xTable
    where DESC_ID  in (2,8,4)
    order by name
    ) type1,
    (select distinct name, desc_id
    from xTable
    where DESC_ID  in (1,3,5,6,7)
    order by name
    ) type2
    where desc_id in (type1, type2);
    The code above seems terribley unefficent and apparently not at the exit of the things in the order I want. Any ideas?

    Published by: user652714 on January 5, 2010 11:23

    Published by: user652714 on January 5, 2010 11:28

    If you have a known list of DESC_ID you could do something like this:

    SQL> WITH xTable AS
      2  (
      3          SELECT 'ALAN'   AS NAME, 1 AS TYPE_ID, 2 AS DESC_ID FROM DUAL UNION ALL
      4          SELECT 'AMY'    AS NAME, 2 AS TYPE_ID, 3 AS DESC_ID FROM DUAL UNION ALL
      5          SELECT 'BILL'   AS NAME, 2 AS TYPE_ID, 5 AS DESC_ID FROM DUAL UNION ALL
      6          SELECT 'BOB'    AS NAME, 2 AS TYPE_ID, 7 AS DESC_ID FROM DUAL UNION ALL
      7          SELECT 'CARL'   AS NAME, 2 AS TYPE_ID, 1 AS DESC_ID FROM DUAL UNION ALL
      8          SELECT 'CHRIS'  AS NAME, 1 AS TYPE_ID, 8 AS DESC_ID FROM DUAL UNION ALL
      9          SELECT 'DAN'    AS NAME, 1 AS TYPE_ID, 4 AS DESC_ID FROM DUAL UNION ALL
     10          SELECT 'DEREK'  AS NAME, 2 AS TYPE_ID, 6 AS DESC_ID FROM DUAL
     11  )
     12  SELECT  NAME
     13  ,       DESC_ID
     14  FROM    xTable
     15  ORDER BY
     16          (CASE
     17                  WHEN DESC_ID IN (2,8,4)         THEN 1
     18                  WHEN DESC_ID IN (1,3,5,6,7)     THEN 2
     19          END)
     20  ,       1
     21  /
    
    NAME               DESC_ID
    ----- --------------------
    ALAN                     2
    CHRIS                    8
    DAN                      4
    AMY                      3
    BILL                     5
    BOB                      7
    CARL                     1
    DEREK                    6
    
    8 rows selected.
    

    Another option would be to use the UNION, but he strikes the table twice instead of once as described above:

    SQL> WITH xTable AS
      2  (
      3          SELECT 'ALAN'   AS NAME, 1 AS TYPE_ID, 2 AS DESC_ID FROM DUAL UNION ALL
      4          SELECT 'AMY'    AS NAME, 2 AS TYPE_ID, 3 AS DESC_ID FROM DUAL UNION ALL
      5          SELECT 'BILL'   AS NAME, 2 AS TYPE_ID, 5 AS DESC_ID FROM DUAL UNION ALL
      6          SELECT 'BOB'    AS NAME, 2 AS TYPE_ID, 7 AS DESC_ID FROM DUAL UNION ALL
      7          SELECT 'CARL'   AS NAME, 2 AS TYPE_ID, 1 AS DESC_ID FROM DUAL UNION ALL
      8          SELECT 'CHRIS'  AS NAME, 1 AS TYPE_ID, 8 AS DESC_ID FROM DUAL UNION ALL
      9          SELECT 'DAN'    AS NAME, 1 AS TYPE_ID, 4 AS DESC_ID FROM DUAL UNION ALL
     10          SELECT 'DEREK'  AS NAME, 2 AS TYPE_ID, 6 AS DESC_ID FROM DUAL
     11  )
     12  SELECT  NAME
     13  ,       DESC_ID
     14  FROM
     15  (
     16          SELECT  NAME
     17          ,       DESC_ID
     18          ,       1 AS ORD_COL
     19          FROM    xTable
     20          WHERE   DESC_ID IN (2,8,4)
     21          UNION
     22          SELECT  NAME
     23          ,       DESC_ID
     24          ,       2 AS ORD_COL
     25          FROM    xTable
     26          WHERE   DESC_ID IN (1,3,5,6,7)
     27  )
     28  ORDER BY ORD_COL
     29  ,       NAME
     30  /
    
    NAME               DESC_ID
    ----- --------------------
    ALAN                     2
    CHRIS                    8
    DAN                      4
    AMY                      3
    BILL                     5
    BOB                      7
    CARL                     1
    DEREK                    6
    
    8 rows selected.
    
  • How to export the result of the SQL via automation like ksh file

    Hello
    I did a query sql statement, this sql file will be called using the ksh file.
    As soon as the ksh is double clicked, the sql will be called and executed on the database.

    Here is my file KSH syntax.

    sqlplus-s user/pass@database < < END
    @D:/sql/export.sql
    OUTPUT
    END

    We want to automate the generation of output result. Such that, when the ksh files are completed, the output from the export.sql will export a .csv or .dat file in the directory defined. Thus, automation is launched without having to manually export in the Toad for sql.

    Please let me know if this is possible? and give an example of the syntax to use? If not, let me know what corrective measures would be to achieve this? Thank you very much for your help.

    Published by: user10070712 on November 20, 2012 03:39
    set colsep ','
    set heading off
    set feedback off
    spool /tmp/result1.csv
    select * from table;
    spool off
    
    set heading off
    set feedback off
    spool /tmp/result2.csv
    select column1 || ',' || column2 || ',' || column3 ... from table;
    spool off
    
  • How to break the line in Oracle SQL?

    Hi all

    I have a long text with the value separated by commas. I'm storing this in a single table custom as it is. But I want that store with the next line, I mean split the comma separated line and insert in the table with the following line table or the character of new line.

    For example: my long text is A, B, C, D, E, F

    I need to insert as below in the table.
    A
    B
    C
    D
    E
    F

    Hello

    Can't you just use REPLACE to change all commas in the line breaks?

    INSERT INTO table_b
    (       txt
    ,      ...
    )
    SELECT  REPLACE ( txt
                    , ','
                    , CHR (10)   -- or whatever it is on your system
                    )
    ,       ...
    FROM    table_a;
    
  • How to modify data in "Result grid query" in Oracle SQL developer

    Dear,

    I would like to know how to change values directly in the query result grid.

    I use Oracle SQL Developer version 4.0.3.16

    Thank you

    Khalil

    EditValues.JPG

    I checked in SQL Developer 4 and I found no option to do this.

    I don't think it's available. You can open the table and add filters on each column and change. Or you can add where clause as suggested the link written by Jeff that I already gave. (http://www.thatjeffsmith.com/archive/2013/06/sql-developer-im-looking-at-a-record-how-do-i-edit-it/)

    Or you write update instructions.

    See you soon

    AJ

  • How to create a planner oracle sql developer

    Hello

    How to create developer oracle sql Scheduler created?

    Hello

    Finally, I refer link below its helpful

    ORACLE-BASE - Support SQL Developer 3.1 Scheduler (DBMS_SCHEDULER)

  • How to change the password of a schema by using Oracle SQL Developer

    Hi need to change the password of a schema by using Oracle SQL Developer, how can I do?

    or maybe http://www.thatjeffsmith.com/archive/2012/11/resetting-your-oracle-user-password-with-sql-developer/

  • Number displayed in the oracle.sql.NUMBER form in the result of the query

    Developer SQL version 3.2.10.09.57 displays numbers like "oracle.sql.NUMBER@66a35419 (the part after @ is not constant and change each time) even for simple count (*) select double."
    At the same time "run the Script (F5)" no indication that the header
    COUNT (*)
    ------------
    and no the query results.

    Hi Andriy,

    The forum search, I see a similar complaint noted against 3.1.07.42. Instruction execution produces the list oracle.sql.NUMBER, probably because of a corrupt installation query results (due to decompress questions, or perhaps no decompression in an empty directory). See the following thread:
    SQLDev 3.1: Number-fields in the tables have "oracle.sql.NUMBER @...". »

    Hope this helps,
    Gary
    SQL development team

  • How to display the output of PL/SQL and difficulty package below error (please help)

    -PACKAGE SPECIFICATION AND met with success, but I see no way out, an error is also here... Please help. How do I solve this problem
    -with the code

    CREATE OR REPLACE PACKAGE package_variables
    -Declare the components of a package.
    Established PROCEDURE (VARCHAR2 value);
    Public FUNCTION get RETURN VARCHAR2;
    END package_variables;
    /



    CREATE OR REPLACE PACKAGE BODY package_variables
    -Declare the package-scoped variable.
    variable VARCHAR2 (20): = "initial value";
    -Define the function
    Get function RETURN VARCHAR2 IS
    BEGIN
    RETURN variable;
    END get;
    -Define the procedure.
    PROCEDURE set(value VARCHAR2) IS
    BEGIN
    variable: = value;
    The END value;
    END package_variables;
    /



    Result VARIABLE VARCHAR2 (20)
    CALL package_variables.get () IN: result;
    SELECT: result AS result FROM dual;


    RUN package_variables.set ("new value '");
    CALL package_variables.get () IN: result;
    SELECT: result AS result FROM dual;

    /*

    OUTPUT


    PACKAGE compiled package_variables.
    PACKAGE compiled package_variables BODY.

    Error at startup on line 2 of the command:
    CALL package_variables.get () IN: results
    Error report:
    SQL error: ORA-01008: not all variables
    01008 00000 - "not all variables.
    * Cause:
    * Action:
    RESULTS
    --------------------------------


    1 selected lines

    anonymous block filled

    Error at startup on line 2 of the command:
    CALL package_variables.get () IN: results
    Error report:
    SQL error: ORA-01008: not all variables
    01008 00000 - "not all variables.
    * Cause:
    * Action:
    RESULTS
    --------------------------------


    1 selected lines

    */

    The package name is package_variables (note the 's'. Plural.) But using package_variable (in the singular) in your call.
    Also select in as a SQL statement seems to be not valid. You encapsulate a begin - end around her block.

    SQL> begin
      2  select package_variables.get into :outcome from dual;
      3  end;
      4  /
    
    PL/SQL procedure successfully completed
    outcome
    ---------
    Initial Value
    
  • How to recover the vales separated by commas in the same column in Oracle SQL

    Dear members

    Please give me the solution for the below question

    Oracle table

    Ename product
    A 1,2,3
    B 1,2,3


    Product column has data like this only separated by commas

    Output should be like this.

    Ename, product
    A 1
    A 2
    A 3
    B 1
    B 2
    B 3

    Can we get the output above using just Oracle SQL select statement?
    I tried in Google I got an answer in SQL server, there is something called "Cross apply split" function, I'm not sure in Oracle.

    Welcome to the forum.

    Here is another interesting site, with lots of useful examples:
    http://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:2189860818012 #2654179200346949517

    Also, be sure to read the SQL and PL/SQL FAQ:
    http://forums.Oracle.com/forums/Ann.jspa?annID=1535

  • How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    WITH cte (col1, col2) AS
    (
    SELECT col1, col2
    FROM dbo. [tb1]
    WHERE col1 = 12
    UNION ALL
    SELECT c.col1, c.col2
    FROM dbo. [tb1] AS c INNER JOIN cte AS p ON c.col2 = p.col1
    )
    DELETE one
    FROM dbo. [tb1] AS an INNER JOIN b cte
    ON a.col1 = b.col1

    Hello
    Something like this maybe:

    DELETE FROM dbo.tb1 a
     WHERE EXISTS (
      SELECT 1
        FROM dbo.tb1 b
      WHERE a.co11 = b.col1
          AND a.col2 = b.col2
       START WITH b.col1 = 12
      CONNECT BY b.col2 = PRIOR b.col1)
    

    Although you need to do here is to check that CONNECT it BY SELECT, returns records you wait first, then the DELETION should work too.

  • How to create a new connection on oracle sql developer

    Hello
    I was installed oracle sql program in windows after installation I tried to create a new connection, but I get the error message: the account is locked.
    Oracle dba must install for this connection or else.i was developer sql only oracle installed on my windows machine.






    Thanks and greetings
    Prabhakar

    The account is locked at the database level and Developer SQL cannot get around that.

    You must have dba privileges to unblock, but this isn't a problem SQL Developer.

Maybe you are looking for

  • Question I look at KODI cable HDMI MacBook Pro 13"

    Hello, I have a MacBook Pro 13 inch with the retina display; 2.9 GHz Intel Core i5 processor and an a 6100 Graphics Iris Intel running iOS EL Capitan 10.11.3. My MBPro has an HDMI port that I'm supposed to be able to connect to and watch on my TV. Wh

  • Intermittent Wireless - Satellite A200-1VO

    I can get a wireless broadband connection, but then the connection is lost and then turns on again sometimes several times per minute.Broadband connection is OK using an Ethernet cable direct, but the wireless connection is intermittent, even if the

  • Impossible to install WIN 7 SP1 on NB250

    When I run Windows Update on the laptop NB250 installing Windows 7 SP1 is recommended. Even if the computer is not able to install this update and shows error code 800F0829. In this site, I learned that NB250 is compatible with SP1. That is why I wou

  • Luxor adventure freezes during playback

    Original title: luxor adventure freezes during the game and can't get out of Access violation 05370BC and 6CF1E828Game address will freeze access violation and read the address 6CF1E828. To go out I have to stop down

  • The r240hy of 23.8 "monitor has a headphone jack?

    I specifically requested on the 23.8 "model. I continue to read the amazon reviews that say there a and pcmag review mentions as he does, but there is no mention of it Acer.com or amazon cares and there is no site of anywhere in the pictures on one o