Cannot wrap a select with order by clause in a file.
TOGETHER SET TERMOUT OFF FEEDBACK OFF PAGESIZE 0 400 LINESIZE ECHO OFF OFF POSITION
coil & 1;
Select "EMPID, EMP_NAME, REGION, FROM, TO, MONTH, ACTIVITY_TYPE, PROJECT_PIN, MILESTONE_NAME, PRACTICE_ID, RESOURCE_CATEGORY, HOURS, COMMENT, percent ALLOCATION, INVOICE_TO, the STATE of the double"
Union of all the
select empid,resource_name,region,week_of,(week_of+7),core_month,bill_rate,project_name,project_type,milestone_name,practice_id,resource_category,total_hours_submitted,project_type,"%ALLOCATION",invoice_to,status from master_emp_allocation order by week_of;
spool off;
"exit";
/
the above block gives result below
select empid,resource_name,region,week_of,(week_of+7),core_month,bill_rate,project_name,project_type,milestone_name,practice_id,resource_category,total_hours_submitted,project_type,"%ALLOCATION",invoice_to,status from master_emp_allocation order by week_of
*
ERROR at line 3:
ORA-00904: "WEEK_OF": invalid identifier
---------------------------------------------------------------------------
Without the order by clause it wraps the file passed as an argument.
check
Combining the UNION AGENDA and BY
Columns in the ORDER BY list must be a subset of the columns in the selection list on the left side of the union.
All the columns in the ORDER BY list should be sorted in ascending order, and they must be a prefix in the order of the columns in the target of the left side of the UNION list.
Tags: Database
Similar Questions
-
Hai all,
I have problem with order by clause,
My query is
"Select number from table1 order number CSA.
and the output as
1
10
12
13
15
17
19
2
20
21
22
.
........
But if we give the order that it should display below the only good?
1
2
10
12
13
15
17
19
20
21
22 ........
Help me please why it is not displayed as she. and how to make the statement to display as in the second case. Thanks in advance.
Kind regards
UrajaIn your table, the column is VARCHAR2 data type.
It is a string, even if it is to store numeric values, it will get condemn as strings
Try the below
select your_column from table1 order by to_number(your_column) asc
Published by: JAC on November 19, 2012 16:35
-
Hello
I have a table with the data below, when I run my select with order option gives me
1 card
as a first line, but I need it
12 atm
as the first line, how this is possible.
create table test
(Identification number,
Val varchar2 (20)
)
insert into test values (1, 'Card')
Insert test values (2, ' map')
Insert test values (3, ' map')
Insert test values (4, 'cash')
Insert test values (5, 'Cash')
Insert test values (6, 'cash')
Insert test values (7, "Checque")
Insert test values (8, "Checque")
Insert test values (9, "Checque")
Insert test values (10, 'atm')
insert into test values (11, 'atm')
Insert test values (12, 'atm')
Select * from test
order by ASC of valOr try again with
select * from test order by upper(val) asc, id desc
-
Need help with order by clause row_number() Fn
Desired outputwith t as ( select 123 id, 'brwr' lstatus from dual union all select 123 id, 'ca' lstatus from dual union all select 123 id, 'fac' lstatus from dual union all select 345 id, 'ca' lstatus from dual union all select 345 id, 'brwr' lstatus from dual union all select 567 id, 'brwr' lstatus from dual union all select 789 id, 'brwr' lstatus from dual union all select 1011 id, 'fac' lstatus from dual union all select 1011 id, 'xyz' lstatus from dual )select id,lstatus,row_number() over(partition by id order by lstatus)rw from t;
That is, my first priority is to 'ca', then 'College '.id lstatus rn 123 brwr 3 123 ca 1 123 fac 2 345 ca 1 345 brwr 2 567 brwr 1 789 brwr 1 1011 fac 1 1011 xyz 2
I am aware that this can be done through the use of CASE within the order by clause
but could not find the logic of the apt.
Please help me.A solution just for data given to samples...
with t as ( select 123 id, 'brwr' lstatus from dual union all select 123 id, 'ca' lstatus from dual union all select 123 id, 'fac' lstatus from dual union all select 345 id, 'ca' lstatus from dual union all select 345 id, 'brwr' lstatus from dual union all select 567 id, 'brwr' lstatus from dual union all select 789 id, 'brwr' lstatus from dual union all select 1011 id, 'fac' lstatus from dual union all select 1011 id, 'xyz' lstatus from dual )select id,lstatus,row_number() over(partition by id order by (case when lstatus <> 'brwr' THEN UPPER(lstatus) else lstatus end)) rw from t;
Basically, it shows how to use the CASE statement. You can change based on your actual data.
Concerning
Arun -
Stmts SELECT with a Having Clause
Hello
A body can help me to improve the performance of the query below...
Select t.seq_no, t.contract_id, t.date_from in test_plan_tab t
Group of t.seq_no, t.contract_id, t.date_from
seen (select count (*)
of test_plan_tab p
where p.contract_id = t.contract_id
and p.date_from = t.date_from) > 1
The clause will reduce the performance of the query above, I guess as seen...
Thank you and best regards,
/ Dieng...In order to analyze the table only once you can try something like this:
SELECT seq_no, contract_id, date_from FROM (SELECT t.seq_no, t.contract_id, t.date_from, COUNT(*) over(PARTITION BY contract_id, date_from) count_filter FROM test_plan_tab t GROUP BY t.seq_no, t.contract_id, t.date_from) WHERE count_filter > 1
Published by: fsitja on March 18, 2010 02:08
-
All,
Facing a problem with the query below... "DISTINCT with Order By Clause.
His work when we take the same distinct column and order at this time where the query works. But in my case... There are a couple of b/w of joining tables... and are distinct for a column and the order is for a different table with a different column.
Please suggest me a solution for this below query column in the separate and column used for sorting are different.
SELECT DISTINCT gl_cc.segment2
OF gl_code_combinations gl_cc,.
per_all_people_f req_emp,
per_all_assignments_f req_emp_assign
WHERE req_emp.person_id = req_emp_assign.person_id
AND gl_cc.code_combination_id =
req_emp_assign.default_code_comb_id
AND req_emp.full_name = 'xyz '.
ORDER BY req_emp_assign.last_update_date DESC
Thank you
Problem will takes us to Basic!
Processing order for SELECT statements.
SQL query(Non recursive SQL) are processed in the following order
FROM clause
WHERE clause
GROUP BY clause
HAVING clause
SELECT clause
ORDER BY clause
So if you have something in the ORDER BY, but even not Fetch in SELECT it is bound to view the error.
Given THAT order will work on column projected by SELECT!
Single table query will fail also.
Select distinct ename in order by empno emp;
SQL error: ORA-01791: not a selected expression
01791 00000 - "not a selected expression.
* Cause:
* Action:
Inclusion of the req_emp_assign.last_update_date in the select column is necessary for order processing
-
Hi all
I want to use rownum with order of clause-
When I use an order clause in the select query, I get so many lines that I don't want.
I have average-i want only two first rows according to the order of.
EG. - Select employee_id, salary of the order of salary employees;
EMPLOYEE_ID, FIRST_NAME SALARY
----------- -------------------- --------
132 2100 TJ
Steven 128 2200
2200 hazelnut 136
James 127 2400
135 Ki 2400
now, I just want to see the first two lines of the output above.
any oneone please help doesSQL> SELECT * FROM (SELECT employee_id, first_name, salary FROM employees ORDER BY salary) WHERE ROWNUM < 3; 2 3 4 5 6 7 EMPLOYEE_ID FIRST_NAME SALARY ----------- -------------------- ---------- 132 TJ 2100 128 Steven 2200
-
Problem in the SQL because of the order by clause
Hi all
I am facing a problem in a sql query. I use Oracle 10 g 2.
Query is given below:
The query Plan is:SELECT t1.ename FROM T1, T2 WHERE T1.EMPNO = 1234 AND T1.ACCOUNTNO = T2.ACCOUNTNO AND T1.SEQ = T2.SEQ ORDER BY T2.SEQ
Now, I want to reduce the time of this request..---------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 2 | 218 | 11716 (1)| 00:00:41 | |* 1 | TABLE ACCESS BY INDEX ROWID | T1 | 1 | 89 | 1 (0)| 00:00:01 | | 2 | NESTED LOOPS | | 2 | 218 | 11716 (1)| 00:00:41 | |* 3 | TABLE ACCESS BY INDEX ROWID| T2 | 2 | 40 | 11715 (1)| 00:00:41 | | 4 | INDEX FULL SCAN | PK_T2_SEQ | 58752 | | 122 (5)| 00:00:01 | |* 5 | INDEX RANGE SCAN | FK_ACCOUNTNO | 3 | | 0 (0)| 00:00:01 | ----------------------------------------------------------------------------------------------------
If I remove order by clause query that the query performance is quite perfect, but with order by clause its take time.
I already set SORT_AREA_SIZE, but still nothing improves.
Welcome and thank you for your suggestions.
Thank you
Published by: BluShadow on June 23, 2011 07:55
addition of {noformat}{noformat} tags and formatted explain plan to make it readable. Please see {message:id=9360002} for details on how to post code and data
Hey, a quick test, try:
select ename from ( SELECT t1.ename, T2.SEQ FROM T1, T2 WHERE T1.EMPNO = 1234 AND T1.ACCOUNTNO = T2.ACCOUNTNO AND T1.SEQ = T2.SEQ and rownum > 0) ORDER BY SEQ
Amiel Davis
-
Install the Microsoft silverlight plug in. it's necessary to watch movies on my vista computer. When I try it is the message I get. Cannot find a volume with enough disk space for the file extraction. This is the message I get trying to watch a movie on netflix.
Hi cardsharkha,
I suggest you try the steps mentioned in the link below for cleaning broken Silverlight installation and check if the problem persists
How to manually clean a broken Silverlight installation
Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems can occur if you modify the registry incorrectly. Therefore, make sure that you proceed with caution. For added protection, back up the registry before you edit it. Then you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click on the number below to view the article in the Microsoft Knowledge Base:
How to back up and restore the registry in Windows
http://support.Microsoft.com/kb/322756/Thank you, and in what concerns:
Ajay K
Microsoft Answers Support Engineer
Visit our Microsoft answers feedback Forum and let us know what you think
-
ORDER BY clause with an expression
As the column of names and table name is valid, what happening internally when the query is executed?
SQL > SELECT STU_ID, STU_NAME FROM to STUDENT BY 2 + 3, STU_ID;
What I discovered, was that the lines get sorted by ascending order of STU_ID. It is obvious that he does not know the expression 2 + 3, so my doubts are:
(a) is he adding a pseudo-column to the table with 2 + 3 get discounted at 5?
Select (b) if there is a 5th column among students of the table and specify us it in the select statement of the list (5 column names) then why not consider as 5 and sort the data according to that?
(c) it is true that, any expression that we write is getting evaluated to null? Then - what is ORDER BY NULL refers to any order and if the Analyzer search name column or next position (if specified)?
(d) If neither of the two, so what is the reason of ignorance?Hello
Welcome to the forum!
987236 wrote:
As the column of names and table name is valid, what happening internally when the query is executed?SQL > SELECT STU_ID, STU_NAME FROM TO STUDENT BY 2 + 3, STU_ID;
What I discovered, was that the lines get sorted by ascending order of STU_ID. It is obvious that he does not know the expression 2 + 3, so my doubts are:
b is a pseudo-column adding to the table with 2 + 3 get discounted at 5
There is no column pseduo involved. (Pseudo-colonnes are something that Oracle provides to you, without requiring you to specify what you want. Include ROWID and LEVEL pseudo-colonnes. In this example, 2 + 3 is an Expression . Like the pseudo-colonnes, expressions can usually appear in the ORDER BY clause, even if they are not actually stored in the table.)
It is the first sort by the NUMBER 5 (= 2 + 3), not the 5th column. Since the NUMBER 5 has the same value on every row, every row relates to the forefront. The result of sorting by any constant is the same; the results are the same that besides as exrpression in the ORDER BY clause. This is the clause ORDER BY, that you have published is equivalent toORDER BY 2 + 3 , 'foo' , SYSDATE , NULL , stu_id
and this is also equivalent to
ORDER BY stu_id
None of the expressions except stu_id vary from one line to the other, then none of them affect sorting.
Select (b) if there is a 5th column among students of the table and specify us it in the select statement of the list (5 column names) then why not consider as 5 and sort the data according to that?
As Solomon replied only literal numbers are taken to refer to a column. 5 is a literal number, then
ORDER BY 5
means "Sort by the 5th column", but 2 + 3 is not a literal (that is an expression that happens to include a couple of literals), so
ORDER BY 2 + 3
does not refer to the 5th colunmn.
(c) it is true that, any expression that we write is getting evaluated to null? Then - what is ORDER BY NULL refers to any order and if the Analyzer search name column or next position (if specified)?
No, when you way "ORDER BY x", the rows with values of x which come first, followed by the lines with higher values of x. lines having the same value of x will be together, in no particular order with respect to the other (unless there is an expression of failure later in the clause ORDER BY.
This is exactly what happens when you say "ORDER BY NULL". NULL has the same value (in fact, the same lack of any value) on all lines, so all rows have the same value of x, and they will appear in no particular order.(d) If neither of the two, so what is the reason of ignorance?
-
WITH the ORDER BY clause and bug SDO_GEOMETRY?
I'm having a problem using SDO_GEOMETRY in a WITH clause. Specifically with ORDER BY. I'll show a shortened version of SQL here. I'm doing something wrong or is this a bug?
It works:
After the statement select in a with clause, this does not work, which gives an identifier not valid "SDO_GEOMETRY" ORA-00904:SELECT loc.location_id, SDO_GEOM.SDO_DISTANCE(cent.lat_long, MDSYS.SDO_GEOMETRY ( 2001, -- SDO_GTYPE attribute: 2 in 2001 specifies dimensionality is 2. '4326', SDO_POINT_TYPE(-78.6386145, 35.772096, NULL), NULL, NULL ), 0.01, -- tolerance 'unit=mile') result_center_distance FROM location loc JOIN centroid cent ON loc.centroid_id = cent.centroid_id ORDER BY result_center_distance
If I duplicate the function of the distance in the ORDER BY, it works:WITH location_distance AS ( SELECT loc.location_id, SDO_GEOM.SDO_DISTANCE(cent.lat_long, MDSYS.SDO_GEOMETRY ( 2001, -- SDO_GTYPE attribute: 2 in 2001 specifies dimensionality is 2. '4326', SDO_POINT_TYPE(-78.6386145, 35.772096, NULL), NULL, NULL ), 0.01, -- tolerance 'unit=mile') result_center_distance FROM location loc JOIN centroid cent ON loc.centroid_id = cent.centroid_id ORDER BY result_center_distance ) SELECT * from location_distance
WITH location_distance AS ( SELECT loc.location_id, SDO_GEOM.SDO_DISTANCE(cent.lat_long, MDSYS.SDO_GEOMETRY ( 2001, -- SDO_GTYPE attribute: 2 in 2001 specifies dimensionality is 2. '4326', SDO_POINT_TYPE(-78.6386145, 35.772096, NULL), NULL, NULL ), 0.01, -- tolerance 'unit=mile') result_center_distance FROM location loc JOIN centroid cent ON loc.centroid_id = cent.centroid_id ORDER BY SDO_GEOM.SDO_DISTANCE(cent.lat_long, MDSYS.SDO_GEOMETRY ( 2001, -- SDO_GTYPE attribute: 2 in 2001 specifies dimensionality is 2. '4326', SDO_POINT_TYPE(-78.6386145, 35.772096, NULL), NULL, NULL ), 0.01, -- tolerance 'unit=mile') ) SELECT * from location_distance
This is a bug. But it is set to 11g R2. Note that this is not a space bug, but a bug in generic compilation.
-
Purpose of the ORDER BY clause in the analytic function Min Max
I was always using analytical functions like Min Max without ORDER BY clause. But today I used with the ORDER BY clause. The results are very different. I would like to know the purpose of the ORDER BY clause in Min, Max and analogues of analytical functions.user10566312 wrote:
I was always using analytical functions like Min Max without ORDER BY clause. But today I used with the ORDER BY clause. The results are very different. I would like to know the purpose of the ORDER BY clause in Min, Max and analogues of analytical functions.It is a good point that many developers are not so aware. As far as I understand it the way it works.
Some analytical functions do not need an order by or windowing clause (SUM, COUNT, MIN, etc.). If there is no specified window, then the full score is the window.
As soon as you add a command also add you a windowing clause. This window has the default value of 'rank ofrowsbetween unbounded preceding and current_row. So as soon as you add an order by clause, you get a sliding window.Documentation: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm
windowing_clause
...
You cannot specify this clause unless you specified the order_by_clause. Window limits defined by the clause RANGE you can not specify only a single expression to the > order_by_clause. Please refer to 'Restrictions on the ORDER BY Clause'.example of
with testdata as (select 10 numval, level lv from dual connect by level < 10) select lv, numval, sum(numval) over () sum1, sum(numval) over (order by lv) sum2 from testdata; LV NUMVAL SUM1 SUM2 -- ------ ---- ---- 1 10 90 10 2 10 90 20 3 10 90 30 4 10 90 40 5 10 90 50 6 10 90 60 7 10 90 70 8 10 90 80 9 10 90 90
Published by: Sven w. on 25 Sep 2012 16:57 - default behavior has been corrected. Thanks to Chris
-
order by clause and index access
Hi all
I have tried under request.
SELECT e.employee_id, e.department_id
E EMPLOYEES
order by 2;
Implementation plan...
SELECT STATEMENT, GOAL = ALL_ROWS 4 107 856
SORT ORDER BY 4 107 856
TABLE ACCESS FULL EMPLOYEES OF HR 3 107 856
Below query Oracle by using the INDEX FULL SCAN. I'm not able to find an appropriate explanation. Pls how me oracle optimizer include order by clause while to fetch documents.
-departmentId has index EMP_DEPARTMENT_IX, which is the normal index.
SELECT e.employee_id, e.department_id
E EMPLOYEES
order by 1;
SELECT STATEMENT, GOAL = ALL_ROWS 3 107 856
TABLE ACCESS BY INDEX ROWID HR 3 107 856
INDEX FULL SCAN HR EMP_EMP_ID_PK 1 107
Thank you.Consolidation of the index factor is used by the CBO to calculate how much is a scan interval index (the one that is followed by a table-access by rowid) for this index will be. The CBO calculates this option to select an index if two or more paths index are available.
But it could also be used to decide between choosing a full index scan (to honor an order by clause and without having to sort after the scan) in the course of a full table scan that requires an extra sort (in honor of the order by clause) operation.There are many articles talking about this:
http://www.oaktable.NET/category/tags/clustering-factor
http://Oracle-Randolf.blogspot.com/2010/01/clusteringfactor-what-if-analysis.html
http://mehrajdba.WordPress.com/2009/02/09/index-clustering-factor/
I just realized today that in case you described: If department_id column is NULL-able, Oracle cannot use the index in department_id to honor the order by clause, because he would find all the lines (those with an id of NULL service), in this case.
-
passing parameters in the order by clause of the cursor
Hi friends,
I am facing a strange problem
I have a cursor with an order by clause.
OPEN FOR Cursor_nomrpt
SELECT DISTINCT
CAST (plano.desc3 AS VARCHAR2 (50)) category
plano.name plan_name
, chip nvl (CAST (plano.desc6 AS VARCHAR2 (50)), 'not applicable')
, nvl (trunc(plano.value18,2), 0) nominal_slm
, nvl (trunc(plano.value19,2), 0) blm
plano.dbdateeffectivefrom date_live
,
Plano.DBKEY pog_id
, case when plano.value47 < 0 THEN 0 when plano.value47 IS NULL THEN 0 ELSE plano.value47 END as parent_id
Of
Plano dplapro1.ix_spc_planogram
INNER JOIN dplapro1.ix_spc_performance ON plano.dbkey = perf.dbparentplanogramkey perf
Produces INNER JOIN dplapro1.ix_spc_product ON perf.dbparentproductkey = product.dbkey
INNER JOIN dplapro1.ix_spc_product_key ON product.dbkey2 = prodkey.dbkey prodkey
AND prodkey.keylevel = 2
WHERE
Plano.value50 = 0
AND plano.dbkey4 = p_subcatkey
ORDER BY ltrim (rtrim (p_orderby)) CSA;
p_orderby is the parameter that is passed. But the result is not sorted. But when I run the cursor to hardcode the value of parameter, that it works fine...
Need your help on thisHello
When you use a local variable in a cursor, it's as if you had hard-coded literal in its place, you cannot use a variable to a column name.
If you know all the possible values for p_orderby, you can do something like this:
... ORDER BY TRIM ( CASE p_orderby WHEN 'DESC' THEN plano.desc WHEN 'VALUE' THEN plano.value ... END ) ASC;
If you don't know not all possible values, you can use dynamic SQL statements.
By the way
TRIM (x)
Returns the same results as
LTRIM ( RTRIM (x))
-
Hello
I want to know what it means when I use the "order by" clause with more than one column in both cases (sort order, it's the same, and when the sort order is different), for example
What should happen when I do this
1 Select * from table
order by 1, 2; -both are a CSA
2 - Select * from table
order by 1 asc, desc 2;
in both cases if it sorts the column with the first column without worrying, it is asc or desc, order another column order, because he should get
related data in the first column, then another sort column does nothing?
Am I wrong?
Thank you
SQL > select * from t by col1, col2 CSA CSA;
COL1 COL2
-------------------- --------------------
1 1
1 2
1 3
2 1
2 2
SQL > select * from t by CSA col1, col2 desc;
COL1 COL2
-------------------- --------------------
1 3
1 2
1 1
2 2
2 1
Maybe you are looking for
-
DVD writer internal necessary for Satellite Pro 4340
Hi everyone has found a suitable DVD INTERNAL burner (preferably double layer) which adapts and will work in a Satellite Pro 4340 or a laptop of the 4200 series? No answers please tell your machine is too old, etc. - they are not useful. I only want
-
After a Windows 10 update, my printer will not touchpad analyze. It will scan the troubleshooting utility. I unplugged and reset without success. I have updated to the latest version of the HP software for the printer. What else can I try?
-
Weird hang-ups with T61 HARD drive
Hello I bought a new Thinkpad T61 in March and have had a lot of problems with it since then. I think that they are somehow related to my HARD drive. I'm not 100% sure though. In certain situations, my system just hangs. It will not crash, it just ha
-
Not recognised as a device of media by my computer
How can I make visible my tablet in my computer icon? It seems that it is not recognized by my computer but I did completely successful installation of the driver of my Acer Iconia B1 - A71 tablet in my laptop. My operating system is Windows XP. I tr
-
Windows Meida Player can not broadcast raidio stations
I installed the service Pack 2 of Windows on my computer, but it is not allowing me to the radio stations stream with the Microsoft Windows Media Player only has something how to make my radio works with Windows Vista Service Pack 2?