Return the rows of the table where a column contains a specific value first
I want my query to return the rows of the table where a column contains a specific values first in a certain order, and then return the rest of the rows alphabetized.
For Example:
Country
ALBANIA
ARGENTINA
AUSTRALIA
CANADA
USA
Now i want USA and CANADA on top in that order and then other in alphabetized order.
Edited by: 986155 on Feb 4, 2013 11:12 PM
986155 wrote:
If it is 2 then i can write a case... i want generalised one where may be around 5 or 6 mentioned should be in descending order at the top and remaining in ascending order there after.Computers tend not to work in 'generalized' ways... they require specifics.
If you store your "top" countries in a table you can then simply do something like...
SQL> ed
Wrote file afiedt.buf
1 with c as (select 'USA' country from dual union
2 select 'Germany' from dual union
3 select 'India' from dual union
4 select 'Australia' from dual union
5 select 'Japan' from dual union
6 select 'Canada' from dual union
7 select 'United Kingdom' from dual union
8 select 'France' from dual union
9 select 'Spain' from dual union
10 select 'Italy' from dual
11 )
12 ,t as (-- top countries
13 select 'USA' country from dual union
14 select 'United Kingdom' from dual union
15 select 'Canada' from dual
16 )
17 select c.country
18 from c left outer join t on (t.country = c.country)
19* ORDER BY t.country, c.country
SQL> /
COUNTRY
Canada
USA
United Kingdom
Australia
France
Germany
India
Italy
Japan
Spain
10 rows selected.
Similar Messages
-
How to get the rows from a table having some column has any letter
Hi All,
suppose i have a table having columns id(number), code(varchar).
code has alphanumeric characters (ex. ABC123, 67B56 etc).
some codes are only numbers (2344, 7898 etc).
how can i get the rows which have alphabets in the code.
ex:
id code
1 AB45
2 456
3 890
4 67B7
how can i write a query such that it should give me the ids 1 and 4 (as they have alphabets in code)
thanks in advance to allThanks to one and all.
i am gettig my required output.
But i have a doubt in the operator.
If i add or remove '[]' in the operator, i am getting different ouputs.
There is a count difference in the result of the operators used.
REGEXP_LIKE(<column>,'[[:lower:]]')
REGEXP_LIKE(<column>,'[[[:lower:]]]')
REGEXP_LIKE(<column>,'[:lower:]')
Can anybody please explain what is the difference in using '[]', in the operator?
What is the correct syntax, whether i have to use two '[]'s or one '[]'.
Also, can i use REGEXP_LIKE() in oracle 8i version.( I am unable to use the operator in 8i)?
Any query to get the required output in 8i version?
Thanks in advance to all. -
How do I get the numbers ipad app to plot a graph of dates against values, where the most recent date is on the right of the graph, but the most recent date is at the top rather than bottom of the rows in the table?
Also how can it be a line graph without plotting a circle at each value?
Thanks this is very frustratingMake a copy of the table and produce your Line chart or Bar chart from the copy. Sort the copy into the order you want to see in your chart.
Alternately you could use a Scatter Chart...
Jerry -
Hi,
In my example I want to get all the rows of the table. The table has 20 rows. The visibleRowCount is set to 7 and firstVisibleRow is set to 3.
I have created the table as
var oTable = new sap.ui.table.Table({
id: "oTable",
title: "My Table",
visibleRowCount: 7,
firstVisibleRow: 3,
selectionMode: sap.ui.table.SelectionMode.Single
I tried to get the rows of the table using the below code
var table = sap.ui.getCore().byId("oTable");
var rows = table.getRows(); // Returns only 7 rows
How to get all the rows of the table when the table is populated with a odata service ?Hi Vishal,
The table only put in the html file the rows that you define in visiblerowcount (rows control). The method getRows, get this controls, and you only have 7. The table control render automacatically the data in thats rows when you scroll on it.
If that you want is to retrieve the data of the rows, you need catch it from the model:
oTable.getModel().getData();
Regards, -
Query from oracle to MySql using dblink fetch all the rows in MySql table
Hello,
I am using Heterogeneous connectivity between oracle 10204 to Mysql database.
I have a database link in the oracle side .
I am query a table in MySql that have 10 million rows.
Its doesnt matter if i am running :
select * from "CDR_Accounts"@mysql where "id"=7675405;
or
select * from "CDR_Accounts"@mysql ;
There is an index on the id column.
Yet, it seems that the Mysql is feteching all the rows from the table , all the data is transfering to oracle over the dblink , and only after that the requested rows are get back to the client.
The /etc/odbcinst.ini file is as follow:
[odbcprd:oracle@odbc /software/oracle]$ cat /etc/odbcinst.ini
[myodbc3]
Description = Mysql connector to mysql version 3.5
Driver = /software/oracle/MysqlOdbc/3.52/lib/libmyodbc3-3.51.25.so
Driver64 = /usr/lib
Setup = /software/oracle/MysqlOdbc/3.52/lib/libmyodbc3S-3.51.25.so
Setup64 = /usr/lib
UsageCount = 1
CPTimeout = 3600
CPReuse = Please advice
ThanksWhen using a gateway it is always possible that a where clause is not sent to the remote database. This is called post processing and depends on several factors like the used ODBC driver, the columns and its data types but also if you specify certain functions in the where clause.
The fastest way to see if post processing happens is in Oracle 11g the explain plan for a query. In 10g the plan does not always match the statement sent to the foreign database. Here it would be better to enable gateway tracing and setting the trace level to ON. This will log the statements sent to the foreign database and you can compare what statement was sent with the statement you've tried to execute. -
Display all the rows in the table with Varray
I created two Varrays
CREATE TYPE phone_varray AS VARRAY(3) OF NUMBER(10);
CREATE TYPE email_varray AS VARRAY(3) OF varchar2(30);
CREATE TABLE ee
(id number(2),
phone phone_varray);
now i inserted some rows into ee table and displayed it as:
SELECT e1.id,e2.COLUMN_VALUE"PHONE NO" FROM ee e1,TABLE(e1.phone) e2;
ID PHONE NO
1 1111111111
1 2222222222
1 3333333333
1 1111111111
1 2222222222
1 4444444444
4 1111
4 2222
4 33334
5 1111
5 2222
5 33334
Then i altered the table with email_varray
desc ee;
Name Null? Type
ID NUMBER(2)
PHONE PHONE_VARRAY
EMAIL EMAIL_VARRAY
I updated some rows:
update ee e1 set email=email_varray('aasda') where id=4;
and when i try to display the table data by:
SELECT id,e2.*,e3.* from ee e1,TABLE(e1.phone) e2,TABLE(e1.email) e3;
it only displays the rows that contain all the details like
ID COLUMN_VALUE COLUMN_VALUE
4 1111 aasda
4 2222 aasda
4 33334 aasda
and not all the rows that are in the table which have id and phone and email as NULL
need help to display all the rows in the table.will this work for you ?
SELECT e1.id,e2.COLUMN_VALUE as PHONE_NO, null as email FROM ee e1,TABLE(e1.phone) e2
union
SELECT e1.id,null,e3.column_value as email from ee e1, TABLE(e1.email) e3; -
How can i select the rows from the 3 tables by particular column name?
Vehicle Passing Summary table structure
PsngSmry_ID(Number),Vehicle_iD(Number),PsngSmryTime(datetime)
Vehicle table structure
Vehicle_iD(Number),VehicleName(VarChar2),VehicleType(VarChar2)
Here Vehicle_iD is the Primary Key
Equipment Table Structure
Eqpmt_id(Number),Vehicle_iD(Number),EqpmtName(VarChar2),EqpmtType(VarChar2)
Here Eqpmt_id is the Primary Key and Vehicle_iD is the foreign Key
Equipment Component Table Structure
Eqpmt_Cmpnt_id(Number) ,Eqpmt_id(Number),EqpmtCmpntName(VarChar2),EqpmtCmpntName(VarChar2),Parent_Eqpmnt_ID(Number)
Here Eqpmt_Cmpnt_id is the Primary Key and Eqpmt_id is the foreign Key
The rows in the Vehicle Passing Summary table
PsngSmry_ID Vehicle_ID PsngSmryTime
111111 80986246 2010/10/11
111112 80986247 2010/10/12
111113 80986248 2010/10/10
The rows in the Vehicle Table
Vehicle_iD VehicleName VehicleType
80986246 Lorry Four Wheeler
80986247 Van Four Wheeler
80986248 Bus Four Wheeler
The rows in the Equipment Table:
Eqpmt_id Vehicle_iD EqpmtName EqpmtType
109846 80986246 2 Axle Lorry CAR
109821 80986246 4 Axle Lorry CAR
109825 80986246 4 Axle Lorry CAR
109562 80986247 2 Axle VAn CAR
109555 80986247 3 Axle VAn CAR
109777 80986247 3 Axle VAn CAR
109587 80986248 2 Axle Bus CAR
The rows in the Equipment Component Table :
Eqpmt_Cmpnt_id Eqpmt_id EqpmtCmpntName Parent_Eqpmnt_ID
20904146 109846 Truck
20904147 109846 Truck
20904148 109846 Axle 20904146
20904159 109846 Axle 20904146
20904167 109846 Wheel 20904148
20904177 109846 Wheel 20904148
20904185 109846 Wheel 20904159
20904325 109846 Wheel 20904159
20904188 109846 Axle 20904147
20904189 109846 Axle 20904147
20904195 109846 Wheel 20904188
20904196 109846 Wheel 20904188
20904197 109846 Wheel 20904189
20904398 109846 Wheel 20904189
10904146 109562 Truck
10904147 109562 Truck
10904148 109562 Axle 10904146
10904159 109562 Axle 10904146
10904167 109562 Wheel 10904148
10904177 109562 Wheel 10904148
10904185 109562 Wheel 10904159
10904325 109562 Wheel 10904159
10904188 109562 Axle 10904147
10904189 109562 Axle 10904147
10904195 109562 Wheel 10904188
10904196 109562 Wheel 10904188
10904197 109562 Wheel 10904189
10904398 109562 Wheel 10904189
Note : In Equipment Component Table,the hierarchy will be Truck-->Axle-->Wheel.So
1.the Parent_Eqpmnt_ID of Axle is Truck's Eqpmt_Cmpnt_id.
2.the Parent_Eqpmnt_ID of Wheel is Axle's Eqpmt_Cmpnt_id.
Now I want to write the store procedure which will take "PsngSmry_ID(Number)" as input and the o/p will be in the format :
Eqpmt_Cmpnt_id Eqpmt_id EqpmtCmpntName Parent_Eqpmnt_ID
20904146 109846 Truck
20904148 109846 Axle 20904146
20904167 109846 Wheel 20904148
20904177 109846 Wheel 20904148
20904159 109846 Axle 20904146
20904185 109846 Wheel 20904159
20904325 109846 Wheel 20904159
20904147 109846 Truck
20904188 109846 Axle 20904147
20904195 109846 Wheel 20904188
20904196 109846 Wheel 20904188
20904189 109846 Axle 20904147
20904197 109846 Wheel 20904189
20904398 109846 Wheel 20904189
10904146 109562 Truck
10904148 109562 Axle 10904146
10904167 109562 Wheel 10904148
10904177 109562 Wheel 10904148
10904159 109562 Axle 10904146
10904185 109562 Wheel 10904159
10904325 109562 Wheel 10904159
10904147 109562 Truck
10904188 109562 Axle 10904147
10904195 109562 Wheel 10904188
10904196 109562 Wheel 10904188
10904189 109562 Axle 10904147
10904197 109562 Wheel 10904189
10904398 109562 Wheel 10904189
**Please add these columns in the o/p **
1.EqpmtName and EqpmtType from Eqpmt table
2.VehicleName and Vehicle Type from Vehicle table
3.PsngSmryTime from PassingSummary table **
Can anyone tell me the solution?
Edited by: 865216 on Jun 22, 2011 2:14 AMHi,
I am new to this technology;But, just wanted to help you.
Please refer the code it might be atleast helpful for you.
But am facing PL/SQL: ORA-00933: error and unable to resolve it.could anyone please correct this code.
sorry if my code is totally wrong.
Thank you,
Rupa
create or replace procedure Equipment_proc
is
begin
DECLARE
TYPE EQP_record IS RECORD (
Vehicle_iD Vehicle.Vehicle_iD%TYPE,
Eqpmt_Cmpnt_id Equipment_Component.Eqpmt_Cmpnt_id%type,
EqpmtCmpntName Equipment_Component.EqpmtCmpntName%type,
Parent_Eqpmnt_ID Equipment_Component.Parent_Eqpmnt_ID%type,
Eqpmt_id Equipment.Eqpmt_id%type,
vehicleId NUMBER);
EQP_rec EQP_record;
CURSOR EQP_cursor IS
select a.Vehicle_iD,c.Eqpmt_Cmpnt_id,b.Eqpmt_id,c.EqpmtCmpntName,c.Parent_Eqpmnt_ID
from Vehicle a,Equipment b,Equipment_Component c
where a.Vehicle_iD=b.Vehicle_iD
and b.Eqpmt_id=c.Eqpmt_id
and a.vehicle_id=&EQP_rec.vehicleId;
BEGIN
OPEN EQP_cursor;
FETCH EQP_cursor INTO EQP_rec;
dbms_output.put_line(EQP_rec.Vehicle_iD,EQP_rec.Eqpmt_Cmpnt_id||','||EQP_rec.Eqpmt_id||','||EQP_rec.EqpmtCmpntName||','||EQP_rec.Parent_Eqpmnt_ID);
CLOSE EQP_cursor;
END;
END; -
How to Restrict the Rows In Pivot Table
Hi All,
how to Restrict the Row in the Pivot table.
My Requirement is like this.
i have to show the top 10 values in the pivot table but My report is show all the values.
how can we achieve this.
any quick solution for this appreciated.
Thanks,
Yogi.Yogi1729 wrote:
Hi All,
how to Restrict the Row in the Pivot table.
My Requirement is like this.
i have to show the top 10 values in the pivot table but My report is show all the values.
how can we achieve this.
any quick solution for this appreciated.
Thanks,
Yogi.You can't really restrict the rows in a pivot table, but you can do this:
http://oraclebizint.wordpress.com/2008/01/17/oracle-bi-101332-pagination-in-pivot-tables/ -
How to increase the rows of a Table control on ITS
Hi,
I'm trying to increase the number of rows to 20 on ITS but it always shows 2 rows per navigation. Although in the backend module pool there are 8 rows and the GV_SOS_LIST_CONTROL-LINES contains the total no of rows of the internal table. yet there are always 2 rows getting printed. This screen is in different function group and being called from some other function group i.e BBP_SC_UI_ITS. Are there any parameters that we have missed out to pass from BBP_SC_UI_ITS to our function group. Reply needed urgently!!!!!!!!!!!Hi,
i tried increasing the rows on the browser by hard coding the counter and then the rows do increase but the records that are shown are still 2 per navigation. i doubt if it is a screen size constraint. the transaction in which i'm trying all this is bbpsc01. -
How to list all the rows from the table VBAK
Friends ,
How to list all the rows from the table VBAK.select query and the output list is appreciated.Hi,
IF you want to select all the rows for VBAK-
Write-
Data:itab type table of VBAK,
wa like line of itab.
SELECT * FROM VBAK into table itab.
Itab is the internal table with type VBAK.
Loop at itab into wa.
Write: wa-field1,
endloop. -
Import only the rows of emp table from Test into emp table of Prod
hi,
Test Instance:
=========
I have a table "emp". I want to take export of it.
Prod Instance:
=========
Table with name "emp" already exists.
I want to import only the rows of emp table from Test Instance into emp table of Prod Instance.
regards,
charanCharan,
Set the import command IGNORE=Y
Importing into Existing Tables
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/exp_imp.htm#i1023662
Regards,
Hussein -
Fixing the row height in table
Hi All,
In my table column i am displaying address. Address field is of type STRING_TABLE. (This is needed to display address in the format shown in the example below) As a result of this the row height changes depending on the length of the address.
Hence all the rows in the table are of different heights.
For Example i am displaying the output as shown below.
39 Car Street,
abcdefg,
pincode
india,
ph no.
Now is it possible set the height of the row so that all the rows in the table are of fixed height?
Please help.
Thanks in advance.closed
-
How to merge the Rows in ALV table?
Hi All,
I want to merge the Rows in my ALV table(SALV_WD_TABLE). Is it possible?
Regards,
Yugesh A.Yogi1729 wrote:
Hi All,
how to Restrict the Row in the Pivot table.
My Requirement is like this.
i have to show the top 10 values in the pivot table but My report is show all the values.
how can we achieve this.
any quick solution for this appreciated.
Thanks,
Yogi.You can't really restrict the rows in a pivot table, but you can do this:
http://oraclebizint.wordpress.com/2008/01/17/oracle-bi-101332-pagination-in-pivot-tables/ -
How to return mismatched rows from two tables?
I have created two tables in the same database as below which gives the row
count of tables across all databases before and after an DB restore
operation.
create table before_restore(db_name varchar(100),table_name
varchar(1000),row_count int) insert into before_restore exec sp_msforeachdb 'USE
[?]; select ''?'' as database_name,o.name,max(i.rowcnt ) From [?].sys.objects o
inner join [?].sys.sysindexes i on o.object_id=i.id where o.type=''U'' group by
o.name'
create table after_restore(db_name varchar(100),table_name
varchar(1000),row_count int) insert into after_restore exec sp_msforeachdb 'USE
[?]; select ''?'' as database_name,o.name,max(i.rowcnt ) From [?].sys.objects o
inner join [?].sys.sysindexes i on o.object_id=i.id where o.type=''U'' group by
o.name'
I want to compare these two tables and it should only return me rows that
have changed after the restore operation is complete.
Eg:
Table xyz has rowcount of 100 before restore and the restore was not proper
and after restore count is 50. So it should return me the result set as
below;
Db_name Table_Name row_count_before_restore row_count_after_restore
abc xyz 100
50
Thanks!!!Something like below perhaps? Btw, I recommend using catalog view and dynamic management views instead of the old system tables (now called compatibility views)...
SELECT
COALESCE(a.db_name, b.db_name) AS db_name
,COALESCE(a.table_name, b.table_name) AS table_name
,a.row_count AS row_count_before_restore
,b.row_count AS row_count_after_restore
FROM before_restore AS b FULL OUTER JOIN after_restore AS a ON b.db_name = a.db_name AND b.table_name = a.table_name
WHERE b.row_count <> a.row_count OR b.db_name IS NULL OR a.db_name IS NULL
Tibor Karaszi, SQL Server MVP |
web | blog -
VO got executed but is not showing the rows on the page the first time
Hi, Below are my senario:
I have one jspx which contain a panel tab and 2 tabs inside it: tab A and tab B, under each tab is its own taskflow, jsff page, and its own AM and datacontrol also.
tab A have a table
tab b have a table with search panel. The view criteria that used to generate the search panel is not check "Run Automatically"
What I am trying to do is in tab A, user can select some rows and click one button, then below action happen:
1. the id of the selected rows will be pass to a AM method of tab B as string that separated by comma, and this AM method will execute the VO that the table of Tab B is based on
2. set tab b disclosure to be true to show tab B
3. The row that selected in Tab a will be shown in the table of tab b
Below are the code in the AM of tab b, it is exposed to client and it will be invoked by the button actionlistener of Tab A from the bean:
public void applyDashbaordViewCriteria(String listOfPS) {
if (listOfPS != null) {
PullSequenceSetupVOImpl psvo = this.getPullSequenceSetupVO2();
ViewCriteria vc = psvo.createViewCriteria();
vc.setName("PSDashboardVC");
ViewCriteriaRow vcRow = vc.createViewCriteriaRow();
ViewCriteriaItem vcItem =
vcRow.ensureCriteriaItem(PullSequenceSetupVORowImpl.PULLSEQUENCEID);
vcItem.setOperator(JboCompOper.OPER_IN);
vcItem.getValues().get(0).setValue(listOfPS);
vc.add(vcRow);
psvo.applyViewCriteria(vc);
psvo.executeQuery();
However my issue here is:
Whenever the first time entering the page, which will show tab A, I select some rows in the table and click the button, AM got executed correctly and before it leave above code, VO executed and row count is correctly match with what user selected in Tab A. However, the rows in the vo is not showing in tab B. Table in tab B show no rows.
Workaround for the issue:
If first time entering the page, I go to tab B first, without doing anything then come back to tab A, select some rows and click the button again, then this time, the row I selected start showing in the table of Tab B.
So my question is, how can I solved this issue to make the selected rows show in tab B without going to tab B to load the page first? Is that something to do with datacontrol scope?
I am using Jdev 11.1.1.3.0
Thanks.Hi, now I think i know what is the root cause:
I overide executeQueryForCollection and executeQuery method in the VOImpl that table of Tab B is based on. And I notice the following:
Even when select row in tab A and click the button to call AM method to apply the view criteria and execute the query to return some row, when tab b loading the first time, I notice executeQueryForCollection is being fired again and invoked by executeEmptyRowSet.
It looks to me that even thought before the page load, VO already executed and have some row, somehow when ADF load the page, it will empty all the rows in the VO. And also since I have a query panel which I uncheck the Query Automatically. So even my applied view criteria still there, but VO will not get re executed again and show the result.
I think that is why this issue is happening. And also, that is why if I navigate to tab B first and come back to Tab A, now perform the same action, the selected rows start showing on the page.
Anybody can help me how can I resolved this issue? And also, I don't want to check the "Query Automatically" of the view criteria that I used to genreate the search panel because it may impact the performance.
Edited by: user10867484 on Apr 21, 2011 2:48 PM
Maybe you are looking for
-
Can't get into Mail on iPad 2. Returns to home page with blank white screen.
Any help appreciated. Recently can not get into mail account on iPad 2. Seems to go to blank white page and then returns to home page. thanks, m
-
hello everyone!!! i'm having trouble with my Zen Xtra... i opened Creative MediaSource Organizer to transfer my mp3's to the Zen Xtra from my Music Library... and it wouldn't let me do it, there is a msg about an error, it would say, "Error: Unable t
-
Display Java documentation as Tooltip
Hi! I have a table displaying class attributes with their runtime value; I like to display as tooltip (when the mouse points at the attribute name) the java documentation for that attribute (if it exists). Has anybody tried this and can give me a hin
-
Magic Wand Universal Color/Value Selection?
Is there a way to cause the wand to select ALL similar pixels of a certain value, or value range, throughout the image instead of the ones just immediately under the clicked the selection? Similar to how Illustrator's magic wand deals with fill selec
-
Survey/Questionnaire Widget/Snippet
I want to create and post a survey/questionnaire to iWeb...that can be scored...and the survey with results either stored on the site or sent to my e-mail. Anyone got any experience locating such a critter? regards, mdhttp