Alias in where clause
Hi,
This is a OCA certification question.
1. SQL> SELECT prod_name,prod_list_price,prod_list_price-(prod_list_price*.25) "DISCOUNTED_PRICE"
FROM products
WHERE discounted_price<10;
The query generates an error.
What is the reason of generating error?
A. The parenthesis should be added to enclose the entire expression
B. The double quotation marks should be removed from the column alias
C. The column alias should be replaced with the expression in the WHERE clause
D. The column alias should be put in uppercase and enclosed within double quotation marks in the WHERE clause
Answer: D
My question is how can we use alias ("DISCOUNTED_PRICE") in where clause as (WHERE "DISCOUNTED_PRICE"<10) ??
please clarify.
Hi,
Answer C. (and I beleive, you are not writing the exam right now )
You cant use alias name in WHERE clause.
And if you still want to use DISCOUNTED_PRICE in WHERE clause, you need to use inline view.
SELECT *
FROM (SELECT prod_name,prod_list_price,prod_list_price-(prod_list_price*.25) "DISCOUNTED_PRICE"
FROM products
WHERE WHERE discounted_price<10;Cheers,
Suri
Similar Messages
-
How to use Alias Columns in WHERE CLAUSE
Hi ,
I have a query where in there are 2 alias columns, start_date and end_date where in i need to use them in my WHERE clause as start_date < end_date. Please let me know if this is possible. please see the bwlow query
SELECT (GREATEST (MIN (a.start_date_active),
MIN (b.start_date_active),
MIN (c.start_date_active),
d.start_date_active ) start_date ,
LEAST (MAX (NVL (a.end_date_active, b.end_date_active)),
MAX (c.end_date_active),
MAX (b.end_date_active),
NVL (d.end_date_active,'31-DEC-2099')) end_date,
c.terr_id,
a.source_number,
e.resource_id mgr_resource_id,
d.role_relate_id role_relate_id
,g.resource_id
FROM table1 a,
table5 e,
table4 d,
table6 f,
table7 g,
table8 h ,
table2 b,
table3 c,
table9 i
WHERE 1=1
AND b.resource_id = g.resource_id
AND c.terr_id = b.terr_id
AND to_number (c.attribute3) = i.party_id
AND a.source_number = UPPER (e.salesrep_number)
AND d.role_resource_type = 'RS_INDIVIDUAL'
AND e.resource_id = d.role_resource_id
AND d.role_id = f.role_id
AND (a.start_date_active <= b.end_date_active
AND (NVL (a.end_date_active, b.end_date_active) >= b.start_date_active))
AND h.resource_id = a.resource_id
AND UPPER (g.salesrep_number) = h.source_number
GROUP BY a.source_number, c.terr_id, e.resource_id,d.start_date_active,d.end_date_active,d.role_relate_id,g.resource_id
Thanks,
LakshmiI did not understand your query but have you tried using the HAVING clause?
HAVING clause allows you to use a "where" like condition for your groupings.
See http://www.techonthenet.com/sql/having.php for some examples.
Sandeep Gandhi -
How to use alias name in where clause
Hello,
DECODE (item.inv_type,'OT', (DECODE (item.attribute2, 'STONE', 0, xfer.release_quantity1 * xfer.attribute10)
'FG', (xfer.release_quantity1 * xfer.attribute10)
) matl_val
In the above code matl_val is alias name i need to use that one in where clause as
where matl_val > 0
is this possible or anyother way can anyone help me.But the point is as you haven't read the documentation you may miss some valuable points about alias and will soon end with another problem.
>
Specify an alias for the column expression. Oracle Database will use this alias in the column heading of the result set. The AS keyword is optional. The alias effectively renames the select list item for the duration of the query. The alias can be used in the order_by_clause but not other clauses in the query.
>
http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#SQLRF01702 -
Problem with column alias: Unknown column 'avg_rating' in 'where clause'
Hello,
I have a basic sql statement as follows:
SELECT
e.establishment_id,
e.establishment_name,
avg(r.rating) avg_rating
FROM
establishment e,
rating r,
comment com,
establishment_country ec,
country_ref cou
where
etc...
and avg_rating >= 1
and 0=0
group by e.establishment_id
order by e.establishment_idI have used a column alias for "avg(r.rating)" and named it "avg_rating".
It works in my Mysql Query browser without problem but when I run it from Java I get this:
java.sql.SQLException: Unknown column 'avg_rating' in 'where clause'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2988)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2917)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:824)
at org.jboss.resource.adapter.jdbc.WrappedStatement.executeQuery(WrappedStatement.java:145)
at arcoiris.SearchSessionBean.performSearch(SearchSessionBean.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
at org.jboss.ejb.Container.invoke(Container.java:873)
at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:415)
at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:88)
at $Proxy172.performSearch(Unknown Source)
at arcoiris.SearchManagedBean.performSearch(SearchManagedBean.java:171)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)Can anyone help please?
Thanks in advance,
Julien Martin.I am having the similiar problem, the query in java creator IDE works fine after i upgraded the J-connector and changed DataSource type for MySQL to mysql-connector-java-5.0.4-bin.jar. but still i cannot bind any control in the form to the aliased column. this is really frustrating. can anyone from Sun Developer explain?
THX -
Additional where-clause for LOV in 9i needs table-alias
We have upgraded from 6.0 to 9i. All our Forms had been generated for 100% using Headstart. Now we try to generate them all again and encounter a problem with the list of values. It appears that the Additional restriction in the List of Values Properties always needs the table-alias to work properly when references are made to an item in the form.
For example:
We have item ORG_CODE in block ORG and have a lov showing all others organisations. The default-where coded in 6.0 looked like this:
org_code <> :org.org_code
In 6.0 this worked perfectly. However, in 9i the where-clause is being translated into
:org.org_code <> :org.org_code
Offcourse the lov now always gives the message that it contains no entries!
We have found a solution for this problem - rewrite the where-clause to
lov_alias.org_code <> :org.org_code
However, this solution means that we have to check tens, hundreds of lov's, because we never used to put an alias in the where-clause.
Because of this problem 95% of our Forms can not be generated anymore.
Anyone has a easy solution for this problem?I mean:
select * from T-A, T-B
where T-A.id = T-B.id (+)
and T-B.number (+) = 570
to get the null record you'll have to do:
select * from T-A, T-B
where T-A.id = T-B.id (+)
and nvl(T-B.number,0) (+) not in (0,570)
or
select * from T-A, T-B
where T-A.id = T-B.id (+)
and (T-B.number (+) <> 570
or T-B.number (+) is null)
hope that works (untested)
null -
Referencing Aggregated Column Value in Where Clause
Hello -
I'm trying to determine how I can accomplish the following in the most straightforward, efficient way.
Among other things, I'm selecting the following value from my table:
max(received_date) as last_received_dateI also need to evaluate the "last_received_date" value as a condition in my where clause. However, I can't reference my aliased "last_received_date" column value, and when I try to evaluate max(received_date) in the where clause, I get the "group function is not allowed here" error.
Does anyone know of a good workaround?
Thanks,
ChristineHi,
Column aliases can be used in the ORDER BY clause: aside from that, they cannot be used in the same query where they are defined. The workarounds are
(a) define the alias in a sub-query, and use it in a super-query, like Someoneelse did, or
(b) repeat the aliased expression, as in the HAVING-clause, below.
Aggregate functions are computed after the WHERE-clause. (That explains why you can do things like
SELECT MAX (received_date) last_received_date_2008
FROM table_x
WHERE TO_CHAR (received_date, 'YYYY') = '2008';).
The HAVING-clause is like the WHERE-clause, but it is applied after the aggregate functions are computed, e.g.
SELECT deptno
, MAX (recieved_date) AS last_received_date
FROM table_x
GROUP BY deptno
HAVING MAX (received_date) > SYSDATE - 7 -- Only show deptartments with activity in the last week
; -
VPD - How to make the where clause a correlated query
Hi,
My VPD function has the following where clause:
where_clause:= ' project_id in (select object_id from pa_project_classes p'||
' where p.class_category='||''''||l_cat||''''||
' and p.CLASS_CODE='||''''||l_class||''''||
' and p.OBJECT_TYPE=''PA_PROJECTS'''||
The problem is that the subquery is not using the unique key defined on the table pa_project_classes. What I need is something as follows:
where_clause:= ' project_id in (select object_id from pa_project_classes p'||
' where p.class_category='||''''||l_cat||''''||
' and p.CLASS_CODE='||''''||l_class||''''||
' and p.OBJECT_TYPE=''PA_PROJECTS'''||
' and p.object_id=mainquery.project_id ||
The problem is that since the table pa_project_classes also has a column project_id, I have to prefix the column name by the alias of the main query like 'mainquery.project_id'. However this seems impossible as main query is not unknown .
I would be grateful if you could suggest any workaround or solution.
ThanksJust have a look over these two statements if it solves your problem
one time where clause
Set_Block_Property('BLOCK_NAME',ONETIME_WHERE,your form item);
dynamic where clause
set_block_property('BLOCK_NAME'default_where, your form itme)
you can where clause at run time from any procedure or some triggers -
Where clause in UPDATE statement is ignored
I have the following procedure that updates a field in a table. The only problem is that all rows in the table are updated like the update statement doesn't have a where clause. When I hard code the number (733) in the where clause it works as expected. Even if I don't alias the table name it still updates all rows in the table. Any ideas?
DECLARE
extlinkid CONSTANT NUMBER := 733;
newURL CONSTANT VARCHAR2(250) := 'mailto:[email protected]';
BEGIN
UPDATE SCHEMA.TABLE A
SET A.URL = newURL
WHERE (A.EXTLINKID = extlinkid);
commit;
END;Oracle is resolving your variable extlinkid as the column in the table, so your UPDATE statement is equivalent to:
UPDATE schema.table a
SET a.url = newurl
WHERE (a.extlinkid = a.extlinkid);Which, of course, matches every record in the table. You need to change the name of your variable to something that is not a column name.
TTFN
John -
Dynamic Where Clause in select using member attribute of class
Hello,
can anybody provide me some tips how to solve this problem:
SELECT (lv_sql_select) INTO CORRESPONDING FIELDS OF TABLE lt_cntrl2
FROM (lv_db_name)
FOR ALL ENTRIES IN mt_guids
WHERE (lv_sql_where).
works perfectly fine if I use a local table variable or a member of my class. But if I build my where clause using a member attribute of my class which comes from the interace- exactly the same type and data as before I get a dump.
SELECT (lv_sql_select) INTO CORRESPONDING FIELDS OF TABLE lt_xyz
FROM (lv_db_name)
FOR ALL ENTRIES IN if_abc~mt_guids
my where clause "guid = if_abc~mt_guids-guid.
Dump:
Error analysis
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
not caught in
procedure "....GET_DATA" "(METHOD)", nor was it propagated
by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
Das laufende ABAP-Programm wollte eine Open SQL-Anweisung ausführen,
die eine dynamische Angabe enthält. Der Parser lieferte jedoch den
Fehler: "Wrong table name or table alias name table alias name
table alias name "....". table alias name
"...". table alias name "...". t"Hi Marco Freischlag,
As per my understanding , if we give for all entries we want to use internal table , For where conditions you want to pass variable , not internal table one filed,because it will not have header line...
so code like this...
SELECT (lv_sql_select) INTO CORRESPONDING FIELDS OF TABLE lt_xyz
FROM (lv_db_name)
FOR ALL ENTRIES IN if_abc~mt_guids
where guid = if_abc~mt_guids-guid. " Here pass some variable or work area in it and test.
Thanks,
Vijay SR -
Can a recursive sql have a where clause
can the following sql have a where clause and I dont want to hard code the id is is that possible...
select DISPLAY_NAME, ID, PARENT_ID, display_in_parent_folder, sub_folder_sequence
from wwsbr_all_folders start with id = 8888
connect by prior id= parent_actually g is another alias I created sorry I missed it... if I do this as a regular sub query I get three records but when I implement it as a recursive query it does not retutn any thing. Below is my regular query followed by the recursive query which I am using to organize the result but get no results:
REGULAR Query that retrieves records with parent_id = from the list of parent ids
select distinct f.DISPLAY_NAME, f.id, f.type_id, f.type_siteid, f.base_type_id, f.parent_id, f.sub_folder_sequence
from WWSBR_ALL_FOLDERS f, WWSBR_ALL_FOLDERS g
where g.parent_id = ( select g.parent_id from WWSBR_ALL_FOLDERS e
where
e.caid = 103 AND
e.parent_id <> 0 AND
e.type_id = 1 AND
e.display_in_parent_folder <> 0 AND
e.id = f.parent_id)
order by f.id, f.sub_folder_sequence;
Recursive query that results nothing:
select distinct f.DISPLAY_NAME, f.id, f.type_id, f.type_siteid, f.base_type_id, f.parent_id, f.sub_folder_sequence
from WWSBR_ALL_FOLDERS g, WWSBR_ALL_FOLDERS f start with f.id = ( select g.parent_id from WWSBR_ALL_FOLDERS e
where
e.caid = 103 AND
e.parent_id <> 0 AND
e.type_id = 1 AND
e.display_in_parent_folder <> 0 AND
e.id = f.parent_id)
connect by prior f.id= g.parent_id
order by f.id, f.sub_folder_sequence; -
Where clause in BMM (logical table Source) is not working
Hello Folks ,
I felt I ask here before I ask Siebel(oops Oracle!) support, by which I could save significant time NOT restart box multiple times , change log level , upload RPD , making multiple screen shots etc.. etc..
Here is an example the scenario
I have a custom field in the activity called the Activity source with two digit abbreviation
TX – Text message
LT – Letter
EM – Email so forth
The LOV table W_LOV_D has the type as CUST_SRC_ACT
Whoever implemented analytics they did an alias table for W_LOV_D and did a physical join between W_ACTICITY_F to W_LOV_D through field VAL
W_ACTICITY_F.X_ACT_SRC--> W_LOV_D.VAL and they did not do a where clause in BMM to retrieve only W_LOV_D.TYPE =’CUST_SRC_ACT’
So in fact the query pulls TX for CUST_SRC_ACT as well as TX for State abbreviation
I went ahead and added the where clause filter
"Siebel Data Warehouse".Catalog.dbo."Dim_W_LOV_D_Acty_Src".TYPE = 'CUST_SRC_ACT'
I saved the repository and started the server (I was doing offline) spooled the SQL and the results are the same. Looks like the filter is not being applied.
I did reload the server meta data etc..
Would anyone knows what is going on with the filter (or what I am doing wrong)?
Thanks in advance,
APhi Ap,
Pull only Dim_W_LOV_D_Acty_Src column into answers and check whether u r able to see CUST_SRC_ACT or not .Of course, you need to check sql query too
Thanks,
Saichand.v -
Appending a dynamic where clause in VO
Hi All
I am trying append a where clause dnamically to a VO
The query is
SELECT DISTINCT
pvsa.org_id AS OrgId,
GECMPoVendorsEO.VENDOR_ID AS SupplierId,
GECMPoVendorsEO.VENDOR_NAME AS SupplierName,
GECMPoVendorsEO.STANDARD_INDUSTRY_CLASS AS StdIndustryClass,
GECMPoVendorsEO.END_DATE_ACTIVE AS SupplierInactiveDate,
GECMPoVendorsEO.SEGMENT1 AS SupplierNumber
FROM PO.PO_VENDORS GECMPoVendorsEO,
po_vendor_sites_all pvsa
WHERE GECMPoVendorsEO.vendor_id = pvsa.vendor_id
AND DECODE('Y','Y', NVL(GECMPoVendorsEO.end_date_active,SYSDATE+1), SYSDATE+1) >= SYSDATE
AND DECODE('Y','Y', NVL(pvsa.inactive_date,SYSDATE+1), SYSDATE+1) >= SYSDATE
When the query is executed by OA Framework
it changes it into
SELECT * FROM (
SELECT DISTINCT
pvsa.org_id AS OrgId,
GECMPoVendorsEO.VENDOR_ID AS SupplierId,
GECMPoVendorsEO.VENDOR_NAME AS SupplierName,
GECMPoVendorsEO.STANDARD_INDUSTRY_CLASS AS StdIndustryClass,
GECMPoVendorsEO.END_DATE_ACTIVE AS SupplierInactiveDate,
GECMPoVendorsEO.SEGMENT1 AS SupplierNumber
FROM PO.PO_VENDORS GECMPoVendorsEO,
po_vendor_sites_all pvsa
WHERE GECMPoVendorsEO.vendor_id = pvsa.vendor_id
AND DECODE('Y','Y', NVL(GECMPoVendorsEO.end_date_active,SYSDATE+1), SYSDATE+1) >= SYSDATE
AND DECODE('Y','Y', NVL(pvsa.inactive_date,SYSDATE+1), SYSDATE+1) >= SYSDATE
) QRSLT
WHERE UPPER(SupplierName) like '%DEL%' AND OrgId = 468
and i need to append something like
WHERE UPPER(SupplierName) like '%DEL%' AND OrgId = 468
This clause when appended executes fine
however when i try to append
UPPER(pvsa.ATTRIBUTE12) like 'CBSI' AND OrgId = 468
then it gives me error that pvsa.ATTRIBUTE12 is invalid identifier
I need to select the value in select clause to use it outside in the where clause
but i cant select it in query since it gives me multiple values that i dont want
Have anyone faced similar issue
Is there any workaround possible for this?
Please help me out
Thanks
HusainI have come across this issue many times.
OAF framework aliases the design time query like a result set (QRSLT, consider it like a temp table). In SQL terms, the query after appending the where clause becomes like
SELECT * from QRSLT WHERE UPPER(pvsa.ATTRIBUTE12) like 'CBSI' AND OrgId = 468.
But the ATTRIBUTE12 (also pvsa alias) are not defined in the above query and the query gives an error.
One work around I have used is to use Bind Variables with the query at design time.
Hope this helps'
Srini -
Using radio button in a where clause
Dears,
I'd like to filter my result using the value of a radio button in my where clause.
Could you tell me if is it the right way to do? i get an issue in my code below
DECLARE
v_counter INTEGER := 0;
v_line VARCHAR2 (4000);
v_rec_in_row INTEGER := 12;
lpar varchar2(50);
BEGIN
HTP.prn ('<table>');
HTP.prn ('<tr>');
HTP.prn ('<td>');
lpar:=v('P48_LVAR');
CASE
WHEN lpar='SERVERS'
THEN
FOR c IN
( SELECT CASE
WHEN SERVER_MARK='SUN'
THEN '<table width="">'
|| '<tr><td><a href="#WORKSPACE_IMAGES#New Image.GIF"><img src="#WORKSPACE_IMAGES#New Image.GIF"/></td></tr>'
|| '<tr><td style="text-align:center"><h1>'
|| SERVER_NAME
|| '</td></tr></a></table>'
WHEN SERVER_MARK='HP'
THEN '<table>'
|| '<tr><td><a href="#WORKSPACE_IMAGES#New Image.GIF"><img src="#WORKSPACE_IMAGES#hp.GIF"/></td></tr>'
|| '<tr><td style="text-align:center"><h1>'
|| SERVER_NAME
|| '</td></tr></a></table>'
END AS emp
FROM SERVERS
WHERE CASE
WHEN v('P48_RA_ENV')='ALL' THEN SERVER_ENV LIKE '%'
WHEN v('P48_RA_ENV')='PROD' THEN SERVER_ENV LIKE '%PROD%'
WHEN v('P48_RA_ENV')='UAT' THEN SERVER_ENV LIKE '%UAT%'
WHEN v('P48_RA_ENV')='DEV' THEN SERVER_ENV LIKE '%DEV%'
END)Thx
CelioAcharya,
Tjis is all my code, i change it a little , it works fine in sqlworkshop but when I execute it in my page i don't get result
DECLARE
v_counter INTEGER := 0;
v_line VARCHAR2 (4000);
v_rec_in_row INTEGER := 12;
lpar varchar2(50);
BEGIN
HTP.prn ('<table>');
HTP.prn ('<tr>');
HTP.prn ('<td>');
lpar:=v('P48_LVAR');
CASE
WHEN lpar='SERVERS'
THEN
FOR c IN
( SELECT CASE
WHEN SERVER_MARK='SUN'
THEN '<table width="">'
|| '<tr><td><a href="#WORKSPACE_IMAGES#New Image.GIF"><img src="#WORKSPACE_IMAGES#New Image.GIF"/></td></tr>'
|| '<tr><td style="text-align:center"><h1>'
|| SERVER_NAME
|| '</td></tr></a></table>'
WHEN SERVER_MARK='HP'
THEN '<table>'
|| '<tr><td><a href="#WORKSPACE_IMAGES#New Image.GIF"><img src="#WORKSPACE_IMAGES#hp.GIF"/></td></tr>'
|| '<tr><td style="text-align:center"><h1>'
|| SERVER_NAME
|| '</td></tr></a></table>'
END AS emp
FROM SERVERS
WHERE SERVER_ENV LIKE CASE
WHEN v('P48_RA_ENV')='ALL' THEN '%'
WHEN v('P48_RA_ENV')='PROD' THEN '%PROD%'
WHEN v('P48_RA_ENV')='UAT' THEN '%UAT%'
WHEN v('P48_RA_ENV')='DEV' THEN '%DEV%'
END)
LOOP
v_line := v_line || c.emp || '</td><td>';
v_counter := v_counter + 1;
IF v_counter = v_rec_in_row
THEN
HTP.prn (v_line);
HTP.prn ('</td></tr><tr><td>');
v_line := NULL;
v_counter := 0;
END IF;
END LOOP;
HTP.prn (v_line);
HTP.prn ('</td></tr></table>');
WHEN lpar='ZONES'
THEN
FOR c IN
( SELECT '<table>'
|| '<tr><td><a href="#WORKSPACE_IMAGES#New Image.GIF"><img src="#WORKSPACE_IMAGES#New Image.GIF"/></td></tr>'
|| '<tr><td style="text-align:center"><h1>'
|| ZONE_NAME
|| '</td></tr></a></table>'
emp
FROM ZONES)
LOOP
v_line := v_line || c.emp || '</td><td>';
v_counter := v_counter + 1;
IF v_counter = v_rec_in_row
THEN
HTP.prn (v_line);
HTP.prn ('</td></tr><tr><td>');
v_line := NULL;
v_counter := 0;
END IF;
END LOOP;
HTP.prn (v_line);
HTP.prn ('</td></tr></table>');
WHEN lpar='ALIAS'
THEN
FOR c IN
( SELECT
'<table>'
|| '<tr><td><a href="#WORKSPACE_IMAGES#New Image.GIF"><img src="#WORKSPACE_IMAGES#New Image.GIF"/></td></tr>'
|| '<tr><td style="text-align:center"><h1>'
|| ALIAS_NAME
|| '</td></tr></a></table>'
emp
FROM ALIAS)
LOOP
v_line := v_line || c.emp || '</td><td>';
v_counter := v_counter + 1;
IF v_counter = v_rec_in_row
THEN
HTP.prn (v_line);
HTP.prn ('</td></tr><tr><td>');
v_line := NULL;
v_counter := 0;
END IF;
END LOOP;
HTP.prn (v_line);
HTP.prn ('</td></tr></table>');
WHEN lpar='FS'
THEN
FOR c IN
( SELECT
'<table>'
|| '<tr><td><a href="#WORKSPACE_IMAGES#New Image.GIF"><img src="#WORKSPACE_IMAGES#New Image.GIF"/></td></tr>'
|| '<tr><td style="text-align:center"><h1>'
|| FS_NAME
|| '</td></tr></a></table>'
emp
FROM FS
LOOP
v_line := v_line || c.emp || '</td><td>';
v_counter := v_counter + 1;
IF v_counter = v_rec_in_row
THEN
HTP.prn (v_line);
HTP.prn ('</td></tr><tr><td>');
v_line := NULL;
v_counter := 0;
END IF;
END LOOP;
HTP.prn (v_line);
HTP.prn ('</td></tr></table>');
END CASE;
END; -
Case with where clause - ORA-00920: Invalid relational operator
Hi All, when I try to run the query below, I get the following error...
ORA-00920: invalid relational operator
00920. 00000 - "invalid relational operator"
*Cause:
*Action:
Error at Line: 16 Column: 5
Does anyone know what's wrong with my query? thanks in advance.
SELECT concat (year,period)
FROM DD_ACTUALS_FACT
WHERE CASE Period
WHEN 'JAN' THEN '01'
WHEN 'FEB' THEN '02'
WHEN 'MAR' THEN '03'
WHEN 'APR' THEN '04'
WHEN 'MAY' THEN '05'
WHEN 'JUN' THEN '06'
WHEN 'JUL' THEN '07'
WHEN 'AUG' THEN '08'
WHEN 'SEP' THEN '09'
WHEN 'OCT' THEN '10'
WHEN 'NOV' THEN '11'
WHEN 'DEC' THEN '12'
END as "MonthNo"
ORDER BY CONCAT (year,"MonthNo") DESCThe problem is the as "MonthNo" - you can't give an "AS" alias to an expression in a where clause.
You have not actually given any condition, just a set of translations from period into a number.
You also haven't said what you're trying to do.
Perhaps you want:
SELECT concat (year,period)
FROM DD_ACTUALS_FACT
WHERE something
ORDER BY CONCAT (year, CASE Period
WHEN 'JAN' THEN '01'
WHEN 'FEB' THEN '02'
WHEN 'MAR' THEN '03'
WHEN 'APR' THEN '04'
WHEN 'MAY' THEN '05'
WHEN 'JUN' THEN '06'
WHEN 'JUL' THEN '07'
WHEN 'AUG' THEN '08'
WHEN 'SEP' THEN '09'
WHEN 'OCT' THEN '10'
WHEN 'NOV' THEN '11'
WHEN 'DEC' THEN '12'
END ) DESC -
Hi specialist's,
i have a simple question about a select, but I think I do not see the forrest becaus of too many trees ...
I have a table where timestamps are stored in seconds-since-epoch.
I select a human readble format with this statement:
select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS') as timestamp from txlog;
TIMESTAMP
19-10-2013 09:31:27
19-10-2013 09:31:27
19-10-2013 09:31:27
Now I want to filter i.e. for dates of 19-01....
My first try was this:
select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS') as timestamp from txlog
where timestamp like '19-%'
Result:
ORA-00904: "TIMESTAMP": invalid identifier
My next try was this:
select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS') as timestamp from txlog
where 1 like '19%'
Result: 0 rows!
If I change this to
... where 1 like '%'
I get all rows.
What is wrong with my selects ???Felix_GG wrote:
Hi specialist's,
i have a simple question about a select, but I think I do not see the forrest becaus of too many trees ...
I have a table where timestamps are stored in seconds-since-epoch.
I select a human readble format with this statement:
select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS') as timestamp from txlog;
TIMESTAMP
19-10-2013 09:31:27
19-10-2013 09:31:27
19-10-2013 09:31:27
Now I want to filter i.e. for dates of 19-01....
My first try was this:
select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS') as timestamp from txlog
where timestamp like '19-%'
Result:
ORA-00904: "TIMESTAMP": invalid identifier
My next try was this:
select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS') as timestamp from txlog
where 1 like '19%'
Result: 0 rows!
If I change this to
... where 1 like '%'
I get all rows.
What is wrong with my selects ???
Firstly, why not store timestamps as timestamps?
Anyway, Your first select refers to the alias 'timestamp' which is only accessible in an outer query, not from within the where clause.
Try
Select * from (
select to_char(DATE '1970-01-01' + TRXTIMESTAMP / (24*3600*1000), 'DD-MM-YYYY HH24:MI:SS') as timestamp from txlog
where timestamp like '19-%';
But timestamp is not a good choice for an alias, as it is a keyword.
Your second select is obvious - the number 1 will never be like '19%', but it will work
in the third select: as 1 is indeed like '%' (anything).
Maybe you are looking for
-
I got the Iphone5 a couple of days ago. Today i tooks some lovely photos and tonight i went through itunes to sync my phone and get my old contacts. In the process i have lost todays photos and the original iphone5 apps. Can i get them back?
-
Crystal 8.5 issue within vb6
Hi! I have inherited a vb6 application that uses crystal reports 8.5. I have crystal installed locally on my computer and the CD Key has been entered, as well as having vb6 local. This is the only version of Crystal on this Machine. I am able to e
-
Hello, Is it possible to create a JAVA system to use in UWL? We have webdynpro java iviews which we want to see in UWL work items. Is it possible to define portal system in UWL Administration ? Thanks a lot.
-
Symptoms: - MfE connects, downloads policy and applies policy settings, but disconnects before anything else is downloaded. 'System error' may or may not occur. If removing any of the calendar/tasks/contacts from being synced starts the sync process,
-
Want the link to open EAS IN WEb mode and also the Java API details needed
Want the link to open EAS IN WEb mode and also the Java API details needed to get it up and running. Kindly provide the answer if knows. Thanks .