Resolve column names in a sql Query
Hi Folks,
I’m upgrading an application and there are database columns that have major changes that could affect production reports. I would like to survey v$SQL for a few days to see if these columns are affected. Here’s the problem.
Looking at a SQL query to determine which columns are used is not nearly as easy as it sounds. Are there any oracle functions or 3rd party tools that can be used to list the columns used by a sql query? (this gets extremely tricky when subqueries become involved)
For instance.
select
name, b.dep_id, employee_id
From emp a
Inner join v_department b on a.dep_id=b.dep_id
Columns used:+
Emp.name+
Departments.dep_id (under the view)+
Emp.employee_id+
Emp.dep_id (from the join)+
If you're on > 10g, you can use dbms_xplan with "all" option.
It shows "column projection information" which is exactly what you want.
UKJA@ukja102> set serveroutput on
UKJA@ukja102>
UKJA@ukja102> drop table t1 purge;
Table dropped.
Elapsed: 00:00:00.03
UKJA@ukja102> create table t1(c1 int, c2 int);
Table created.
Elapsed: 00:00:00.03
UKJA@ukja102>
UKJA@ukja102> explain plan for
2 select
3 t1.c1, t1.c2, v.cnt
4 from t1,
5 (select /*+ no_merge */ c1, count(*) as cnt
6 from t1
7 group by c1) v
8 where
9 t1.c1 = v.c1
10 ;
Explained.
Elapsed: 00:00:00.01
UKJA@ukja102>
UKJA@ukja102> @plan_all
UKJA@ukja102> select * from table(dbms_xplan.display(null,null,'all'))
2 /
PLAN_TABLE_OUTPUT
Plan hash value: 536125944
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 52 | 6 (34)| 00:00:01 |
|* 1 | HASH JOIN | | 1 | 52 | 6 (34)| 00:00:01 |
| 2 | TABLE ACCESS FULL | T1 | 1 | 26 | 2 (0)| 00:00:01 |
| 3 | VIEW | | 1 | 26 | 3 (34)| 00:00:01 |
| 4 | HASH GROUP BY | | 1 | 13 | 3 (34)| 00:00:01 |
| 5 | TABLE ACCESS FULL| T1 | 1 | 13 | 2 (0)| 00:00:01 |
Query Block Name / Object Alias (identified by operation id):
1 - SEL$1
2 - SEL$1 / T1@SEL$1
3 - SEL$2 / V@SEL$1
4 - SEL$2
5 - SEL$2 / T1@SEL$2
Predicate Information (identified by operation id):
1 - access("T1"."C1"="V"."C1")
Column Projection Information (identified by operation id):
1 - (#keys=1) "T1"."C1"[NUMBER,22], "T1"."C2"[NUMBER,22],
"V"."CNT"[NUMBER,22]
2 - "T1"."C1"[NUMBER,22], "T1"."C2"[NUMBER,22]
3 - "V"."C1"[NUMBER,22], "V"."CNT"[NUMBER,22]
4 - (#keys=1) "C1"[NUMBER,22], COUNT(*)[22]
5 - "C1"[NUMBER,22]
Note
- dynamic sampling used for this statement
40 rows selected.
Elapsed: 00:00:00.01
UKJA@ukja102>
UKJA@ukja102>
UKJA@ukja102> @end
UKJA@ukja102> set echo offDion Cho
Similar Messages
-
Setting Column Names in Dynamic Pivot Query
Hi all,
I'm having trouble setting column names in a dynamic pivot query and was wondering if someone could please help me figure out what I need to do.
To help you help me, I've setup an example scenario in my hosted account. Here's the login info for my hosted site at [http://apex.oracle.com]
Workspace: MYHOSTACCT
Username : DEVUSER1
Password : MYDEVACCTAnd, here is my test application info:
ID : 42804
Name : dynamic query test
Page : 1
Table 1: PROJECT_LIST (Alias = PL... Listing of Projects)
Table 2: FISCAL_YEAR (Alias = FY... Lookup table for Fiscal Years)
Table 3: PROJECT_FY (Alias = PF... Intersection table containing project fiscal years)
Table 4: PROJECT_FY_HEADCOUNT (Alias = PFH... Intersection table containing headcount per project and fiscal year)Please forgive the excessive normalization for this example, as I wanted to keep the table structure similar to my real application, which has much more going on.
In my sample, I have the "Select Criteria" region, where the user specifies the project and fiscal year range that he or she would like to report. Click the Search button, and the report returns the project headcount in a pivoted fashion for the fiscal year range specified.
I've got it working using a hard-coded query, which is displayed in the "Hardcoded Query" region. In this query, I basically return all years, and set conditions on each column which determines whether that column should be displayed or not based on the range selected by the user. While this works, it is not ideal, as there could be many more fiscal years to account for, and this is not very dynamic at all. Anytime a fiscal year is added to the FISCAL_YEAR table, I'd have to update this page.
So, after reading all of the OTN SQL pivot forums and "Ask Tom" pivot thread, I've been able to create a second region labeled "Dynamic Query" in which I've created a dynamic query to return the same results. This is a much more savvy solution and works great; however, the column names are generic in the report.
I had to set the query to parse at runtime since the column selection list is dynamic, which violates SQL rules. Can anyone please help me figure out how I can specify my column names in the dynamic query region to get the same column values I'm getting in the hardcoded region?
Please let me know if you need anymore information, and many thanks in advance!
MarkHi Tony,
Thanks so much for your response. I've had to study up on the dbms_sql package to understand your function... first time I've used it. I've fed my dynamic query to your function and see that it returns a colon delimited list of the column names; however, I think I need a little more schooling on how and where exactly to apply the function to actually set the column names in APEX.
From my test app, here is the code for my dynamic query. I've got it in a "PL/SQL function body returning sql query" region:
DECLARE
v_query VARCHAR2(4000);
v_as VARCHAR2(4);
v_range_from NUMBER;
v_range_to NUMBER;
BEGIN
v_range_from := :P1_FY_FROM;
v_range_to := :P1_FY_TO;
v_query := 'SELECT ';
-- build the dynamic column selections by looping through the fiscal year range.
-- v_as is meant to specify the column name as (FY10, FY11, etc.), but it's not working.
FOR i IN v_range_from.. v_range_to LOOP
v_as := 'FY' || SUBSTR(i, 3, 4);
v_query := v_query || 'MAX(DECODE(FY_NB,' || i || ',PFH_HEADCOUNT,0)) '
|| v_as || ',';
END LOOP;
-- add the rest of the query to the dynamic column selection
v_query := rtrim(v_query,',') || ' FROM ('
|| 'SELECT FY_NB, PFH_HEADCOUNT FROM ('
|| 'SELECT FY_ID, FY_NB FROM FISCAL_YEAR) A '
|| 'LEFT OUTER JOIN ('
|| 'SELECT FY_ID, PFH_HEADCOUNT '
|| 'FROM PROJECT_FY_HEADCOUNT '
|| 'JOIN PROJECT_FY USING (PF_ID) '
|| 'WHERE PL_ID = ' || :P1_PROJECT || ') B '
|| 'ON A.FY_ID = B.FY_ID)';
RETURN v_query;
END;I need to invoke GET_QUERY_COLS(v_query) somewhere to get the column names, but I'm not sure where I need to call it and how to actually set the column names after getting the returned colon-delimited list.
Can you (or anyone else) please help me get a little further? Once again, feel free to login to my host account to see it first hand.
Thanks again!
Mark -
Changing column names in a local query
I have several underlying queries in my IR bqy(11.1.2.1). I need to be able to change column names in my final query(as the requirements keep changing constantly). Is there a way to do this without modifying the names in the original query(I don't want to create a bunch of computed items either).
Thanks.I have several underlying queries in my IR bqy(11.1.2.1). I need to be able to change column names in my final query(as the requirements keep changing constantly). Is there a way to do this without modifying the names in the original query(I don't want to create a bunch of computed items either).
Thanks. -
Parse SQL: How to extract column names, table names from a SQL query
Hi all,
I have a requirement wherein a SQL query will be given in a text file.
The text file has to be read (probably using text_io package), the SQL query needs to be parsed and the column names, table names and where clauses have to be extracted and inserted into separate tables.
Is there a way to do it using PL/SQL ?
Is there a PL/SQL script available to parse and extract column names, table names etc ?
Pls help.
Regards,
SamI think I jumped to conclusion too early saying it is completely possible and straight forward. But after reading through your post for one more time I realised you are not interested only in the column_names, also the table_names and the predicates .
>
SQL query needs to be parsed and the column names
>
The above is possible and straight forward using the dbms_sql package.
I am pasting the same information as I did in the other forum.
Check this link and search for Example 8 and .
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sql.htm#sthref6136
Also check the working example from asktom
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1035431863958
>
table names and where clauses have to be extracted
>
Now this is the tricky bit. You can extract the list of tables by getting the sql_id from v$sql and joining it with v$sql_plan. But sometimes you may not get all the results because the optimizer may choose to refine your query (check this link)
http://optimizermagic.blogspot.com/2008/06/why-are-some-of-tables-in-my-query.html
and you can get the predicate information from the same table v$sql_plan but I will leave that area for you to do some R&D.
Regards
Raj
Edited by: R.Subramanian on Dec 10, 2008 3:14 AM -
Problem using alias field names in a sql query
Hello,
I have a question regarding a simple Oracle database SQL query writeup:
In the following (badly written but properly working) SQL query:
Query 1:
select
soe.field1,
(soe.field2 + soe.field3) as field4,
(soe.field5 - (soe.field2 + soe.field3)) as field6,
(select comp.parValue*soe.field7
from
CompTable comp) as parValue,
(select soe.field8 - (comp.parValue*soe.field7+ soe.field9)
from
CompTable comp) as field10
from
SomeTable soe
PROBLEM 1:
I am re writing the code (soe.field2 + soe.field3) to get the alias field4 or column name field4 that I have created on the fly in the previously for use with the following fields. Can't I rewrite the query as follows. There is something simple missing!
Query 2:
select
soe.field1,
(soe.field2 + soe.field3) as field4,
soe.field5 - field4 as field6, <<< field4 does not work here
(select
comp.parValue*soe.field7
from
CompTable comp) as parValue,
(select
soe.field8 - (comp.parValue*soe.field7+ soe.field9)
from
CompTable comp) as field10
from
SomeTable soe
PROBLEM 2:
Similar to the above problem, I was thinking to get a field parValue out of the CompTable table and re-use many times rather than the code shown in Query 1:
Query 3:
select
soe.field1,
(soe.field2 + soe.field3) as field4,
soe.field5 - field4 as field6,
soe.field7* (select comp.parValue from CompTable comp) as parValue1,
soe.field8 - (parValue1*soe.field7+ soe.field9) as field10 <<<< parvalue1 does not work here
parValue1*soe.field9 as TaxCondition <<<< parvalue1 does not work here
from
SomeTable soe
See that the query becomes so simple, but the above query does not work. There is something fundamentally wrong in my usage of the alias field names in creating other fields. The Query1 seems to be the only working option but its very slow as I am redoing and re-writing the whole code again and again to get the parValue field out of the CompTable table for use to create many other fields.
I will appreciate if you can guide me in the right direction on this issue.
Thanks and Regards
RamaSELECT tmp.contract_no, tmp.Actual, tmp.Actual - tmp.NbHours
FROM ( SELECT t.contract_no, sum(l.hrs) AS Actual, (c.labour_hours * c.labour_progress_per) / 100 AS NbHours
FROM TASK_DELEGATION t
INNER JOIN COST_CODE c
ON t.cost_code = c.cost_code AND t.contract_no = c.contract_no AND t.is_inactive=0
INNER JOIN Labour.dbo.LABOURALLOT l
ON l.contractNo = c.contract_no AND l.costcode = c.cost_code AND l.pm = 'N'
GROUP BY t.contract_no, c.labour_hours, c.labour_progress_per
) tmp -
The subject sums it up pretty well... I have a query that works fine from SQL*Plus, but throws a JDBC exception with "ORA-00904 invalid column name" if I create a PreparedStatement from it and call executeQuery().
The query itself is substantially similar to:
SELECT foo, t.bar.getStringVal() from some_table t
where "Some table" is an oracle 9i table, "foo" is a varchar2 column, and "bar" is a column that used to be varchar2 before I dropped and re-created the table with an xmltype column instead. "t" is an alias for the table that I didn't used to need (since it's only one table), but apparently is required for getStringVal() to work.
... And, of course, .getStringVal() is being used as a convenient way to treat technically LOB-like xmltype columns as big ersatz varchar2 columns so I won't have to screw around with stream i/o just to read a 4,001-byte value into a String ;-)
I'm using the ojdbc14.jar thin driver and a fairly recent j2sdk (1.4.1_02, I think). I made a point of anihilating every copy of classes12.zip on my PC just to make sure it wasn't lurking in a classpath somewhere to screw things up.
Strangely enough, it DOES work from within Netbeans' database explorer (itself connecting to the same Oracle database using the ojdbc14.jar thin driver).
For the sake of being comprehensive, here's an example of the actual JDBC code that won't work:
public ResultSet doQuery(Connection conn, int val) throws SQLException {
String sql = "SELECT foo, t.bar.getStringVal() from some_table t where anothercolumn = ?";
PreparedStatement sth = conn.prepareStatement(sql);
sth.setInt(1, val);
ResultSet rs = sth.executeQuery();
// everything past this point is moot,
// because sth.executeQuery throws an exception...
// however, the ResultSet would ultimately be
// returned to the method's caller, and
// its values read using getString(fieldname)
// including 'bar', the xmltype field...OK, this particular problem was my fault. The original table was on a server running 8i. To spare myself the grief of having to deal with CLOBs on 8i's terms and take advantage of 9i's new conveniences for handling them, I created a new table on our other server that's running 9i and updated the app's config settings to reflect the new server. Unfortunately, I forgot that the debugging/testing main() method had the URL of the old database hardcoded (it was written before the rest of the class). Ergo... it was still looking at the old database. Oops. (*blush*).
-
Changing Column Value Style using SQL Query
Hi,
I'm trying to build a fantasy basketball game with APEX. I have a table that has a list of games. I need to change the color of the column value i.e. the name of the team that wins according to a SQL query Here's an example:
TABLE NAME: LATESTGAMES
Home Away Homepoints Awaypoints
Boston Cleveland 105 101
Toronto Washington 122 83
What I want to do is display the winning team i.e. Boston and Toronto in Green since that's the team that won.
The SQL query is:
SELECT HOME,
AWAY,
HOMEPOINTS,
AWAYPOINTS
from LATESTGAMES;
What do I need to do in order to display the Winning Team as Green on every column? Please HelpHello Devilfish,
I did something like that in my DG Tournament application (http://www.dgtournament.com)
Your SQL query can look like this:
SELECT CASE
WHEN (homepoints > awaypoints)
THEN '<span style="color:green;">' || home || '</span>'
ELSE home
END AS home,
SELECT CASE
WHEN (awaypoints > homepoints)
THEN '<span style="color:green;">' || away|| '</span>'
ELSE away
END AS away,
HOMEPOINTS,
AWAYPOINTS
from LATESTGAMES;Hope that gives you an idea,
Dimitri
-- http://dgielis.blogspot.com
-- http://apex-evangelists.com -
C# : Get Column name for an Insert Query from The Selected GridView Row.
Hi Guys, I am trying to insert data in an SQL table by executing an Insert Query.
The problem is that I need to get the column name from a cell in the selected gridview Row.
Here's the snippet:
SqlCommand cmd30 = new SqlCommand("insert into mytable ( '"+GridView7.SelectedRow.Cells[0].Text+"' , r_id) values ('"+ GridView7.SelectedRow.Cells[1].Text +"', '"+TextBox1.Text+"')",con30);
cmd30.ExecuteNonQuery();
**r_id is not a Primary Key.
The Error is get is:
Incorrect syntax near 'r_id'.
Any Help will be appreciated.
Thanks,
Shaleen
TheHexLordHi TheShaleen,
Like your title mentioned.GridView control is a web class.This forum is to discuss problems of C# development. Your question is not related to the topic of this forum.
You'll need to post it in the dedicated ASP.Net Forum for more efficient responses, where you can contact ASP.NET experts. Thanks for understanding.
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to use get column name.vi in SQL toolkit 2.0?
Due to the vi "get column name.vi" paremeters,no table name has connected to the vi. So, I want to ask how to use this vi for gain one column name of a table. Maybe there are some other ways to solve column name getting.
Thanks.Thanks!
Error 4101 Description:
Execute SQL - The connection, statement, or query handle you provided is not valid.
I don't just used the toolkit in a while,now, I am developing a irrigation system. For the table field names defined by users,column names must be known before any select operations. Do you have any other good idea about drawing out the columnname parameters?
As you know, a valid DSN and table have been also available. The database I used is Access. The bad thing to me is that there is no any text information gotten. And I think, it may be some problems in connection way which I don't find out.
Really appreciated by your reply.
Could you give me some example in the aspect?
Thank you again. -
How to pull only column names from a SELECT query without running it
How to pull only column names from a SELECT statement without executing it? It seems there is getMetaData() in Java to pull the column names while sql is being prepared and before it gets executed. I need to get the columns whether we run the sql or not.
Maybe something like this is what you are looking for or at least will give you some ideas.
public static DataSet MaterializeDataSet(string _connectionString, string _sqlSelect, bool _returnProviderSpecificTypes, bool _includeSchema, bool _fillTable)
DataSet ds = null;
using (OracleConnection _oraconn = new OracleConnection(_connectionString))
try
_oraconn.Open();
using (OracleCommand cmd = new OracleCommand(_sqlSelect, _oraconn))
cmd.CommandType = CommandType.Text;
using (OracleDataAdapter da = new OracleDataAdapter(cmd))
da.ReturnProviderSpecificTypes = _returnProviderSpecificTypes;
//da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
if (_includeSchema == true)
ds = new DataSet("SCHEMASUPPLIED");
da.FillSchema(ds, SchemaType.Source);
if (_fillTable == true)
da.Fill(ds.Tables[0]);
else
ds = new DataSet("SCHEMANOTSUPPLIED");
if (_fillTable == true)
da.Fill(ds);
ds.Tables[0].TableName = "Table";
}//using da
} //using cmd
catch (OracleException _oraEx)
throw (_oraEx); // Actually rethrow
catch (System.Exception _sysEx)
throw (_sysEx); // Actually rethrow
finally
if (_oraconn.State == ConnectionState.Broken || _oraconn.State == ConnectionState.Open)
_oraconn.Close();
}//using oraconn
if (ds != null)
if (ds.Tables != null && ds.Tables[0] != null)
return ds;
else
return null;
else
return null;
}r,
dennis -
I need the "Real" Table / Table Column names from a sql view
Firstly, we have a system with ~1000 tables and ~250 views. We have field level security on the table columns (in our code)
Now we have a lot of views which select data from the tables, but I need to get the "Table Column Name" that is linked in the view.
I know there are view columns that is not linked to a specific table column, (or concatenation of columns) so those columns can just return NULL.
From the sample you will see there is a view selecting data from another view. I know it is not the best sql performance (execution path) but that is another topic on its own.
I went through a lot of the sys.* stored procs or sys.* views to try and figure out if there is a view that we can use to get the expected results.
here is the sql code:
if
Exists (select
* from
sys.all_objects
where name =
'AliasView2')
drop view dbo.AliasView2
if
Exists (select
* from
sys.all_objects
where name =
'AliasView1')
drop view dbo.AliasView1
if
Exists (select
* from
sys.all_objects
where name =
'Table4')
BEGIN
alter table dbo.Table4
DROP CONSTRAINT [FK_T4_T3]
alter table dbo.Table4
DROP CONSTRAINT [PK_T4_Constraint]
drop table dbo.Table4
END
if
Exists (select
* from
sys.all_objects
where name =
'Table3')
BEGIN
alter table dbo.Table3
DROP CONSTRAINT [FK_T3_T2]
alter table dbo.Table3
DROP CONSTRAINT [PK_T3_Constraint]
drop table dbo.Table3
END
if
Exists (select
* from
sys.all_objects
where name =
'Table2')
BEGIN
alter table dbo.Table2
DROP CONSTRAINT [FK_T2_T1]
alter table dbo.Table2
DROP CONSTRAINT [PK_T2_Constraint]
drop table dbo.Table2
END
if
Exists (select
* from
sys.all_objects
where name =
'Table1')
BEGIN
alter table dbo.Table1
DROP CONSTRAINT [PK_T1_Constraint]
drop table dbo.Table1
END
create
Table dbo.Table1
T1_PK int
NOT NULL
Identity(1, 1)
CONSTRAINT [PK_T1_Constraint]
PRIMARY KEY (T1_PK),
T1_Field1 varchar
NULL,
T1_Field2 varchar
NULL,
create
Table dbo.Table2
T2_PK int
NOT NULL
Identity(1, 1)
CONSTRAINT [PK_T2_Constraint]
PRIMARY KEY (T2_PK),
T2_Field1 varchar
NULL,
T2_Field2 varchar
NULL,
T2_FK int
NOT NULL
CONSTRAINT [FK_T2_T1]
FOREIGN KEY (T2_FK)
REFERENCES dbo.Table1
(T1_PK)
create
Table dbo.Table3
T3_PK int
NOT NULL
Identity(1, 1)
CONSTRAINT [PK_T3_Constraint]
PRIMARY KEY (T3_PK),
T3_Field1 varchar
NULL,
T3_Field2 varchar
NULL,
T3_FK int
NOT NULL
CONSTRAINT [FK_T3_T2]
FOREIGN KEY (T3_FK)
REFERENCES dbo.Table2
(T2_PK)
create
Table dbo.Table4
T4_PK int
NOT NULL
Identity(1, 1)
CONSTRAINT [PK_T4_Constraint]
PRIMARY KEY (T4_PK),
T4_Field1 varchar
NULL,
T4_Field2 varchar
NULL,
T4_FK int
NOT NULL
CONSTRAINT [FK_T4_T3]
FOREIGN KEY (T4_FK)
REFERENCES dbo.Table3
(T3_PK)
GO
--Create a basic view to select some data
CREATE
VIEW dbo.AliasView1
AS
select
t2.T2_FK as Table2_ForeignKey,
t1.T1_Field1 as Table1_FieldOne,
t2.T2_Field1 as Table2_FieldOne
FROM Table1 t1
Left outer
join Table2 t2 on t2.T2_FK
= t1.T1_PK;
GO
--Create another view that select basic data, and also selecting data from view 1
CREATE
VIEW dbo.AliasView2
AS
select
v1.Table1_FieldOne
as Table1_FieldOne,
v1.Table2_FieldOne
as Table2_FieldOne,
t3.T3_Field1 as Table3_FieldOne,
t3.T3_Field2
FROM Table3 t3
Left outer
join AliasView1 v1 on v1.Table2_ForeignKey
= t3.T3_PK;
GO
--My attempt to get the desired output, but no luck
SELECT
col.COLUMN_NAME as AliasColumnName, col.DATA_TYPE, col.CHARACTER_MAXIMUM_LENGTH
as max_length, colu.*
FROM
information_schema.COLUMNS col
left
outer join
(SELECT
VIEW_SCHEMA, VIEW_NAME, COLUMN_NAME,
min(TABLE_NAME)
as TABLE_NAME
FROM information_schema.VIEW_COLUMN_USAGE colu
WHERE VIEW_NAME =
'AliasView2'
Group by VIEW_SCHEMA, VIEW_NAME, COLUMN_NAME
) COLU ON colU.VIEW_NAME
= col.TABLE_NAME
and colu.COLUMN_NAME
= col.COLUMN_NAME
left
outer join
(select a.name
as TableName, c.name
as FieldName
from sys.foreign_key_columns fk
join sys.all_objects a
on a.object_id
= fk.parent_object_id
join sys.all_columns c
on c.object_id
= a.object_id
and c.column_id
= fk.parent_column_id
join sys.all_objects ar
on ar.object_id
= fk.referenced_object_id
join sys.all_columns cr
on cr.object_id
= ar.object_id
and cr.column_id
= fk.referenced_column_id
join sys.schemas scr
on scr.schema_id
= ar.schema_id
) fks on fks.TableName
= colu.TABLE_NAME
and fks.FieldName
= colu.COLUMN_NAME
WHERE COL.TABLE_NAME
= 'AliasView2'
order
by col.ORDINAL_POSITION
This is the results being returned: (That is not 100% what I am looking for)
AliasColumnName
DATA_TYPE
max_length
VIEW_SCHEMA
VIEW_NAME
COLUMN_NAME
TABLE_NAME
Table1_FieldOne
varchar
1
dbo
AliasView2
Table1_FieldOne
AliasView1
Table2_FieldOne
varchar
1
dbo
AliasView2
Table2_FieldOne
AliasView1
Table3_FieldOne
varchar
1
NULL
NULL
NULL
NULL
T3_Field2
varchar
1
dbo
AliasView2
T3_Field2
Table3
The desired results must be like the following:
AliasColumnName
DATA_TYPE
max_length
VIEW_SCHEMA
VIEW_NAME
COLUMN_NAME
TABLE_NAME
Table1_FieldOne
varchar
1
dbo
AliasView2
T1_Field1
Table1
Table2_FieldOne
varchar
1
dbo
AliasView2
T2_Field1
Table2
Table3_FieldOne
varchar
1
dbo
AliasView2
T3_Field1
Table3
T3_Field2
varchar
1
dbo
AliasView2
T3_Field2
Table3
NOTE: the COLUMN_NAME and TABLE_NAME must the REAL field of the TABLE it belongs to and not only ONE LEVEL Higher’s ALIAS View NameNow we have a lot of views which select data from the tables, but I need to get the "Table Column Name" that is linked in the view.
If you are using SQL Server 2012/2014, then you can use
sys.dm_exec_describe_first_result_set (Transact-SQL) to gte the informations.
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Set the column length in an sql query
Hi,
Is there a way to set the column length in a query without using sqlplus commands like row size and format column.
I'd like to do it just from the sql query itself.
select 'this is a test' from dual; Can I define the width of this column in the select statement
Cheers.Use RPAD,
SQL> WITH T
2 AS (SELECT 'this is test' str FROM DUAL
3 UNION ALL
4 SELECT 'this is a long test' FROM DUAL
5 UNION ALL
6 SELECT 'this is a long long long long test' FROM DUAL)
7 SELECT RPAD ( str, 20) str,LENGTH( RPAD ( str, 20)) len
8 FROM T;
STR LEN
this is test 20
this is a long test 20
this is a long long 20
SQL> G. -
How to bind a column name in PL/SQL
i have this code in a transaction report.
DECLARE
q VARCHAR2 (1000);
t VARCHAR2 (15);
BEGIN
t := '11110000';
q := q || 'select STARTDATE, PHONESOURCE, PHONETO, DURATION ';
q := q || 'from TRANSACTION ';
q := q || 'where TRANS_ID = ' ||t|| 'and STARTDATE between :P3_DATE_FROM and :P3_DATE_TO ';
q := q || 'and PHONESOURCE = :P3_FILTER_BY_TEXT';
RETURN q;
END;
I have a combo box item which suppose to select between 2 different columns (PHONESOURCE & PHONEDEST) lets call this combo box: P3_FILTER_BY.
I need to replace 'PHONESOURCE' (marked) with this combo box in order to set the query dynamically. the question is: is it possible? and if so how?
i tried few variaton of replacing it, but it wouldn't work.thank u for your answer,
However, i've thought about it and tried it before. but it gave me this error when applying the edit page:
"LS-00103: Encountered the symbol "&" when expecting one of the following..."
even when i checked the "Use Generic Column Names (parse query at runtime only)" check box it gave me this error in runtime.
so, what should i do ?? -
Executing a column which has a sql query in a tabular form
Hi,
I have a tabular form which contains a column named as SQL which has sql statements in it. Without going to the SQL workshop in Apex i want to execute that query in the tabular form itself. For that i've created a page item which fetches the particular rows sql query and created a button 'EXECUTE'. When i click the execute button it should run the query and should display whether the query is correct or not and should show the error message.
Can any one provide solution for this or whether there are any other ways to achive this scenario.
With Regards
Balaji.P.KBalaji P.K wrote:
Can any one provide solution for this or whether there are any other ways to achive this scenario.Difficult as we have no idea what this "scenario" actually is. Go back several steps and explain in detail the problem this is supposed to solve.
I have a tabular form which contains a column named as SQLBad idea. <tt>SQL</tt> is a PL/SQL reserved word. Using any token from Oracle namespaces as a database identifier is confusing/problematic.
which has sql statements in it.Why? Where does this SQL come from? What is the source of the tabular form?
Without going to the SQL workshop in Apex i want to execute that query in the tabular form itself.Explain the "execute that query in the tabular form itself" concept. Where do the results go? -
11g : column fornula as a SQL query
While creating a report in 11 g and choosing columns from the subject area, I see that we can edit the column formula.
Is it possible to specify a SQL query in the column formula.?No, it's not possible.
If you want to use specific sql you can use the EVALUATE function
http://gerardnico.com/wiki/dat/obiee/evaluate
Regards
Adil
Maybe you are looking for
-
How to send email notifications from a workflow?
I am having problems trying to get notification emails to work from a workflow. I have done the following: 1.Checked notification to file is commented out in waveset.properties 2.Set SMTP server and port setting in Configure > Servers > email templat
-
No Play List's are being transferred to my IPOD Nano
Everytime I update my Nano, I get the msg displayed in "I-TUNES": "Songs on the IPOD cannot be updated because all of the playlists selected for updating no longer exists." I mistakenly deleted some standard playlist in I-TUNES to make room for my ow
-
Hi, I am trying to execute Runtime.getRuntime().exec() command on click of a button. It works fine, but the problem is that i get a command window when the command is executed. Is there any way to make the command window not to appear?
-
Identifying single motor units from EMG data
I need to identify single motor units from EMG data and have been unable to find anything on the NI web site that could help. I have identified a third party program, Spike 2 from Cambridge Electronic Design (CED), that is able to do the job however
-
I have just downloaded iOS5 on my iPhone 4 and all my current iCal entries have been duplicated. Is there a way I can delete these, apart from going through them one by one (which could take many hours!)