The Clause SQL command

Hello

Could someone please help me with this spacial "order by" requirement, which I couldn't do...

Thanks in advance!

drop table test;

create table (test)

number of col1,

col2 number,

number of col3,

COL4 date);

Insert test values (1, 10, 20, to_date (1 January 2014 ',' MON-DD-YYYY ""));

Insert test values (2, 20, NULL, to_date (February 1, 2014 ',' MON-DD-YYYY ""));

Insert test values (3, 10, 30, to_date (March 1, 2014 ',' MON-DD-YYYY ""));

Insert test values (4, 10, 50, to_date (April 1, 2014 ',' MON-DD-YYYY ""));

Insert test values (5, NULL, NULL, to_date (May 1, 2014 ',' MON-DD-YYYY ""));

Insert test values (6, 10, 10, to_date (June 1, 2014 ',' MON-DD-YYYY ""));

Insert test values (7, NULL, NULL, to_date (1 July 2014 ',' MON-DD-YYYY ""));

Insert test values (8, 60, NULL, to_date (August 1, 2014 ',' MON-DD-YYYY ""));

insert into test values (9, NULL, 60, to_date ('01-SEP-2014', 'MON-DD-YYYY'));

insert into test values (10, 30, 80, to_date (October 1, 2014 ',' MON-DD-YYYY ""));

insert into test values (11, NULL, NULL, to_date (1 November 2014 ',' MON-DD-YYYY ""));

Insert test values (12, 120, 100, to_date (December 1, 2014 ',' MON-DD-YYYY ""));

COMMIT;

SELECT * FROM TEST;

COL1 COL2 COL3 COL4

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

1 10 20 1ST JANUARY 14

2 20 1 FEBRUARY 14

3 10 30 1ST MARCH 14

4 10 50 1 APRIL 14

5 1 MAY 14

6 10 10 1 JUNE 14

7 1 JULY 14

8 60 1 AUGUST 14

9 60 01 - SEP - 14

10 30 80 1 OCTOBER 14

11 1ST NOVEMBER 14

12 120 100 1 DECEMBER 14

12 selected lines.

This is the result I'm looking for:

Order by COL4, but NULL in COL2 and COL3 values must appear in the last...

COL1 COL2 COL3 COL4

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

1 10 20 1ST JANUARY 14

3 10 30 1ST MARCH 14

4 10 50 1 APRIL 14

6 10 10 1 JUNE 14

10 30 80 1 OCTOBER 14

12 120 100 1 DECEMBER 14

2 20 1 FEBRUARY 14

5 1 MAY 14

7 1 JULY 14

8 60 1 AUGUST 14

9 60 01 - SEP - 14

11 1ST NOVEMBER 14

12 selected lines.

so, something like

ORDER BY CASE when col2 is null or col3 is null then 1 or 0 end CSA, CSA col4

HTH

Tags: Database

