Column and table aliases
Hi,
I was wondering if any of you know how to do the following:
I have two tables (A & B).
The columns on these two tables are similar in name in some cases eg: name and visit. So for table A I created an alias such as tb1 and for table2 tb2.
This means now that my fields are referenced as: tb1.name and tb2.name.
Now, I've got that sql code in an INLINE VIEW. I want to now reference those inline columns, how do I do it?
I've got this as an example and would like to know if someone can shed some light on this:
select re.name,re.visit from (select tb1.name,tb2.name,tb1.visit from table1 tb1, table2 tb2 where some_criteria_here) re
where rownum <10;
Thanks for your help.
-J
Just give those two name columns aliases in the inline view:
select name1, name2, visit
from (select tb1.name name1, tb2.name name2, tb1.visit
from table1 tb1,
table2 tb2
where some_criteria_here)
where rownum < 10;I'm assuming there is an order by clause in that inline view that you are not showing here - that is the only reason you would need to use an inline view, otherwise it should just be:
select tb1.name name1, tb2.name name2, tb1.visit
from table1 tb1,
table2 tb2
where some_criteria_here
and rownum < 10;
Similar Messages
-
Exporting column and table comments
I need to be able to create an external "data dictionary" to show to database users. I am currently exporting to a reporting schema, and then writing SQL against the reporting schema to get table, column, datatype, etc... information. I also need to be able to get the column and table comments that I entered into data modeler. I can't find those anywhere in the reporting schema. Are they included in the reporting schema? If not, how do I export those comments from data modeler?
Thanks,
JonathanThat's perfect. Thanks!
For anyone interested, here is my "Data dictionary" select statement from the exported reporting schema:
select table_name, sequence as seq, column_name, cast(ccom.text as varchar2(4000)) as description,
native_type as column_type,
case when native_type='NUMBER' then t_precision when native_type='DATE' then null else t_size end column_length,
cast(cnote.text as varchar2(4000)) as valid_values,
mandatory as required,
case when native_type='DATE' then 'DATE' else native_type||'('||case when native_type='NUMBER' then t_precision else t_size end||')' end column_spec
from dmrs_columns, (select * from dmrs_large_text where type='Comments') ccom, (select * from dmrs_large_text where type='Note') cnote
where dmrs_columns.ovid = ccom.ovid (+)
and dmrs_columns.object_id = cnote.ovid (+)
order by table_name, sequence -
How to know columns and table name whose column size are modified
Hi guys
I want to know which all columns in the tables are modify
i.e. list of columns and table name whose column size are modified
Step1 :
CREATE TABLE employees
( employee_number number(5) ,
employee_name varchar2(50) ,
department_id number(10)
CREATE TABLE Supplier
( Supplier_number number(5) ,
Supplier_name varchar2(50) ,
CREATE TABLE customers
( customer_id number(10) not null,
customer_name varchar2(50),
address varchar2(50),
city varchar2(50),
state varchar2(25),
zip_code varchar2(10),
Step2 :
Alter table employees
MODIFY employee_number number(10)
ALTER TABLE supplier
MODIFY supplier_name varchar2(100)
step3
query to dispaly
columnname table name
employee_number employees
supplier_name supplier
How to know columns and table name whose column size are modified
could you please provide query
Thanks in Advance09:35:50 SQL> desc dba_objects
Name Null? Type
OWNER VARCHAR2(30)
OBJECT_NAME VARCHAR2(128)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_ID NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED DATE
LAST_DDL_TIME DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
NAMESPACE NUMBER
EDITION_NAME VARCHAR2(30)LAST_DDL_TIME can be utilized -
Hi,
I need to find out that '101c_0000000018' value is which column and table of database.
Is there a way to find it? I am looking for table and column which is storing this data.
Thanks
SandyIt's possible but performance is going to be horrible.
Assuming the data is stored in a CHAR or VARCHAR2 column, something like
DECLARE
l_value VARCHAR2(100) := '101c_0000000018' ;
l_cnt PLS_INTEGER;
l_sql VARCHAR2(1000);
BEGIN
FOR x IN (
SELECT table_name, column_name
FROM dba_tab_cols
WHERE owner = <<name of schema>>
AND data_type IN ('CHAR', 'VARCHAR2' )
LOOP
l_sql := 'SELECT COUNT(*) FROM ' || x.owner || '.' || x.table_name || ' WHERE ' || x.column_name || ' = :1';
EXECUTE IMMEDIATE l_sql
INTO l_cnt
USING l_value;
IF( l_cnt > 0 )
THEN
dbms_output.put_line( 'Found the value ' || l_value || ' in owner = ' || x.owner || ' table name = ' || x.table_name || ' column name = ' || x.column_name );
END IF;
END LOOP;
END;Justin
Edited by: Justin Cave on Dec 8, 2011 12:20 PM -
How to find the columns and tables used in a stored procedure?
Hi,
Can someone suggest how to find the columns and tables used within a stored procedure?
Thanks
VBKFor example:
SQL> create or replace
2 procedure p1
3 is
4 cnt number;
5 begin
6 select count(*) into cnt from emp;
7 end;
8 /
Procedure created.
SQL> select referenced_owner,
2 referenced_name
3 from dba_dependencies
4 where owner = 'SCOTT'
5 and name = 'P1'
6 and referenced_type = 'TABLE'
7 /
REFERENCED_OWNER REFERENCED_NAME
SCOTT EMP
SQL> SY. -
How to add a comment on column and table
I would like to have a comment for each column, I know this is possible in oracle we can have comment for each column.
can I have the same in SQL Server, can you provide me a simple example.
I created a table as in attached screen, and tried using the extended properties, to do this. however I've few questions
1. How can I retrieve this info using query
2. here in point 4 of attached image I see Name and Value, do I have to give name and value for each column
3. Do I have to rt click each column and go and update this info their, I have a table with 100+ column :(
Thanks!
NeilI saw these examples below, however how to associate and see them this to a table and a column?
exec sp_addextendedproperty
@name = ‘SQL Server Rider’,
@value = ‘This is a test’
GO
2. Updating extended property
exec sp_updateextendedproperty
@name = ‘SQL Server Rider’,
@value = ‘Property Updated’
GO
3. Delete extended property
exec sp_dropextendedproperty
@name = ‘SQL Server Rider’
GO
select * from fn_listextendedproperty(null,null,null,null,null,null,null)
NO Records output
Neil -
Hi Experts,
I just want to ask is there any procedure to know the table name and the corrosponding column name when you have only data with you.
Suppose you have a string say "India". Now i want to know the name of the column and corrosponding tablename
which holds the value "India".
Thanks
RajatSolutions previously provided by 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
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. -
Translation of Columns and Table Names
Hi,
We are starting a large migration project and we have a mix of dutch and english developers.
I was wondering if there is any clever ways to translate column names and table names.
Not physically translate the text but store the english column name against the dutch column name?
I know I could write a view which overlays the table with the english version but I was wondering if there was something a bit cleverer?
Anyway to store multiple meta data against a physical table?
Thanks
RichardI'd tend to agree with Nicolas that you'd generally want all the developers to agree on what a particular object was called rather than having half of them think of it in Dutch and half in English.
On the other hand, it would make sense to me that the comments you create on your objects and tables should be multilingual, i.e.
SQL> create table my_emp (
2 name varchar2(100)
3 );
Table created.
SQL> comment on table my_emp is 'Table containing employee information.
2 Lijst die werknemersinformatie bevat.';
Comment created.(The translation is from babelfish.yahoo so I apologize if it butchers the Dutch).
The developers should be able to see the table and column comments in their IDE of choice and should be able to see what the object represents in their language.
Justin -
'Exists in Hierarchy' column and table name
Hi All
In Position hierarchy form .we all find exists in hierarchy flag ..when checking for
hierarchies , can any one help me ..what is the table and column name which will tell whether position exists in hierarchy or notHi,
I doubt where the exists flag is stored.
But you can derive it very easily by checking the position_id exists in (SUBORDINATE_POSITION_IS or PARENT_POSITION_ID) in table PER_POS_STRUCTURE_ELEMENTS for given structure_id.
Hope it helps.
Thanks,
Sanjay -
Blanks, spetial characters in column and table names
Is there any posibility, which i have overseen to change the sugested table and column names to something with mixed case, blanks, spetial characters, which often occurs in the MS World. It's uggly but 1000 times better then rewriting code, or changing create table scrips like this:
CREATE TABLE "BDProjection"
"ID" NUMBER(11) DEFAULT 0 NOT NULL,
"Name" VARCHAR2(4000),
"Semi-major axis" NUMBER(20,5) DEFAULT 0,
"Semi-minor axis" NUMBER(20,5) DEFAULT 0,
"Latitude origin" NUMBER(20,5) DEFAULT 0,
"Longitude" NUMBER(20,5) DEFAULT 0,
"False easting" NUMBER(20,5) DEFAULT 0,
"False northing" NUMBER(20,5) DEFAULT 0,
"Scale factor at origin" NUMBER(20,5) DEFAULT 0,
"scale Coords" NUMBER(11) DEFAULT 0,
"default" NUMBER(1) DEFAULT 0,
"MinEasting" NUMBER(20,5) DEFAULT 0,
"MaxEasting" NUMBER(20,5) DEFAULT 0,
"MinNorthing" NUMBER(20,5) DEFAULT 0,
"MaxNorthing" NUMBER(20,5) DEFAULT 0
This may be a sugestion for a future relaese.
UweTo query your table, as is:
SQL> SELECT *
2 FROM cst_customer
3 WHERE "#_CUST" = 10030;
To get rid of the #'s in the column names of your table:
SQL> CREATE TABLE new_cst_customer
2 AS
3 SELECT "#_CUST" no_cust,
4 "#_PH_BUS" no_ph_bus,
5 "#_PH_HOME" no_ph_home,
6 n_cust_surname
7 FROM cst_customer;
Table created.
SQL> DROP TABLE cst_customer;
Table dropped.
SQL> CREATE TABLE cst_customer
2 AS
3 SELECT *
4 FROM new_cst_customer;
Table created.
Then, you can query your table as follows:
SQL> SELECT *
2 FROM cst_customer
3 WHERE no_cust = 10030;
You will need to recreate any constraints associated with the table and recompile any procedures, functions, triggers, and packages associated with the table, and change any code to use the new column names. It would be a good idea to make a list of all the changes to be made and make a backup copy of the table before you start. In your code, just replace all #_ with no_. If you are just getting started, it would be worth your while to make the changes now and save a lot of hassles later. If you have a lot of dependencies, it might be better just to use the quotes everywhere. I have seen posts by someone else with a similar situation and everything he tries to do has to be done specially because of it; Creating a simple procedure becomes "procedure agony".
null -
Column and table formatting challenges
Am switching form microsoft word to pages and experiencing some challenge:
1.
how do I format specific text only to be in 2,3 or 4 columns but not the entire page?
2.
how do I insert a table in a table cell, or text box in a table cell, or if that's possible how do I format specific text in a table cell (not everything) to display over 2 columns? I remember doing all of this formatting manually back in the days of wordstar for DOS, and pages 09 ought to offer some improvement I would hope.sgendry wrote:
Am switching form microsoft word to pages and experiencing some challenge:
1. how do I format specific text only to be in 2,3 or 4 columns but not the entire page?
+Menu > Insert > Layout Break+
…before and after the change
2. how do I insert a table in a table cell,
Can't
or text box in a table cell
Can't
or if that's possible how do I format specific text in a table cell (not everything) to display over 2 columns?
Click in a cell:
+Inspector > Table > Table > Edit Rows & Columns > Split row/Column+
I remember doing all of this formatting manually back in the days of wordstar for DOS, and pages 09 ought to offer some improvement I would hope.
You can use tabs. Pages is mostly simpler than Word, with some extra features, and a whole lot cheaper. There is some comfort that Pages can do things that Word can't and in some cases, not all, do the same tasks simpler.
Peter -
JKM DB2 400 column and table name 10 character limit
I am trying to set up CDC on an iSeries. I have successfully loaded data with the LKM SQL to Oracle, and now I want to set up CDC for the table and am trying to use "JKM DB2 400" . I get invalid token errors when I try to start journalizing, and it appears to be the table and column names, used to set up CDC, which are more than the 10 character limit. Tables like SNP_JRN_SUBSCRIBER seem to come from the getJrnInfo function and other table and column names are hard coded. I want to copy the JKM and reduce all of the names to less than 10 characters.
Where else are these names used? How does the interface know which table names to use when set to use only journalized data and how can I change it to use the new shorter names? Is there a better solution?Thanks to all for assistance. It turns out that the 10 character limit, about which the server people warned me, isn't an issue with my ODBC connection. The invalid token error was being caused by some missing qualifiers in the generated sql which caused appearances of ".tablename" rather than "tablename" and other similar. I was able to modify the knowledge module to eliminate this issue and the CDC worked correctly on my first test.
-
Hello All,
I need to know the new created tables on my database and the added columns:
I used the below query so i can get the NEW created tables
select * from dba_objects d where to_date(d.created,'dd/mm/yyyy') = to_Date(sysdate-1,'dd/mm/yyyy') and d.object_type = 'TABLE'and owner = 'MyOwner';
Is there any way to know what are the new added columns to a table, in the below i can know the last DDL, but what i need is to know the added colums
select * from dba_objects d where to_date(d.Last_Ddl_Time,'dd/mm/yyyy') = to_Date(sysdate -1 ,'dd/mm/yyyy') and owner = 'MyOwner';
Thanks in Advance.consider:
SQL> alter system set audit_trail='db_extended' scope=spfile;
System altered.
SQL> startup force
ORACLE instance started.
Total System Global Area 431038464 bytes
Fixed Size 1375088 bytes
Variable Size 301991056 bytes
Database Buffers 121634816 bytes
Redo Buffers 6037504 bytes
Database mounted.
Database opened.
SQL> audit alter table;
Audit succeeded.
SQL> conn ami/ami
Connected.
SQL> create table a as select * from dual;
Table created.
SQL> alter table a add b date;
Table altered.
SQL> select sql_text from dba_audit_trail where sql_text is not null;
SQL_TEXT
alter table a add b dateAmiel Davis -
Row-level Security Filters applied to Columns and Tables only? no Areas?
Good day all,
Just quick question (obiee 10.3.3.2) - Is there a way to edit row-level security using Whole subject areas (instead of bringing in the individual Fact tables and applying filters by copying/pasting them).
Follow up question - if I have nested facts in presentation layer (ones preceding with "-" - do I specifically add them to conditions, or would they be inherited by only including parent fact)?
Thanks!
Message was edited by:
wildmightI'm not sure how that would help; by using the Faculty_ID Session Variable I can identify the CRN and Term of all courses a faculty member is teaching. But I don't think that has to do with the problem I am having?
-
Referencing table-aliased column names in JDBC
We are attempting to port an application from MySQL to Oracle 8i, using JDBC as the database connection technology. The app has SQL statements using joins, e.g.
SELECT A.*, B.* FROM table1 A, table2 B WHERE A.field1=B.field2 etc
Often the tables have columns sharing the same name, so the table alias is required to avoid ambiguity (e.g. both tables have column ID, so they must be referenced as A.ID or B.ID).
When using MySQL, the Java code
String strField = rset.getString( "SURNAME" );
or
String strField = rset.getString( "A.SURNAME" );
both succeed if the column name is unique, and if it is not unique, only the second form works. However, with Oracle, the second form never works, even though the column name is a valid column in the table aliased as A. Providing the whole table name does not work either:
String strField = rset.getString( "table1.SURNAME" );
If the Oracle JDBC driver does not support the {table-alias}.{column-name} syntax, then presumably the only way to reference ambiguous columns in joins is to supply the column number instead. (e.g. getString( 14 )). Our application generates dynamic SQL, and having to do this would be a MAJOR problem.
We are currently using Oracle 8i - might this have been fixed in the move to 9i?
Many thanks for any help,
Steve Francis,
London, UK.Can't do it by alias, as you would just repeat the
calculation/function/whatever and add whatever additional "stuff"
to create your new column.
ISNULL(row1, 99999) AS ideal,
ISNULL(row1, 99999)+10 AS newideal
etc.
Phil
Maybe you are looking for
-
How to pass and work with a PL/SQL or Temp table in a Procedure?
My problem is that I have a query that involves about 10 tables or so, but everything starts from one base table. I am trying to split the base table so that the query actually finishes. Problem Query: with base_table as select * from table_a , t1 as
-
Can I use sprites on images in Flash?
Hi, I'm designing a calculator-like application in Flash for a school IT project. I made the layout in photoshop, and want to lay out the buttons with sprites (was just on CSS so addicted to those things xD ). I've tried googling and have found somet
-
I can't get the send button in iMessages to work
iMessages was working well when I bought my iPad in February. Now the send button stays down and I have to reset iMessages every time I want to use it, and then I can only send one message . Does anyone have any ideas on what it's wrong?
-
Severely problem with SUN HBA card SG-XPCI2FC-QF4 installation
Hello: I'm facing a big problem when installation SUN HBA card,the machine can't recognise the HBA card when poweron with HBA installed, my system is: Server: SUN V890, Solaris 10 HBA: SG-XPCI2FC-QF4 I changed another HBA card and I/O solt,the proble
-
Velocity control, DC motor
Hi, Please refer to my attachment, may I ask how to convert my output variable (after coming out from pid vi and marked by biggest arrow) to PWM Duty Cycle duration? The scaling I have done doesn't seem correct. [This code is modified from the 9505