Alias for column names : Urgent
Hi ,
I want alias names for my columns.
I'm writing query like this
inquiryBean.setQueryStatement("SELECT CDE AS "New Code", TXT AS "New Text" FROM TNR004_PY_METH");
But it is giving me an error because there is space between New and Code also double quote problem is there.
In short I don't know how to write this query statement ?
Can anybody help me ?
Thanks,
-priya
Try to do this:
inquiryBean.setQueryStatement("SELECT CDE AS [New Code], TXT AS [New Text] FROM TNR004_PY_METH");
Similar Messages
-
Hi all,
I want to alias the column name form Location to "Location Name".
say for example:
select location_name as Location Name from Location_table;
i know that the above query will give erroe.
here initially my column name is Location_name, but i want is "*Location Name*".
(there should be a space in between the two words)
Can anybody help me?
Thanks in advance,
Vinayselect location_name as "Location Name" from Location_table;- Mahesh Kaila
-
Alias Names for Column names in the Prompt
Hi,
I have a scenario where I am taking column names into prompt. I have used the following SQL in the SQL results under "Show" option of the Prompt.
SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By OrderDate"' END FROM " Real Time"
UNION ALL
SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By ShipDate"' END FROM "Real Time"
My problem here is I am getting the column names into the Prompt as "Orders"."By OrderDate" and "Orders"."By ShipDate", which is not acceptable and readable format for the user. I tried using the alias name in the SQL query this way.
SELECT (CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By OrderDate"' END) AS "By OrderDate" FROM " Real Time"
UNION ALL
SELECT (CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By ShipDate"' END) AS "By ShipDate" FROM "Real Time"
but it is throwing an error.Is there any way that I can assign an alias name for the column names such as OrderDate and ShipDate in the above SQL.
Your quick respose is appreciated.
Thanks,
RamaChange ur
SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By OrderDate"' END FROM " Real Time"
UNION ALL
SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE '"Orders"."By ShipDate"' END FROM "Real Time"
To
SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE By OrderDate END FROM " Real Time"
UNION ALL
SELECT CASE WHEN 1=0 THEN AGE.AGE ELSE By ShipDate END FROM "Real Time"
So that it displays the Name as required
Then in the Fx for that column in the Report Use '"Orders"."@Presentation variable"'.
This worked for me Let me know if it worked for you. -
Hello,
I am using Oracle Database 11g Enterprise Edition Release 11.1.0.6.0.
I would like to have an Alias for my columns in a query.
The main column value is a date like 201204 the Alias which should appear as column heading when the query is run should be like Apr-2012
So I would like my output to be like
Apr-12 May-12 Jun-12
201204 201205 2012-06
I am using a query like
select '2001204'||' "'||to_char(to_date('201204','yyyymm'),'Mon-yy')||'"'
from dual;
This does not seem to give me the correct results. Am I doing something wrong ?
Thanks
fmIQ wrote:
Hello,
I am using Oracle Database 11g Enterprise Edition Release 11.1.0.6.0.
I would like to have an Alias for my columns in a query.
The main column value is a date like 201204 the Alias which should appear as column heading when the query is run should be like Apr-2012
So I would like my output to be like
Apr-12 May-12 Jun-12
201204 201205 2012-06
I am using a query like
select '2001204'||' "'||to_char(to_date('201204','yyyymm'),'Mon-yy')||'"'
from dual;
This does not seem to give me the correct results. Am I doing something wrong ?
Thanks
fmThe names/datatypes/sizes and number of columns from a query is called the "projection" and is determined at parse time; therefore it cannot be determined by the data without using 2 passes of the data (one to determine what the projection should look like and a dynamic one to query the data again with that dynamically generated projection).
Essentially what you are trying to do is abuse the SQL engine, and it is really something that is best done by reporting tools that query the data and then process it to format the output based on the data itself.
{thread:id=2309172} -
Use variable in SQL for column name
Hi All,
We want to use a user input as a column name in APEX.
For e.g user will enter "ALLOWABLE_AMOUNT" then the query will be as follows :
select Rule,rule_name,rule_desc,"User Input" from rule_dim
where "User_input" > 100
So here the User_input will be substitued with Allowable_amount. Is this doable using any bind/substitution variables ? I tried ":P2_USER_VARIABLE" and "&P2_USER_VARIABLE." but did not work.
Please advice.Hi Andy,
You do that with an Interactive Report and a Dynamic Action.
I'll assume that you're using APEX 4.2
Here's how:
Create Page 2 with an Interactive Report
Create New Page > Report > Interactive Report > Next > Next
Enter a SQL Select statement: select Rule,rule_name,rule_desc from rule_dim
Next > Create > Edit Page
Create the item P2_USER_VARIABLE
Add Item > Number Field > Next
Item Name: P2_USER_VARIABLE
Next > Next > Next
Source Used: Always, replacing any existing value in session state
Source Type: Static Assignment (value equals source attribute)
Create Item
Create a Dynamic Action to refresh the Interactive Report when P2_USER_VARIABLE is changed
Add Dynamic Action
Name: Refresh IRR
Next >
Event: Lose Focus
Selection Type: Item(s)
Item(s): P2_USER_VARIABLE
Next >
Action: Refresh
Next >
Selection Type: Region
Region: Report 1 (10)
Create Dynamic Action
Add the ALLOWABLE_AMOUNT to the Interactive Report
Report 1
Region Source: SELECT * FROM (select Rule,rule_name,rule_desc, :P2_USER_VARIABLE AS ALLOWABLE_AMOUNT from rule_dim) WHERE ALLOWABLE_AMOUNT > 100
Apply Changes > Apply Changes
Get the Interactive Report to submit P2_USER_VARIABLE
Report 1
Page Items to Submit: P2_USER_VARIABLE
Apply Changes
Change the Heading for ALLOWABLE_AMOUNT in the Interactive Report
Interactive Report
Change the Heading of ALLOWABLE_AMOUNT to &P2_USER_VARIABLE.
Apply Changes
Run
Enter something into the USER VARIABLE field and select something else on the page. Watch the last column update to that value.
Tim. -
Maximum length allowed for column name, index name and table name?
Hi,
I want to know what is the maximum length allowed for coulmn name, table name and index name in MaxDB ?
Regards
RajHi Raja,
simply check the catalog:
sqlcli bwt=> \dc domain.columns
Table "DOMAIN.COLUMNS"
| Column Name | Type | Length | Nullable | KEYPOS |
| ---------------- | ------------ | ------ | -------- | ------ |
| SCHEMANAME | CHAR UNICODE | 32 | YES | |
| OWNER | CHAR UNICODE | 32 | YES | |
| TABLENAME | CHAR UNICODE | 32 | YES | |
| COLUMNNAME | CHAR UNICODE | 32 | YES | |
and
sqlcli bwt=> \dc domain.indexes
Table "DOMAIN.INDEXES"
| Column Name | Type | Length | Nullable | KEYPOS |
| ------------------ | ------------ | ------ | -------- | ------ |
| SCHEMANAME | CHAR UNICODE | 32 | YES | |
| OWNER | CHAR UNICODE | 32 | YES | |
| TABLENAME | CHAR UNICODE | 32 | YES | |
| INDEXNAME | CHAR UNICODE | 32 | YES | |
regards,
Lars -
Dynamic UPDATE statement with parameters for column names.
Hello,
On this* website I read "The SQL string can contain placeholders for bind arguments, but bind values cannot be used to pass in the names of schema objects (table or column names). You may pass in numeric, date, and string expressions, but not a BOOLEAN or NULL literal value"
On the other hand, in this Re: execute immediate with dynamic column name update and many other
posts people use EXECUTE IMMEDIATE to create a dynamic UPDATE statement.
dynSQL:='UPDATE CO_STAT2 CO SET CO.'||P_ENT_B_G_NAME||' = '||P_ENT_E_G_WE||'
WHERE ST IN
(SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
'||P_ST||' = CO.ST AND
CO.'||P_ENT_E_G_NAME||' > '||P_ENT_E_G_WE||' AND
CO.'||P_ENT_B_G_NAME||' < '||P_ENT_E_G_WE||');';
EXECUTE IMMEDIATE dynSQL ;
Since this statement is part of a Stored Procedure, I wont see the exact error but just get a ORA-06512.
The compiling works fine and I use Oracle 11g.
http://psoug.org/definition/EXECUTE_IMMEDIATE.htmOK I extracted from all of your posts so far that I have to use "bind-variables with :"
From all the other tuorials and forums posts, I assume using the pipe is correct so I added those as well into the script:
set serveroutput on format wraped;
DECLARE
dynSQL VARCHAR2(5000);
P_ENT_E_G_NAME VARCHAR2 (100) :='test1'; P_ENT_E_G_WE VARCHAR2 (100) :='01.02.2012'; P_ENT_B_G_NAME VARCHAR2 (100) :='01.01.2012';
P_ST VARCHAR2 (100) :='32132';
BEGIN
dynSQL:= 'UPDATE CO_STAT2 CO SET CO.'||:P_ENT_B_G_NAME||' = '||:P_ENT_E_G_WE||'
WHERE ST IN (SELECT ST FROM STG_CO_STAT2_TEST CO WHERE
'||:P_ST||' = CO.ST AND
CO.'||:P_ENT_E_G_NAME||' > '||:P_ENT_E_G_WE||' AND
CO.'||:P_ENT_B_G_NAME||'
< '||:P_ENT_E_G_WE||')';
--this is somehow missing after the last < '||:P_ENT_E_G_WE||')';
dbms_output.enable;
dbms_output.put(dynSQL);
--EXECUTE IMMEDIATE dynSQL;
END;Problem:I think I figured it out, the dates that I parse into the query need additional ' -
How to use resource bundle entries for column names/title in .rpt file
<p>Our application needs to be able to support reporting in multiple languages. Hence we do not want to put language specifiec column names in the rpt file but rather use text for a particular locale during runtime which in java world is easily achievable using Resource Bundle entries.</p><p>Does JRC allow for using resource bundle entries as column names or for that matter for titles etc. in the .rpt file?</p>
Hi,
You can follow this step-by-step tutorial to find out how to achieve this using our User Function Libraries (UFLs). The walkthrough can be found here:
<a href="http://diamond.businessobjects.com/node/412">http://diamond.businessobjects.com/node/412</a>
Regards,<br />Sean Johnson (CR4E Product Manager) <br /><br /> <a href="http://www.eclipseplugincentral.com/Web_Links-index-req-ratelink-lid-639.html">Rate this plugin @ Eclipse Plugin Central</a> -
[Swing] JTable & Oracle DB: SQL Query for Column Names Change
Hello,
I apologise for the 'stupid' thread subject name.
Now i have a JTable wich i fill with rows from an Oracle DB.
The query is something like this: "SELECT location_id, location_name FROM locations*bold*", and in the table i will have the columns names LOCATION_ID & LOCATION_NAME.
I want to change this query like: "SELECT location_id "Location ID", location_name "Location Name" FROM locations".
The only problem is that i CAN NOT insert "" inside ""
So if anyone know how to fix this 'problem' please share that with me.
Thank you,
B.found it.. \" \"
:) -
SQL Query not working for column names with spaces
Hi People..
We have a strange situation wherein, the column name in the database table has a space inbetween like "Constant Name". While we write a JDBC statement code with the select query we get an exception for invalid syntax. It will help us in a great way if you have anything to inform us on this..
Thanks
PrabzUsing case sensitive names and names with spaces in it is not a good practice.
However, I believe the SQL standard accounts for this with quoted identifiers. I believe the syntax is
. select "My Field1", "My Field2"
. from "My Table'
Have also seen the following although it might be MS Access specific.
. select [My Field1], [My Field2]
. from [My Table] -
Hi,
how to create an alias for a domain name in /etc/hosts file ? Wh have this :
192.168.2.30 mymachine.domaine1.domaine2.com mymachine
How can I create an alias for mymachine.domaine1.domaine2.com ??
Many thanks.192.168.2.30 mymachine.domaine1.domaine2.com mymachine
Not sure what you mean : mymachine is already an alias. -
Search for column name in DB tables
Hi Guys
Is it possible to search column name when we do not know the corresponding table in the databse
Cheers
shabarYou can use the data dictionary to search though a list of all column names. The <strike>table</strike> data dictionary view is ALL_TAB_COLUMNS.
Lets assume you want to search for ID columns:
example
select owner, table_name, column_name
from all_tab_columns
where column_name = 'ID';Edited by: Sven W. on Jun 21, 2011 1:47 PM -
JPA Problem using alias for columns in a query
Hello, I am having some problems with a query that I am trying to use in my JEE project. This query doesnt return an entity but a group of values. I created a class representing the result and a query with the jpa constructor expression but it is not working.
The problem is that in the query I added some alias to the results, and when I try to run the project it says that it cannot parse the query.
My Query:
Query query = em.createQuery("SELECT NEW vo.VOOperacionesAgrupadas (o.nemotecnico as nemotecnico, o.esCompra as esCompra, i.equivUltimo as equivUltimo, sum(o.saldo) as saldo, sum(o.utilidad) as utilidad, sum(o.tasaCompraVenta)/count(o.nemotecnico) as promedioTasaCompra, (i.equivUltimo-sum(o.tasaCompraVenta)/count(o.nemotecnico))*100 as puntosBasicos) FROM Operaciones o, Instrumentos i WHERE o.idUsuario = :idUsuario AND o.nemotecnico = i.nemotecnico AND o.estaCerrada = 'false' Group by o.nemotecnico, o.esCompra, i.equivUltimo"); When I use that the server returns :
Exception Description: Syntax error parsing the query [SELECT NEW vo.VOOperacionesAgrupadas (o.nemotecnico as nemotecnico, o.esCompra as esCompra, i.equivUltimo as equivUltimo, sum(o.saldo) as saldo, sum(o.utilidad) as utilidad, sum(o.tasaCompraVenta)/count(o.nemotecnico) as promedioTasaCompra, (i.equivUltimo-sum(o.tasaCompraVenta)/count(o.nemotecnico))*100 as puntosBasicos) FROM Operaciones o, Instrumentos i WHERE o.idUsuario = :idUsuario AND o.nemotecnico = i.nemotecnico AND o.estaCerrada = 'false' Group by o.nemotecnico, o.esCompra, i.equivUltimo], line 1, column 53: syntax error at [as].
Internal Exception: MismatchedTokenException(8!=82)
GRAVE: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing the query [SELECT NEW vo.VOOperacionesAgrupadas (o.nemotecnico as nemotecnico, o.esCompra as esCompra, i.equivUltimo as equivUltimo, sum(o.saldo) as saldo, sum(o.utilidad) as utilidad, sum(o.tasaCompraVenta)/count(o.nemotecnico) as promedioTasaCompra, (i.equivUltimo-sum(o.tasaCompraVenta)/count(o.nemotecnico))*100 as puntosBasicos) FROM Operaciones o, Instrumentos i WHERE o.idUsuario = :idUsuario AND o.nemotecnico = i.nemotecnico AND o.estaCerrada = 'false' Group by o.nemotecnico, o.esCompra, i.equivUltimo], line 1, column 53: syntax error at [as].
Internal Exception: MismatchedTokenException(8!=82)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
Caused by: Exception [EclipseLink-8024] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing the query [SELECT NEW vo.VOOperacionesAgrupadas (o.nemotecnico as nemotecnico, o.esCompra as esCompra, i.equivUltimo as equivUltimo, sum(o.saldo) as saldo, sum(o.utilidad) as utilidad, sum(o.tasaCompraVenta)/count(o.nemotecnico) as promedioTasaCompra, (i.equivUltimo-sum(o.tasaCompraVenta)/count(o.nemotecnico))*100 as puntosBasicos) FROM Operaciones o, Instrumentos i WHERE o.idUsuario = :idUsuario AND o.nemotecnico = i.nemotecnico AND o.estaCerrada = 'false' Group by o.nemotecnico, o.esCompra, i.equivUltimo], line 1, column 53: syntax error at [as].
Internal Exception: MismatchedTokenException(8!=82)
at org.eclipse.persistence.exceptions.JPQLException.syntaxErrorAt(JPQLException.java:362)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.handleRecognitionException(JPQLParser.java:304)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.addError(JPQLParser.java:245)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.reportError(JPQLParser.java:362)
at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.recoverFromMismatchedElement(Unknown Source)
at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.recoverFromMismatchedToken(Unknown Source)
at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.mismatch(Unknown Source)
at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.match(Unknown Source)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.constructorExpression(JPQLParser.java:2635)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.selectExpression(JPQLParser.java:2045)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.selectItem(JPQLParser.java:1351)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.selectClause(JPQLParser.java:1266)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.selectStatement(JPQLParser.java:352)
at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.document(JPQLParser.java:276)
at org.eclipse.persist
GRAVE: ence.internal.jpa.parsing.jpql.JPQLParser.parse(JPQLParser.java:133)
at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.buildParseTree(JPQLParser.java:94)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:198)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:173)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:125)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:109)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1326)
... 59 more
Caused by: MismatchedTokenException(8!=82)
... 74 more
What can I do?? I have been stuck in this problem for 2 weeks :s I have tried almost everything..
Thanks in advance for your help!SELECT 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 -
How to get the alias name of an attribute of a VO from its column name?
How can I programmatically get the alias name of an attribute of a VO given its column name?
Often alias and column names are not same when the VO is created (and I don't require them to be the same)Hello John.
I will be more precise. When the VO based on a table comes out from the wizard, it produces xml entries like the following one:
<ViewAttribute
Name="ColumnName"
AliasName="COLUMN_NAME"/>There the column of the table on the DB really is COLUMN_NAME. The wizard mangles that name producing ColumnName as Name property.
This is ok. I don't want to change this default behaviour.
What I need is to programmatically get the value of that attribute given its AliasName property value:
String f(ViewObject vo, String AliasName) {
return (String)vo.getCurrentRow().getAttributeFromAliasName(aliasName); // getAttributeFromAliasName does not exist
// instead of return (String)vo.getCurrentRow().getAttribute(Name);
That is, usually getAttribute expects what in the xml is the Name property. However, I want a sort of getAttribute() expecting the AliasName.
I hope it's clear. -
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
-
If i open a new window instead of a new tab, in the new window does not appear the menu tab
i want to open new windows instead of tabs and in the new window should appear the menu tab and scrolling up and down, but now with the new version the menu tab does not appear and i cannot scroll up and down.
-
Memory leak in DIADEM 8.1
Hello, I'm using DIADEM 8.1.1292 on a 3GHz WinXP ProSP2-PC with 2Gytes of RAM. I'm doing some extensive data manipulation with DIADEM-VBScript and discovered (?) a memory leak which seriously disturbs my work: After finishing the script DIADEM doesn'
-
I received a request from iTunes concerning updating my iTunes with 11.4.1. The update was on my Vista Home Basic Computer. During the process of updating I received this message which stopped me from completing the update. Micosoft Visual C++ Runt
-
Need to get photos off old imac ruby
I found my old Ruby and realized there are images on there that I need to get off. How do I do that? I tried to stick in cd...but Ruby spits it out. Help? Thanks!
-
HT1386 My iOS was synced to iTunes but is now showing no music content on phone
Just purchased the iphone 4s, connected device through usb last night to sync iTunes to phone, was showing it was synced, but now there is no longer any music on iTunes (on the device)