Rename a column in query
Hello,
I want to rename a column in a query. What are the possible method?
1. We use "AS" to rename.
E.g.
SQL> select sysdate as "Today's date" from dual;
Today's d
12-JUN-07
The above query returns "Today's Date". But the column name in the result set is not colplete "Today's Date" Why?
Thanks.
It' because SQL*Plus truncates it, try this
col "Today's date" on format a12
SQL> select sysdate as "Today's date" from dual;
Today's date
12-JUN-07
Regards,
PP
Message was edited by:
porzer
Similar Messages
-
Can we rename a column in Oracle 8.1.7.4 version?
Can we rename a column in Oracle 8.1.7.4 version?
Hi,
There is no direct way of doing it but if you have DBA access then try this: (these 2 tables are in SYS user)
SELECT obj#
FROM obj$
WHERE name = 'your table name';
SELECT col#
FROM col$
WHERE obj# = obj# from above query
AND name = 'your column name';
UPDATE col$
SET name = 'new column name'
WHERE obj# = obj# from first query
AND col# = col# from above query;
And this change might not be immediately visible.
So once you are done with above, run the following:
ALTER SYSTEM FLUSH SHARED_POOL;
Then go to the respective user and describe the table and you will see new name. There might be some mistake in the above queries as I could not test it because I don't have ORACLE on my current system.
Hope this helps.
Regards
-Rajeev -
i cannot rename a column in a table;
i tried so many sql statements but with no results;
i use the following:
alter table tablename rename column old_column to new_columnname;In other case you can create a view on that table to rename the columns like
SQL> select empno, ename, job from scott.emp;
EMPNO ENAME JOB
7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
7566 JONES MANAGER
7654 MARTIN SALESMAN
7698 BLAKE MANAGER
7782 CLARK MANAGER
7788 SCOTT ANALYST
7839 KING PRESIDENT
7844 TURNER SALESMAN
7876 ADAMS CLERK
EMPNO ENAME JOB
7900 JAMES CLERK
7902 FORD ANALYST
7934 MILLER CLERK
14 rows selected.
SQL> create or replace view emp_vw as select empno as emp_no, Ename as Employee_Name, job from scott.emp;
View created.
SQL> select * from emp_vw;
EMP_NO EMPLOYEE_NAME JOB
7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
7566 JONES MANAGER
7654 MARTIN SALESMAN
7698 BLAKE MANAGER
7782 CLARK MANAGER
7788 SCOTT ANALYST
7839 KING PRESIDENT
7844 TURNER SALESMAN
7876 ADAMS CLERK
EMP_NO EMPLOYEE_NAME JOB
7900 JAMES CLERK
7902 FORD ANALYST
7934 MILLER CLERK
14 rows selected.
SQL> -
How to rename a column name in a table? Thanks first!
I tried to drop a column age from table student by writing the
following in the sql plus environment as :
SQL> alter table student drop column age ;
but I found the following error
ORA-00905: 缺少关键字 (Lack of Key word)
I have oracle enterprise edition 8.0.5 installed at windows 2000
thank you
And I want to know how to rename a column name in a table?
thanksIn Oracle 8i, your syntax would have worked. However, if I
recall correctly, in Oracle 8.0, you can't rename or drop a
column directly. One way to get around that problem is to
create another table based on a select statement from your
original table, providing the new column name as an alias if you
want to change the column name, or omitting that column from the
select statement if you just want to drop it. Then drop the
original table. Then re-create the original table based on a
select statement from the other table. Then you can drop the
other table. Here is an example:
CREATE TABLE temporary_table_name
AS
SELECT age AS new_column_name,
other_columns
FROM student
DROP TABLE student
CREATE TABLE student
AS
SELECT *
FROM temporary_table_name
DROP TABLE temporary_table_name
Something that you need to consider before doing this is
dependencies. You need to make a list of all your dependecies
before you do this, so that you can re-create them afterwards.
If there are a lot of them, it might be worthwhile to do
something else, like creating a view with an alias for the
column or just providing an alias in a select. It depends on
what you need the different column name for. -
How to rename the column name in oracle 8i?
hi,
Does anyone know how to rename the column name in oracle 8i?My method was drop the relationship key first then delete the old column,finally add the new column.
Thanks for your replay.
jingThere is no facilty to rename a column name in Oracle 8i. This is possible from Oracle 9.2 version onwards.
For you task one example given below.
Example:-
Already existed table is ITEMS
columns in ITEMS are ITID, ITEMNAME.
But instead of ITID I want ITEMID.
Solution:-
step 1 :- create table items_dup
as select itid itemid, itemname from items;
step 2 :- drop table items;
step 3 :- rename items_dup to items;
Result:-
ITEMS table contains columns ITEMID, ITEMNAME -
Hi There
Please advice me how to create a blank column in Query?
Thanks in advance..
Regards,
Chandu.Hi
I don't have any IO's regarding that.I just need create a column with some description then user can fill with data.
How can i run that?
Thanks in advance.
Regards,
Chandu. -
dear friends,
Is there any other way to rename a column without creating another table with the requested colum name and dropping the eariler table after inserting the values from it.SQL> desc t2
Name Null? Type
ID2 NUMBER
SQL> alter table t2 rename column id2 to id;
Table altered.
SQL> desc t2
Name Null? Type
ID NUMBERRgds.
...but don't forget side effects !
SQL> create or replace view v2 as select id from t2;
View created.
SQL> select status from user_objects where object_name = 'V2';
STATUS
VALID
SQL> alter table t2 rename column id to id2;
Table altered.
SQL> select status from user_objects where object_name = 'V2';
STATUS
INVALID
SQL> select * from v2;
select * from v2
ERROR at line 1:
ORA-04063: view "SCOTT.V2" has errorsMessage was edited by:
dnikiforov -
The issue with using the multiple columns sub-query in WHERE clause
Hi All,
my database version is 10.2.
the problem i am trying to deal with is that when I use multiple column sub-query in the WHERE clause of the SELECT statement, the actual row number returned from the sub-query is different from the whole statement.
And what I found is that, whenever there is NULL in any of those columns returned from the SUB-QUERY, the outer query will just return NULL for that whole row.
Here is an example:
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job, mgr, hiredate, sal, deptno from t;
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT NULL 17-NOV-81 5000 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10
select * from EMP where (EMPNO, ENAME, job, MGR, HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job, mgr, hiredate, sal, deptno from t);
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10 If I specifically deal with the NULL situations for the columns which might return NULL, I can get the result right.
select * from EMP where (EMPNO, ENAME, job, NVL(MGR,-1), HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from EMP
intersect
select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from t);
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT null 17-NOV-81 5000 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10 the problem is that, I feel this is a very lame way of handling it.
So, I wonder or am asking if there is any better or standard way to do it?
any help would be highly appreciated.
ThanksHi,
As you discovered, INTERSECT treats NULL as a value, but IN does not.
What you did with NVL is one way to handle the situation. If there was a chance that any of the columns could be NULL, then you might prefer something like this:
select *
from EMP
where ( EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
) in (
select EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
from emp
intersect
select EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
from t
);This assumes that you can identify some string (I used '~') that never occurs in the strings in these tables.
This is implicitly converting the NUMBERs. That's usually not a good thing to do. but explicitly converting them would make this even more tedious.
You should explicitly convert any DATEs to strings, however. Depending on your default format, and your data, you might get away with implicit conversions even for DATEs, but don't bet on it.
If you had to do this often, you might consider writing a user-defined function:
delimited_string (empno, ename, job, mgr, hiredate, sal, deptno) would return a string like
'7839~KING~PRESIDENT~~17-NOV-1981~5000~10'
This will make the coding easier, but beware: it will make the execution slower. -
Rename the column names in Embedded BPM Worklist
Hi,
I have embedded the BPM worklist in ADF Page.
My requirement is to rename the column names in the task list.
For example, the column 'state' should be renamed as 'Status' and the column 'from User' should be renamed as 'From'.
Is there any possibility to achieve this? Please let me know.
Regards,
TamilSee if the solution in this post helps -
Re: Customize workspaceAlso , its better to post these questions in the BPM forum -
Business Process Management SuiteEdited by: Sudipto Desmukh on Apr 27, 2012 8:57 AM -
Can we rename a column in a table ?
I am faced with a situation where I need to rename the column in a particular table. The version of Oracle is 8.1.7.2.0
Is there a DDL clause for renaming a column, or does it have to be done the conventional way - drop the column ( you want to rename ) and add a new column (with new name) ?Direct column renaming is not available unti 9iR2. Prior to that, yes, you need to:
1) Add a column with the new name
2) Update new column with old column data
3) Drop old column -
Using FK: 0balance
I need to create a Column in Query to return the following
Full Year Forecast
Forecast to the end of the financial year, variable dependent on plan selected (Q1,2,3 or 4). If select Q2,3, or 4 then use Actual figures for months until the start of the plan. Eg if select Q2 then full year forecast will be Actual for April, May and June plus Forecast for July to March.
Anyone have any ideas please?
thanksHi Smith,
You can follow following approach.
1. Create 2 KF's (KF1 & KF2) one for actual & other for Forcast (using restriction - Plan/Actual & for Quarter / Month).
2. Use variables , say VAr1 & VAR2 (with Customer Exits) to populate values for Month/Quarter (for characteristic used in restriction in step 1) .
3. Value for variables in step 1 will be populated based on value entered for variable VAR3 (this is for user entry Q1,2,3,4).
4. Create KF3 as KF1+KF2.
Regards
SS -
Java.sql.SQLException: Invalid column index Query: while using ROWNUM
hi ,
i am getting the invalid column index query error while executing following query .i m able to run it properly without using rownum but when i append rownum i m getting error.i m using apache queryrunner for execution of query.
java.sql.SQLException: Invalid column index Query: select * from (
SELECT
TO_CHAR(A.REQ_FOR_RATING_ID) RFQID,
TO_CHAR(F.COV_PLAN_ID) COVPLANID,
B.FIRM_NAME FIRMNAME,
B.PRIMARY_ZIP_CD ZIP,
A.PRODUCR_CD PRODUCERCD,
A.PRODUCR_NAME PRODUCER,
H.COV_NAME COVDESP,
C.SALE_OFFC_CD SALEOFFCCD,
C.USR_OFFC_NAME USROFFC,
C.USR_NAME USR,
C.USR_REP_CD USRREPCD,
to_char((SELECT TO_CHAR(COUNT(EMP_NBR)) COUNT FROM ROSTR_DATA WHERE ROSTR_ID = F.ROSTR_ID)) AS count,
TO_CHAR(B.SIC_CD) SICCD,
F.INDSTRY_TYPE_IND INDTYPEIND,
TO_CHAR(F.MANL_SIC_FCTR_NBR) MANSICFACTOR,
TO_CHAR(F.UW_OVERD_SIC_FCTR_NBR) UWOVERDSICFACTOR,
TO_CHAR(G.AREA_FCTR_NBR) STRAREAFACTOR,
G.COV_ID COVID,
F.PLAN_APPRVL_STATUS_CD PLANAPPRVLCD,
F.PLAN_PROGRS_STATUS_CD PLANPROGRESSSTATUSCD ,
F.PLAN_SALE_ASSMNT_CD PLANSALEASSMTCD,
F.CREATD_DT CREATEDDT,
NVL(to_char(F.PLAN_RELSED_DT),' ') PLANRELSEDDT,
TO_CHAR(F.PLAN_RELSED_BY_ID) PLANRELSEDBYID,
TO_CHAR(F.PROPOSD_EFF_DT) PROPOSDEFFECTIVEDT,
TO_CHAR(A.GRACE_PERIOD_NBR) GRACEPERIOD,
A.RNWL_15_MONTH_IND FIFTEENMONTHRNWLIND ,
I.CO_DESC_TXT COMPANYNAME ,
NVL(to_char(F.PLAN_APPRVL_DT),' ') approvedDt,
(Select U.USR_NAME from USR_DETL U WHERE U.USR_ID = F.PLAN_RELSED_BY_ID) as planRelsedByName,
(Select U.USR_NAME from USR_DETL U WHERE U.USR_ID = F.PLAN_APPRVR_ID) as approvedByName,
'' createdByName,
ROWNUM rnum
FROM
REQ_FOR_RATING A,
FIRM B,
USR_DETL C,
SALE_OFFICE D,
QUOTE_SCENRIO E,
QUOTE_COV G,
COV_PLAN F,
COV_LKUP H,
CO_LKUP I
WHERE
A.FIRM_ID = B.FIRM_ID AND
A.SALE_REP_ID = C.USR_ID AND
C.SALE_OFFC_CD = D.SALE_OFFC_CD AND
A.REQ_FOR_RATING_ID=E.REQ_FOR_RATING_ID AND
E.QUOTE_SCENRIO_ID=G.QUOTE_SCENRIO_ID AND
G.QUOTE_COV_ID=F.QUOTE_COV_ID AND
G.COV_ID=H.COV_ID AND
I.CO_CD = F.CO_CD AND
TO_CHAR(F.CREATD_DT,'YYYYMMDD') > TO_CHAR(TO_DATE('07/16/2007', 'MM/DD/YYYY HH24:MI:SS'),'YYYYMMDD') AND
TO_CHAR(F.CREATD_DT,'YYYYMMDD') < TO_CHAR(TO_DATE('10/16/2007', 'MM/DD/YYYY HH24:MI:SS'),'YYYYMMDD')
and rownum <=?) where rnum >=? Parameters: [07/15/2007 00:00:00, 10/15/2007 23:59:59, 1117, 1]That's a SQL fault, not a JDBC/Java fault.
-
Hi all,
I have a table employee with columns
'employee_id',
'employee_name'
' employee_city' ( Note the spaces before the column name )
The table is created successfully.
But i cant to able to retreive the data by specifying the column name..
eg: select employee_city from employee.
It throws an error.
Please send me a solution to reanme the column name, so that it should not contain any spaces at start & end.
Thanks & Regards,
Hariharan STObviously the table was created this way:
SQL>create table testtab
"employee_id" number,
"employee_name" varchar2(100),
" employee_city" varchar2(100)
Table created.
SQL>desc testtab
Name Null? Type
employee_id NUMBER
employee_name VARCHAR2(100)
employee_city VARCHAR2(100)Note the double quotes: Columns that are created this way can only be selected using double quotes, too:
SQL>select employee_city from testtab;
select employee_city from testtab
ERROR at line 1:
ORA-00904: "EMPLOYEE_CITY": invalid identifier
SQL>select " employee_city" from testtab;
employee_city
Chicago
SQL>This of course is a very bad idea. Dave already showed you how to rename the columns.
Regards,
Gerd -
Hi All,
Can rename a column name permanantly.?
Please clarifyYes. It is possible
alter table some_table rename column column_name to new_column_name;
Regards
K.Rajkumar -
Odi REVERSE ENGINEERING AFTER RENAMING A COLUMN.
hi,
i have altered the table definition .
i have just renamed the columns name .
now when i reverse engineer , the model contains new as well old columns.
is there any way by which i can rename existing columns to the new one.No. You cannot.
ODI doesnt know what your intentions were with the column renames.
It doesnt remove the columns during reverse engineering that dont exist in the database because the columns in ODI maybe used in the mappings.
The only way you can do is by doing it manually in ODI by renaming them
Maybe you are looking for
-
HT201250 Time Machine freezes and screens are blank.
I recently upgraded my mid-2007 iMac to Mavericks. I determined it was a mistake due to system slowness and hangs. I'm trying to recover from backup but when using the command-R option for recovery, the systems hangs after I select the drive where T
-
Where to call the BOR objects in the wokr flow builder
where do we call the BOR objects in the workflow builder suppose we need to trigger the even bus7015 or some thing like that in the workflow to find if the manger is terminated or not where do we call a bor object in work flow.
-
Hi Experts, I am Doing IDoc to File Scenario. If i send an idocs sometimes file is get created in target directory and sometime it is not. i checked in SXMB_MONI, for failed messages in Q.Status column a "stop" symbol with red colour is displaying .
-
Adobe Download Assistant log in CFC help!
Whenever I try to log in, it says, "Unable to invoke CFC - the user is not currently authorized to invoke this method." What does this mean? What is a CFC? How can I become authorized?
-
Hi, I have the following query SELECT tab1.id,tab1.hour,AVG(TO_DATE(TO_CHAR(max(tab1.date), 'mm/dd/yyyy hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') - TO_DATE(TO_CHAR(MIN(tab2.date), 'mm/dd/yyyy hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss')) * 24*60*60 avg_second