Sort the columns of a table
Hi,
There is a table with lot of data. I want to change the order in which the columns are displayed when the table is queries. Is there any way or i just have to drop the table and recreate again.
Have a nice day.
Thank you
PK
Hi,
Like user637951 said, you only need to change the order in your query. Example:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> desc employees;
Name Type Nullable Default Comments
EMPLOYEE_ID NUMBER(6) Primary key of employees table.
FIRST_NAME VARCHAR2(20) Y First name of the employee. A not null column.
LAST_NAME VARCHAR2(25) Last name of the employee. A not null column.
EMAIL VARCHAR2(25) Email id of the employee
PHONE_NUMBER VARCHAR2(20) Y Phone number of the employee; includes country code and area code
HIRE_DATE DATE Date when the employee started on this job. A not null column.
JOB_ID VARCHAR2(10) Current job of the employee; foreign key to job_id column of the
jobs table. A not null column.
SALARY NUMBER(8,2) Y Monthly salary of the employee. Must be greater
than zero (enforced by constraint emp_salary_min)
COMMISSION_PCT NUMBER(2,2) Y Commission percentage of the employee; Only employees in sales
department elgible for commission percentage
MANAGER_ID NUMBER(6) Y Manager id of the employee; has same domain as manager_id in
departments table. Foreign key to employee_id column of employees table.
(useful for reflexive joins and CONNECT BY query)
DEPARTMENT_ID NUMBER(4) Y Department id where employee works; foreign key to department_id
column of the departments table
SQL> select e.employee_id, e.first_name, e.last_name from employees e where e.employee_id = 100;
EMPLOYEE_ID FIRST_NAME LAST_NAME
100 Steven King
SQL> select e.first_name, e.last_name, e.employee_id from employees e where e.employee_id = 100;
FIRST_NAME LAST_NAME EMPLOYEE_ID
Steven King 100
SQL> Regards,
Similar Messages
-
Sorting the column of VARCHAR in report
Hi,
I want to sort the column in report with the following scenario,
I have a column name with PERIOD as VarChar with values APR-11,FEB-11,JAN-11,JUN-11,MAR-11,MAY-11 in a report
As you can see, It is sorting in Alphabetic order but I need to arrange in JAN-11,FEB-11,MAR-11,APR-11,MAY-11,JUN-11
So can anyone has a good work around solution?
regards
VjHere is your challenge. How do you get Jan-12 to come after Dec-11? Adil's solution is partial. It works only for the current year. Once you cross over to the next year, it stops working because you are only sorting the month. You must include the year to make the solution complete. So here is a solution that always works. It involves some math so I'll explain the math first.
Let's look at your values:
Jan-11
Feb-11
Dec-11
Jan-12
If you convert each month to a number (i.e., Jan = 1, Feb =2... etc.) and then multiply the year by 1000 and finally add them together, we get this:
Jan-11 1 --> 11001
Feb-11 2 --> 11002
Dec-11 12 --> 11012
Jan-12 1 --> 12001
You get the picture. The last column will be in the order you seek because the integer will always be greater than the previous month-year even at the transition from December to January. BTW, I multiplied the two digit year by 1000 to ensure that there would be no overlap.
Now you can sort by this third column. Here is the code that does this:
CAST(CASE WHEN LEFT(Table.PERIOD, 3) = 'Jan' THEN '1' WHEN LEFT(Table.PERIOD, 3) = 'Feb' THEN '2' WHEN LEFT(Table.PERIOD, 3) = 'Mar' THEN '3' WHEN LEFT(Table.PERIOD, 3) = 'Apr' THEN '4' WHEN LEFT(Table.PERIOD, 3) = 'May' THEN '5' WHEN LEFT(Table.PERIOD, 3) = 'Jun' THEN '6' WHEN LEFT(Table.PERIOD, 3) = 'Jul' THEN '7' WHEN LEFT(Table.PERIOD, 3) = 'Aug' THEN '8' WHEN LEFT(Table.PERIOD, 3) = 'Sep' THEN '9' WHEN LEFT(Table.PERIOD, 3) = 'Oct' THEN '10' WHEN LEFT(Table.PERIOD, 3) = 'Nov' THEN '11' WHEN LEFT(Table.PERIOD, 3) = 'Dec' THEN '12' END AS INTEGER)+CAST(RIGHT(Table.PERIOD, 2) AS INTEGER)*1000
This solves your problem now even when the month-year crosses to the next year. There you go! -
How to store data file name in one of the columns of staging table
My requirement is to load data from .dat file to oracle staging table. I have done following steps:
1. Created control file and stored in bin directory.
2. Created data file and stored in bin directory.
3. Registered a concurrent program with execution method as SQL*Loader.
4. Added the concurrent program to request group.
I am passing the file name as a parameter to concurrent program. When I am running the program, the data is getting loaded to the staging table correctly.
Now I want to store the filename (which is passed as a parameter) in one of the columns of staging table. I tried different ways found through Google, but none of them worked. I am using the below control file:
OPTIONS (SKIP = 1)
LOAD DATA
INFILE '&1'
APPEND INTO TABLE XXCISCO_SO_INTF_STG_TB
FIELDS TERMINATED BY ","
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
COUNTRY_NAME
,COUNTRY_CODE
,ORDER_CATEGORY
,ORDER_NUMBER
,RECORD_ID "XXCISCO_SO_INTF_STG_TB_S.NEXTVAL"
,FILE_NAME CONSTANT "&1"
,REQUEST_ID "fnd_global.conc_request_id"
,LAST_UPDATED_BY "FND_GLOBAL.USER_ID"
,LAST_UPDATE_DATE SYSDATE
,CREATED_BY "FND_GLOBAL.USER_ID"
,CREATION_DATE SYSDATE
,INTERFACE_STATUS CONSTANT "N"
,RECORD_STATUS CONSTANT "N"
I want to store file name in the column FILE_NAME stated above. I tried with and without constant using "$1", "&1", ":$1", ":&1", &1, $1..... but none of them worked. Please suggest me the solution for this.
Thanks,
AbhayPl post details of OS, database and EBS versions. There is no easy way to achieve this.
Pl see previous threads on this topic
SQL*Loader to insert data file name during load
Sql Loader with new column
HTH
Srini -
How we can replace the column in Core Table plz see this msg
Hi,
How we can replace the column in Core Table plz see this msg
Req:
when i push the Insert button the data inserted into the Table
like
Cols Values
FOCD CUFZ14
PRDCD FU6
Month 082008
AgencyCD AG02
PLAN 123
This is FO_Plan Table....
Requirement:
i need at table show to replace the Prd_CD to Prd_Desc while inserting the above Row....
There is no Prd_Desc in FO Plan Table....
Prd_desc comes from Product Table.
did u get my point...
how to solve.
Thanks
Ram
Edited by: Ram Vungarala on Sep 24, 2008 9:09 AM
Edited by: Ram Vungarala on Sep 24, 2008 9:15 AMHi,
I'm not sure if I understood what are you trying to do. But you can modify your table in a backing bean code. JSF page code for a table:
<af:table id="product_search_results_tbl" binding="#{backingBean.boundTable}" ... />
And a backing bean code:
import oracle.adf.view.faces.component.core.data.CoreTable;
public class YourBackingBean {
private CoreTable boundTable;
public void setBoundTable(CoreTable boundTable) {
this.boundTable = boundTable;
public CoreTable getBoundTable() {
return boundTable;
public String insertButtonAction() {
// Bind your button action to this method and modify here your bound table
return null;
{code}
Look for column modification methods in a CoreTable class documentation.
Marius -
How to sum the column in a table seperated by sign.
How to sum the column in a table separate by sign.
For Example:
A B
10 MOHAN
-15 KUMAR
-25 MARCH
50 MAYSELECT SUM(CASE SIGN(A) WHEN 1 THEN A ELSE NULL END) SUM_POSTIIVE,
SUM(CASE SIGN(A) WHEN -1 THEN A ELSE NULL END) SUM_NEGATIIVE
FROM tbl
/SY. -
Query to get the data of all the columns in a table except any one column
Can anyone please tell how to write a query to get the data of all the columns in a table except one particular column..
For Example:
Let us consider the EMP table.,
From this table except the column comm all the remaining columns of the table should be listed
For this we can write a query like this..
Select empno, ename, job, mgr, sal, hiredate, deptno from emp;
Just to avoid only one column, I mentioned all the remaining ( 7 ) columns of the table in the query..
As the EMP table consists only 8 columns, it doesn't seem much difficult to mention all the columns in the query,
but if a table have 100 columns in the table, then do we have to mention all the columns in the query..?
Is there any other way of writing the query to get the required result..?
Thanks..Your best best it to just list all the columns. Any other method will just cause more headaches and complicated code.
If you really need to list all the columns for a table because you don't want to type them, just use something like...
SQL> ed
Wrote file afiedt.buf
1 select trim(',' from sys_connect_by_path(column_name,',')) as columns
2 from (select column_name, row_number() over (order by column_id) as column_id
3 from user_tab_cols
4 where column_name not in ('COMM')
5 and table_name = 'EMP'
6 )
7 where connect_by_isleaf = 1
8 connect by column_id = prior column_id + 1
9* start with column_id = 1
SQL> /
COLUMNS
EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO
SQL> -
Hiding the columns in data table in jsf
Hi Guys,
I have stuck one situation in my project . i.e i want to hide the columns in Data table in jsf.
Please response this mail.
Thanks
NarneSee this...
[http://forum.java.sun.com/thread.jspa?threadID=5119514&messageID=9938606] -
How to get the column name and table name with value
Hi All
I have one difficult requirement
I have some column values and they have given some alias column names but i need to find the correct column name and table name from the database.
For example value is "SRI" and i dont know the table and exact column name so is there any possibilities to find the column name and table name for the given value
Thanks & Regards
Srikkanth.MSearching all the database for a word...
Courtesy of michaels...
michaels> var val varchar2(5)
michaels> exec :val := 'as'
PL/SQL procedure successfully completed.
michaels> select distinct substr (:val, 1, 11) "Searchword",
substr (table_name, 1, 14) "Table",
substr (t.column_value.getstringval (), 1, 50) "Column/Value"
from cols,
table
(xmlsequence
(dbms_xmlgen.getxmltype ('select ' || column_name
|| ' from ' || table_name
|| ' where upper('
|| column_name
|| ') like upper(''%' || :val
|| '%'')'
).extract ('ROWSET/ROW/*')
) t
-- where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
order by "Table"or
11g upwards
SQL> select table_name,
column_name,
:search_string search_string,
result
from (select column_name,
table_name,
'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
from cols
where table_name in ('EMP', 'DEPT')),
xmltable (str columns result varchar2(10) path '.')
TABLE_NAME COLUMN_NAME SEARCH_STRING RESULT
DEPT DNAME es RESEARCH
EMP ENAME es JAMES
EMP JOB es SALESMAN
EMP JOB es SALESMAN
4 rows selected. -
How to find the column name and table name with a value
Hi All
How to find the column name and table name with "Value".
For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
Any help is highly appricatable
Thanks & Regards
Srikkanth.M2 solutions by Michaels (the latter is 11g upwards only)...
michaels> var val varchar2(5)
michaels> exec :val := 'as'
PL/SQL procedure successfully completed.
michaels> select distinct substr (:val, 1, 11) "Searchword",
substr (table_name, 1, 14) "Table",
substr (t.column_value.getstringval (), 1, 50) "Column/Value"
from cols,
table
(xmlsequence
(dbms_xmlgen.getxmltype ('select ' || column_name
|| ' from ' || table_name
|| ' where upper('
|| column_name
|| ') like upper(''%' || :val
|| '%'')'
).extract ('ROWSET/ROW/*')
) t
-- where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
order by "Table"or
SQL> select table_name,
column_name,
:search_string search_string,
result
from cols,
xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
columns result varchar2(10) path '.'
where table_name in ('EMP', 'DEPT')
TABLE_NAME COLUMN_NAME SEARCH_STRING RESULT
DEPT DNAME ES RESEARCH
DEPT DNAME ES SALES
EMP ENAME ES JONES
EMP ENAME ES JAMES
EMP JOB ES SALESMAN
EMP JOB ES SALESMAN
EMP JOB ES SALESMAN
EMP JOB ES PRESIDENT
EMP JOB ES SALESMAN
9 rows selected. -
How I compare the columns of 2 tables
Hi, what's the query I use to compare all the columns of 2 tables, or how I use the result of COLUMN_NAME in the DBA_TAB_COLS?
Tnks for helping...
MnkI have this select:
SELECT D.COLUMN_NAME AS CFINAL
FROM DBA_TAB_COLS D,
(SELECT A.COLUMN_NAME AS C1
FROM DBA_TAB_COLS A
WHERE (A.OWNER LIKE '%TEL_USJ07%' AND
A.TABLE_NAME = 'BOLETOS')) F
WHERE D.COLUMN_NAME = F.C1
AND D.OWNER LIKE '%TEL_USJ07%'
This will return the column's name where tabel_name LIKE BOLETOS.
I want use this result in another select where the table have this columns and more, but I want to see all the results in the second table where the columns came from the first select.
For example: the first select bring to me the columns: cod_tipo_bol and cod_tipo_corte, I want to see in the second select only the results of this 2 columns.
THIS IS THE COLUMNS OF THE SECOND TABLE I WANT TO USE:
cod_tipo_bol
cod_frente_corte
num_carga
cod_caminhao
cod_motorista
lib_numero
cod_enc_frente
cod_div2
cod_div3
cod_div4
bol_data
cod_carregadora1
cod_oper_carreg1
cod_carregadora2
cod_oper_carreg2
cod_colhedora1
cod_oper_colhed1
cod_colhedora2
cod_oper_colhed2
cod_colhedora3
cod_oper_colhed3
cod_trat_reb
cod_oper_trat_reb
cod_trat_transb1
cod_oper_transb1
cod_trat_transb2
cod_oper_transb2
cod_trat_transb3
cod_oper_transb3
cod_julieta_sm_reboque
bol_status
-------- -
How do I sort songs in the iTunes store? You used to be able to click on the column header to sort the column (ie Popularity)?
It seems this is a "backwards" upgrade from Apple in their iTunes 11 release....like you, I used to use that function in the iTunes store to sort through and decide which song version to purchase. (For a large returned list of songs...see all...then sort by any of the headers, including Popularity...this functionality is now gone.)
The iPad always suffered from this...was never able to sort on those same column headers with an iPad. It seems, this new iTunes release killed that functionality on the Mac as well.
Just one of the few things that went wrong with number 11!
Better luck next time, -
Ho do I change the physical order of the columns in a table
I want to change the physical order of the columns in a table, so that I get the expected order when I query like :
select * from <tablename>Hi!
There are different methods of doing that, you can either create a view on that table which will retrieve the columns in the correct order, or you can copy and rename the table using CREATE TABLE AS SELECT ..., or you can use the online table redefinition functionality if your using 10g.
Regards,
Petra -
I am unable to sort multiple columns in a table created in Pages.
I had been using Appleworks up until I installed Lion and have now switched to iWork. I created a table within a Pages document and am able to sort a single column (using the Table Inspector and choosing Sort from Edit Rows and Columns) but the Sort option is grayed out when I attempt to sort multiple columns.
In another post, someone talked about this being a problem if you have merged fields. I do not believe I have done this (to be honest I don't know the function of merging fields).
This is very frustrating as I was easily able to sort these tables in Appleworks.Sharon Anderson wrote:
Thanks for your quick response! I have been trying that but then found that Numbers would only let me print in landscape view so I had to paste the table back into Pages. Is there a way to print in portrat view (from Numbers?)
Not so. In the lower left corner of the window, there's an icon that looks like a piece of paper. If you see this:
you are in Sheet View, or normal, mode. If you see this:
You are in Print View mode. Now you see the icons for portrait and landscape modes. Click your choice. Then arrange your content to fit the pages as you wish.
Jerry -
Unable to sort the records of a table
Hi Experts,
I have populated one z table with records. The table coloumns are as below:
Mandt
Pernr
Personnel Area
Total Points
Rank
I have to sort the table records in descending order of Total Points. In many cases there will be same total points for many records. In such cases we have to arrange records in following fashion:
If more than 1 person have same total points then person having more years of service will have higher rank
If more than 1 person have same total points and same years of service then older people (date of birth) will have higher rank.
I have written following program. It is not working. Please help me. If you have some ready made code, please share with me.
Regards,
Gary
IF NOT itab_prio[] IS INITIAL.
CLEAR v_index.
v_index = 1.
SORT itab_prio BY z_prio_pts DESCENDING .
itab_rank[] = itab_prio[].
LOOP AT itab_prio.
*---Check eligibility.
CALL FUNCTION 'zmy_prg_CHECK_ELIGIBILITY'
EXPORTING
pernr = itab_prio-z_pernr
IMPORTING
return = return.
IF return-type = 'E'.
itab_prio-z_prio_pts = 0.
itab_prio-z_prio = 0.
MODIFY itab_prio TRANSPORTING z_prio_pts z_prio.
ELSE.
LOOP AT itab_rank WHERE z_prio_pts = itab_prio-z_prio_pts
AND z_pernr NE itab_prio-z_pernr.
*---Get Hiring date for same rank.
CALL FUNCTION 'zmy_prg_GET_EMP_HIRING_DATE'
EXPORTING
pernr = itab_rank-z_pernr
IMPORTING
hiring_date = hire_new.
*---Get Hiring date of update emp.
CALL FUNCTION 'zmy_prg_GET_EMP_HIRING_DATE'
EXPORTING
pernr = itab_prio-z_pernr
IMPORTING
hiring_date = hire_old.
IF hire_old = hire_new.
*---Check for Birth date of both employees.
READ TABLE it_date WITH KEY pernr = itab_rank-z_pernr.
IF sy-subrc = 0.
hijri_new = it_date-zzhdob.
ENDIF.
READ TABLE it_date WITH KEY pernr = itab_prio-z_pernr.
IF sy-subrc = 0.
hijri_old = it_date-zzhdob.
ENDIF.
IF hijri_old > hijri_new.
flag = 'X'.
ENDIF.
ENDIF.
ENDLOOP.
IF flag NE 'X'.
itab_prio-z_prio = v_index.
v_index = v_index + 1.
MODIFY itab_prio TRANSPORTING z_prio.
ELSE.
itab_prio-z_prio = v_index.
v_index = v_index + 1.
MODIFY itab_prio TRANSPORTING z_prio.
ENDIF.
ENDIF.
CLEAR : flag , return.
ENDLOOP.
MODIFY zhop_priority_pt FROM TABLE itab_prio.
COMMIT WORK.
IF sy-subrc = 0.
MESSAGE i000(zz) WITH 'sucessfully generated'.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
Please use code tags to format your code
Edited by: Rob Burbank on Sep 29, 2010 1:59 PMGary,
Firstly, to make things easier, I suggest you add service and age columns to your internal table.
Mandt
Pernr
Personnel Area
Total Points
Service
Age
Rank
Does your internal table itab_prio contain large number of rows? Is the code that determines service and age performance intensive? If the answer is 'NO', then I suggest you populate service and age for every row and sort. This will make the logic simple and easy to maintain.
If you must query service and age only when there is a conflict, then following logic should help.
- itab_prio_copy[] = itab_prio[].
- Loop at itab_prio.
- l_next_row = sy-tabix + 1.
- read table itab_prio_copy index l_next_row.
- are points same?
- get service for both the employees.
- is the service same for both?
- get age for both.
- rank accordingly
- endloop.
I know I have skipped a lot of gotcha points. For example, how to handle the last row, how to update the rank to the next row, etc. I am sure you can figure that out.
Good luck. -
Problem with sorting a Column in Advance table .
Dear Friends ,
I have a OAF page developed with advanced table region , the table has several columns, now i would
like to sort a column named "Trial number" which is of the type Number .
To accomplish this i have given Sort Allowed : True (Property Inspector) . but when i click on the sort button
i am unable to sort the record . Could you please some one give me some suggestion and help me out .
Regards,
Keerthi.kNo there is no Transient attribute involved , could you please tell me what might cause this error .
Basically this page is for inserting a record.
Thanks ,
Keerthi
Edited by: user1140193 on Oct 21, 2011 7:15 AM
Edited by: user1140193 on Oct 21, 2011 7:16 AM
Maybe you are looking for
-
Hi, i've been trying to add days to a date with no luck. I have two dates. Date date1= new Date(); Date date2; I want date2 to equal x amount of days from date1. eg. date1 = 6/10/2004 I want date2 to be 4 days from date1 so date2 would be 10/10/2004.
-
Lost WiFi on Ipad 3 with IOS8.2
I lost the wifi connection on my ipad 3 after downlaoding the latest software. Can you advise me on how am I going to sort any problems out if I cannot connect to the internet to be able to download any software updates???
-
Alternate UOM For indirect purchasing
Hello Experts, It is possible to maintain alternative Unit of Measurement for indirect purchasing ie without material master? Our issue is we need to receive Purchase Orders from SRM, where the Int UoM is different from R/3. Commercial unit and ISO C
-
Can anyone please help me to overcome this e-book download error message? It reads: "Error getting License, License Server Communication Problem: E_ADEPT_DOCUMENT_OPEN_ERROR. I would be most grateful.
-
What color space does iPhoto use to import digital photos from a digital camera, if the camera does not embed its own profiles? I read that iPhoto uses Colorsync default settings, but even though I set the RGB space to Adobe RGB1998, the photos seem