Similar Questions

  • ETG assess "in order to" in the APEX SQL command window?

    I need to recreate my table in order to change the order of the columns. When I use the SQL command window and run the SQL, it runs successfully, creates the table, but is not rearrange the columns.

    This is expected behavior?

    user648567 wrote:

    Please update your forum profile with a real handle instead of 'user648567 '.

    I need to recreate my table in order to change the order of the columns. When I use the SQL command window and run the SQL, it runs successfully, creates the table, but is not rearrange the columns.

    What do you mean by "in order to"?

    A clause using "ORDER BY" in a DEC (in SUMMIT or other anywhare) has no effect on the order of the columns , which is determined by the order in which the columns appear in the projection. It will affect the order in which the rows are returned from this query, and it will not determine the order in which lines will be returned by querying the new table in the future.

    To change the order of columns, the columns in the SELECT of the ETG clause must be in a different order than the original table,

  • a summary of the set which are accepted by the developer SQL commands...

    Sorry, I searched for a list of commands that are used by the SQL Developer such as "game check out | on", etc.

    Can someone point me to a list of these commands (equivalent to SQL * more set controls)?

    Thanks in advance!
    Tom

    Hi Tom,

    Try help | Table of contents | SQL Developer concepts and use. With the help of the SQL worksheet | SQL * more statements support and not supported in the SQL worksheet.

    What you see depends on your version of SQL Developer. Over time, SQL * more supported continues to improve.

    Kind regards
    Gary Graham
    SQL development team

  • Use of ROWID in the Update SQL statement

    Hi all

    I have an update statement that uses the rowid column to make the selection on the target table. Since a rowid represents the physical location of a row on disc, we know that this reference may change when various activities are conducted on the line of database/table/etc...

    Here is an example of the statement I post:

    UPDATE tabA outertab SET col1 = 'value '.
    WHERE EXISTS (SELECT 1 FROM tabA innertab WHERE outertab.) ROWID = outertab. ROWID AND...)

    Of course, the inner query is more complicated and uses other tables etc. but for the purposes of the example we don't need to include the details.

    My question is: what help rowid in a single statement SQL as a reference of a subquery in the outer statement is there a risk that outdoor activities can change the rowid and these changes be reflected in the session database that my query is executed which causes an incompatibility between the clause SQL internally and externally?

    In response to the question that will follow this post: 'why don't you just use a PK', we would like to avoid to maintain a PK on the table that we are talking about very large volumes of data and we do not want to have to appeal to a sequence, if we can avoid when we insert the data. If however there is a risk that this Update statement may fail, or update lines badly, then we might have to use a PK.

    I know there are a lot of discussions about this, but I havnt been able to find one that someone answered with any kind of confidence or clarity, any help would be appreciated.

    Thank you

    Keith

    Edited by: Turtle on March 5, 2009 05:24

    When using rowid in a single statement SQL as a reference of a subquery in the outer statement is there a risk that outdoor activities can change the rowid and these changes be reflected in the session database that my query is executed which causes an incompatibility between the clause SQL internally and externally?

    No, it's safe to use rowid in this query type. Docs

    A line assigned ROWID remains unchanged, unless the line is exported and imported using the import and export utilities. When you delete a row in a table, then commit the transaction enclosing, rowid of the deleted row can be attributed to a line inserted in a subsequent operation.

  • Maximum length of the SQL command

    I created a MySQL database and a LabView 8.6 application that inserts data into the database using the SQL Toolbox.  I have a problem very long character data insertion in a LONGTEXT field.  I determined that the problem occurs when the SQL command is more than 1 048 574 characters or the length of a particular field exceeds 1 048 326 characters (cannot say who).

    The error I get is "error-2147467259 occurred at NI_Database_API.lvlib:Conn Execute.vi.  "Exception occurred in the Microsoft OLE DB provider for ODBC drivers: [MySQL] [ODBC 5.1 Driver] [mysqld - 5.1.35 - community] MySQL version disappeared in NI_Database_API.lvlib:Conn Execute.vi.

    According to the MYSQL documentation, a LONGTEXT can 4294967295 characters, so length shouldn't be a problem.  The documentation also indicates "the effective maximum length of LONGTEXT columns also depends on the maximum packet size that is configured in the client/server protocol and available memory", but I don't know how to configure the packet size in LabView.

    I enclose the code example that reproduces the problem, although it is based on a special run table structure effectively.  The table definition is included on the diagram.

    This setting must be configured outside of LabVIEW (UDL or DSN).

    You must configure the server and the client:

    I found this link while searching on stackoverflow

    http://dev.MySQL.com/doc/refman/5.1/en/packet-too-large.html

    You may need to select/Configure a specific vendor (different) in order to set this variable.

  • Customize the operator for the SQL command

    With JDeveloper 12.1.3, I created a search form "Panel with ADF Query Table".  After having specified the search parameters, the SQL that is subject to the MSSQL root command generates the following error message:

    < oracle.adf.controller > < Utils > < buildFacesMessage > < ADF: addition of the following JSF error: incorrect syntax [FMWGEN] [SQLServer JDBC Driver] [SQL Server] close to ' |'. >

    java.sql.SQLException: incorrect syntax [FMWGEN] [SQLServer JDBC Driver] [SQL Server] close to ' |'.

    Here is the part of SQL code that is the question:

    WHERE (((city AS (?) || '%')) AND (State AS (?) || '%') ) ) ) )

    Since MSSQL does not accept the "|" as an operator is valid, an error message is generated.  MSSQL expects the CONCAT function or operator ' + '.  Is it possible and easy to configure JDeveloper for change the operator of ' | ' to the CONCAT function?

    OK, your settings are looking as it should.

    You have two options to work around the problem.

    (1) use your own sql generator, as shown here http://www.jobinesh.com/2013/02/customizing-sql-builder-class.html

    (2) modify the sql code generated for the START WITH operator generate the right sql for sql server code. For this, you can override the method getViewCriteriaItem() as shown here https://tompeez.wordpress.com/2011/08/21/extending-viewcriteria-to-use-sql-contains-4/

    Timo

  • Use the lines of a text file as input to an SQL command

    Hello

    I have a text file containing the lines...

    123

    1234

    I would like to use as input for a SQL command running in a script. ie

    Update flag set < table > = 'Y' where job = < the text file lines >;

    Any help much appreciated.

    See you soon

    External table will do.

    For reference...

    CREATE TABLE Hold'em (SEQ_NUM NUMBER (10));

    insertion in hold select SEQ_NUM in task where proc like '% PROC;

    update set hold_flag = task ' ' where in SEQ_NUM (select hold SEQ_NUM);

  • Using the SQL commands

    Hi I need help with my sql commands please.
    1. build a query to list the name of the Department with pay the lowest.
    2.construct a query to list the personnel number of the Manager (without duplicates) for managers who make more than twice the average salary of their employees
    (Note that not all managers have a function of MANAGER).

    I just need some advice please

    Published by: 888669 on October 28, 2011 10:36

    888669 wrote:
    I had the min() function before and I got a message error "function group is nested too deeply.

    Select dname, sum (sal) of the Department of inner join emp = dept.deptno emp.deptno group of dname with min (sum (sal));

    Try:

    select ...
    from ....
    group by deptno
    having sum(sal) <= ALL (SELECT sum(sal) from emp group by deptno)
    
  • ORA-00911 during addition of comment in the SQL command.

    I work within the ORACLE Database Express Edition page "SQL Command".

    The following query works fine for me:

    SELECT *.
    CUSTOMERS

    As soon as I add comments, I get an error ORA-00911:

    -It is a comment.
    --
    SELECT *.
    CUSTOMERS

    ORA-00911: invalid character

    Hello

    Apex SQL worksheet don't like comments. What is reason you like add comments when you run the query?
    You can try

    SELECT *
    /*This is a comment.*/
    FROM CUSTOMERS
    

    Kind regards
    Jari

  • creation of database using the SQL command * more

    Hello

    This isn't a matter of urgency.

    I learn the Oracle DBA. I have installed Oracle 9.2 in my windows system. And I'm trying to create a database using the SQL command.

    OracleVersion: 9.2
    Windows XP operating system

    CREATE DATABASE suri
    USER SYS identified by manager
    USER system identified by surendra
    LOGFILE GROUP 1 ('F:\Oracle\oradata\suri\redo01.log') SIZE 100M,
            GROUP 2 ('F:\Oracle\oradata\suri\redo02.log') SIZE 100M,
            GROUP 3 ('F:\Oracle\oradata\suri\redo03.log') SIZE 100M
       MAXLOGFILES 5
       MAXLOGMEMBERS 5
       MAXLOGHISTORY 1
       MAXDATAFILES 100
       MAXINSTANCES 1
       CHARACTER SET US7ASCII
       NATIONAL CHARACTER SET AL16UTF16
    DATAFILE 'F:\Oracle\oradata\suri\system01.dbf' size 200M EXTENT MANAGEMENT LOCAL
    UNDO tablespace undots datafile 'F:\Oracle\oradata\suri\undots01.dbf' size 200M
    DEFAULT TEMPORARY TABLESPACE tempts1 DATAFILE 'F:\Oracle\oradata\suri\temp01.dbf' SIZE 100M EXTENT MANAGEMENT LOCAL
    I get the error like below when executing the CREATE DATABASE command.

    ERROR at line 16:
    ORA-25139: invalid option for CREATE TEMPORARY TABLESPACE
    I have validated the syntax but not able to find where is the error.

    Please let me know if you need more details.

    Thanks in advance for your help.


    Kind regards
    Suri

    OracleVersion: 9.2

    Why a so old version (and desupported)? In any case...

    TEMPORARY TABLESPACE tempts1 DATAFILE 'F:\Oracle\oradata\suri\temp01.dbf' SIZE 100 M EXTENT MANAGEMENT LOCAL default

    .. try change DATAFILE with TEMPFILE.

  • Subquery 'WITH SAWITH0 AS' OBIEE 11 g factoring clause contained in the generated sql code

    I have observed that OBIEE 11 g generates in physics request log query using the (subquery factoring) WITH clause to the generated sql code elegantly readable. It's great! Thanks for the developers. However I have a few questions about it.

    __Background__
    Oracle database ' default behavior is that if you have only a subquery in the section, it runs as a perspective in line and he not materialized before the main sql is running. If you have more than one default database engine materializes all the in the order of definition. In some cases, it can completely blow up the SGA and make a query without end. To divert this behavior, you can apply two tips that work both in inline views in subqueries as well: / * + MATERIALIZE * / and / * + INLINE * /, however Analytics 11 g does not seem to have capabilities of Board at the table level logical, only at the level of the physical table.

    If we go with the current default settings, the developers do not know this feature can fall on serious performance problems for the sake of a few sweets of syntax to the generated sql level, I'm afraid.

    __Questions__

    * It is possible to turn the Analytics Server to not use WITH but views inline instead?
    * Is it possible to sneak in a few boards that would the / * + INLINE * / allusion to the proper place in the subqueries generated if necessary
    * Is the Oracle database has any initialization parameter that can influence the behavior of this subquery factoring and divert by default?

    The WITH statement is not added to make the query more elegant, it is added for performance reasons. If your queries slow to run, then you can have a design problem. In a typical DWH DB SGA should be increased seriously given that ran queries are much larger and complex than on an OLTP DB. In all cases, you can disable the WITH statement in the administration tool by double clicking on your database on the physical layer from object in the features tab. The function is called WITH_CLAUSE_SUPPORTED.

  • ORA-00900 - the SQL commands: invalid SQL statement

    Hello world
    I installed Oracle Xe on a Centos 5.5 host yesteday.
    Installation was Ok, I can connect to the web interface on "http://127.0.0.1:8080 / apex / '.
    But when I want to use sql commands, regardless of the input control, I have the "ORA-00900: invalid SQL statement" message.
    I can enter the command "Show all", for example, in a terminal after SQL > command prompt, it works... but not in the web interface...
    I tried to import the .sql, script trought the web interface, no much result, no display in the window.
    Can someone help me,
    Thank you

    Show all is NOT a SQL command is a command that I think, not a command from pl/sql, sql more... Why not try to do a select on a table is know YOU the schema...

    Thank you

    Tony Miller
    Webster, TX

  • Access to SQL previously saved in the SQL command window

    Hi all

    If I kept some codes SQL in the SQL command window, should we not available to other developers when they click on the saved SQL tab? I saved an example query and one of my other developers can't see it. I don't see any setting available on the developer account that controls whether or not the account can see others saved SQL.

    If this is not allowed, then I see really the point of the drop in the saved SQL owner tab.

    Any advice?

    Thank you!!
    John

    My apologies - I've never used this tab so I was not aware of it.

    I played a little and it seems that if you are an administrator of the workspace, but your other user is just a developer, then in fact he or she cannot see your SQL. If you were to switch to the workspace administrators, they should be able to see.

  • execute sql commands in the browser

    I use Oracle 10 g standard edition in the windows platform.

    I am getting SQL prompt, but I want to run the SQL commands in the browser. But I'm not.

    Please help me!

    You must start the iSQL * Plus service. Check starting the iSQL * Plus Application Server.

  • How to monitor the sql commands?

    Hello

    Are there opportunities to control all the SQL commands (ddl, dml) run from all the tools of database (sqlplus, sqldeveloper, Toad, etc.)? Precisious more... Is there something like .bash_history in Linux operating system?

    Best.

    Hello

    Reference: http://www.juliandyke.com/Diagnostics/Trace/EnablingTrace.html
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14211/SQLTrace.htm#PFGRF01010

    It's an additional reference.
    http://download.Oracle.com/docs/CD/B10501_01/EM.920/a88748/otdv.htm

    -Pavan Kumar N

Maybe you are looking for