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

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,
    Lakshmi

    I 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 CASE stmt in Where clause

    Hi,
    How to use CASE stmt in WHERE clause?. I need the code. Please send me as early as possible..........

    Hi,
    1004977 wrote:
    Hi,
    How to use CASE stmt in WHERE clause?. There's no difference between how a CASE expression is used in a WHERE clause, and how it is used in any other clause. CASE ... END always returns a single scalar value, and it can be used almost anywere a single scalar expression (such as a column, a literal, a single-row function, a + operation, ...) can be used.
    CASE expressions aren't needed in WHERE clauses very much. The reason CASE expressions are so useful is that they allow you to do IF-THEN-ELSE logic anywhere in SQL. The WHERE clause already allows you to do IF-THEN-ELSE logic, usually in a more convenient way.
    I need the code.So do the peple who want t help you. Post a query where you'd like to use a CASE expression in the WHERE clause. Post CREATE TABLE and INSERT statements for any tables used unless they are commonly available, such as scott.emp). Also, post the results you want from that sample data, and explain how you get those resuts from that data.
    See the forum FAQ {message:id=9360002}
    Please send me as early as possible..........As mentioned bfore, that's rude. It's also self-defeating. Nobody will refuse to help you because you don't appear pushy enough, but some people will refuse to help you if you appear too pushy.

  • How to use between timestamp in where clause

    Hi All,
    i have a colum column2 of data type timestamp.now i wants to fatch record having between two date of column2.how to use between operator in where condition having column as timespamp'

    Hi,
    You can use a timestamp literal, or use a function that return a timestamp datatype, here is an example:
    (TIMESTAMP 'YYYY-MM-DD HH24:MI:SS.FF')
    select * from yourtable where column2 between TIMESTAMP '1997-01-31 09:26:50.12' and  systimestampHave a look to the documentation, for example http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch4datetime.htm

  • How to use Alias name in OData service in SAP HANA

    Hi,
         I need to change one column name with alias of another name in odata service definition or odata url running in rest client. I am trying to give alias name with as key in the service definition like sql query.
    ex:
    There is one table with column name of PRODUCT_ID. I exporting that table via odata service to SAP UI. In the UI i dont want the product id column as PRODUCT_ID. It should be ike "Prodcut". Like we are using in SQL example
    select "PRODUCT_ID" as "Product" from "producttab";
    But i can't use as key for alias name. So i am getting syntax error.
    I have tried in rest client also ie executing odata file in rest based service. But i got error only.
    If anyone knows about this alias name in odata service, Please help me to resolve this issue..

    Hi Thomas
         Thanks for your reply.
         Actually in odata service definition i am using attribute and calculation views only. But in some case from the model view itself i need to use some alias names to the UI through odata service.
         For example in attribute view i have some columns with name col1,col2... I am getting those columns in UI using  odata service, for particular col2 column i need to change column name as product. And i am using the same view as source of another odata service in that service i need to change that column name as productname.
         In that case i need alias name usage. So that only i am searching alias keyword in odata service.
         Is there any possibility to use alias names in odata service.

  • How to use case function in where clause

    Hi,
    Suppose a table DEMO has columns
    DEMO TABLE
    user_id
    user_name
    location
    In this table i have 15 users. but out of 15 users i want to use only 5 users for passing as user_name.
    then how to achieve the result
    1. when i pass the particular 5 user_name in where clause then i should get all the user_name and for other 10 users it will show only the passing user_name.
    how to use case function

    Do you mean this ?
    SQL> var name varchar2(10)
    SQL> exec :name := 'ALLEN'
    PL/SQL procedure successfully completed.
    SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
      2  else :name end = ename;
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> exec :name := 'SMITH'
    PL/SQL procedure successfully completed.
    SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
      2  else :name end = ename;
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> exec :name := 'BLAKE'
    PL/SQL procedure successfully completed.
    SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
      2  else :name end = ename;
    ENAME
    BLAKERgds.

  • How to use string operation in where clause of select query

    Hello All,
    I just want to know how can i write a restriction in select query saying retrive data only begins with name "DE*".
    Explaination: If my table has records and names starts with character then i want to write a query to fetch all the records in which names starts with DE*.
    Thanks in advance for your quick reply...
    Dev.

    Hi
    In the where clause you need to write like
    WHERE NAME LIKE 'DE%'
    Regards
    Sudheer

  • How to use MONTH NAME in where condition in date column?

    Hi dudes,
    this is the table.
    sql>desc ACMINUTESPDFTEST;
    Name Null? Type
    ACDATE DATE
    TYPES VARCHAR2(10)
    here i have tried the following 2 queries,but i could not get the correct result
    select types,seqno,acdate from ACMINUTESPDFTEST where acdate like to_date('NOV','MON');
    or
    select types,seqno,acdate from ACMINUTESPDFTEST where acdate = to_date('NOV','MON');
    (for both the query the output is same)
    TYPES ACDATE
    PINK 01-NOV-10
    but the table having following data:
    TYPES ACDATE
    PINK 14-NOV-10
    WHITE 15-NOV-10
    PINK 01-NOV-10
    Any suggestion why i could not get correct result.

    bharathit wrote:
    Thanks for toon and divya...it solved my problem and my question how will you select between two months..
    select types,acdate from ACMINUTESPDFTEST where to_char(acdate,'MON') >= 'SEP' AND to_char(acdate,'MON') <= 'OCT';
    and i got
    no rows selected
    Edited by: bharathit on Nov 2, 2010 10:37 PMIf you're interested in finding dates in a range of months regardless of the year then try this:
    select ...
    from   ...
    where  to_number(to_char(date_column,'MM')) Between 9 And 10;You could also do something like:
    select ...
    from   ...
    where  to_number(to_char(date_column,'MM')) In (1,4,7,10);If you are interested in dates in a range of months in a particular year however, use something like this:
    select ...
    from   ...
    where  date_column >= date '2010-09-01' and
           date_column < date '2010-11-01' and

  • How to use DATE in the where clause

    I need to select list of records from a table where available date is greater than or equal to current date. Below is the table structure and
    select query used to get the list of records
    CREATE TABLE TEMP (ITEM_ID NUMBER(20),ITEM_NAME VARCHAR2(100),CREATION_DATE DATE,AVAILABLE_DATE DATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(1,'ITEM1',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(2,'ITEM2',SYSDATE,SYSDATE+10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(3,'ITEM3',SYSDATE,SYSDATE-10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(4,'ITEM4',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(5,'ITEM5',SYSDATE,SYSDATE+5);
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date > SYSDATE OR available_date LIKE SYSDATE;I am getting the expected records but i am not able to find a condition where i can use *>=* for date data type, a query like the below one is
    not returning expected records
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date >= SYSDATE ;Edited by: Balaji on Mar 19, 2012 9:13 PM

    Hi,
    Balaji wrote:
    I need to select list of records from a table where available date is greater than or equal to current date. Below is the table structure and
    select query used to get the list of records
    CREATE TABLE TEMP (ITEM_ID NUMBER(20),ITEM_NAME VARCHAR2(100),CREATION_DATE DATE,AVAILABLE_DATE DATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(1,'ITEM1',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(2,'ITEM2',SYSDATE,SYSDATE+10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(3,'ITEM3',SYSDATE,SYSDATE-10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(4,'ITEM4',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(5,'ITEM5',SYSDATE,SYSDATE+5);
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date > SYSDATE OR available_date LIKE SYSDATE;
    Both operands to LIKE are supposed to be strings. Don't try to use a DATE, such as SYSDATE, with LIKE.
    I am getting the expected records but i am not able to find a condition where i can use *>=* for date data type, a query like the below one is
    not returning expected records
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date >= SYSDATE ;
    It's returning the results I expect.
    If you'd say what results you were expecting, someone could help you wite a query to get them.
    Assuming 1 second elapses between the time 'ITEM4' is inserted and the time the 2nd query is run, then, at run-time, available_date will be 1 second less than SYSDATE, so it should not be included.
    If you want to find rows that are on the same calendar day as SYSDATE, or later, then use
    WHERE    available_date >= TRUNC (SYSDATE)

  • How to use division with a Where() clause

    I have to report four specific time periods dynamically so I made Date variables. I cannot use division of the metrics without applying the date codes to the individual metrics. There has to be a way I am not thinking of. This is a massive report so I need to keep variables to a minimum.
    Example:
    [Sales 1] / [Quota 1] = Percent to Quota
    I have a Date Variable for Quarter to Date: [Months in QTD] That returns multiple "Fiscal Periods" (months) per date formulas
    However, to get the right time period data using DIVISION, say for Quarter To Date I have to use:
    [Sales 1] Where( [Fiscal Period] = [Months In QTD]) / [Quota 1] Where( [Fiscal Period] = [Months In QTD])
    The above returns the correct value for the three months in the quarter.
    That would be OK except I need an IF..Then..ElseIf..Else statement to solve for zeros and nulls and it gets very long adding the “Where( [Fiscal Period] = [Months In QTD])” to every measure in the statement.
    I have tried nesting:  =(SUM(  [Sales 1] ) / Sum( [Quota 1) ) Where( [Fiscal Period] = [Months In QTD])
    And that does not work as with other attempts to nest.
    I tried an IF( [Fiscal Period] = [Months In QTD] … but it returns MULTI error I assume becaause the variable [Months in QTD] delivers more that one Fiscal Period.
    Come on brainac’s.  Division has its own rules but there should be a way.
    Thank you.

    Hi,
    Just to give you rough idea. I would suggest you to apply following logic at query level.
    Create a query with prompt and try to get Months in QTD there only a single object.
    Now apply filter on second query "where result from another query" that will filter data for perticular quarter.
    I hope you can understand.
    Thanks,
    Swapnil

  • How can we use DECODE function in where clause.

    Hi Guys,
    I have to use DECODE function in where clause.
    like below
    select * from tab1,tab2
    where a.tab1 = b.tab2
    and decode(code, 'a','approved')
    in this manner its not accepting?
    Can any one help me on this or any other aproach?
    Thanks
    -LKR

    >
    I am looking for to decode the actual db value something in different for my report.
    like if A then Accepted
    elseif R then Rejected
    elseif D then Denied
    these conditions I have to check in where clause.
    >
    what are you trying to do?
    may be you are looking for
    select * from tab1,tab2
    where a.tab1 = b.tab2
    and
       (decode(:code, 'A','Accepted') = <table_column>
        or
        decode(:code, 'R','Rejected') = <table_column>
       or
        decode(:code, 'D','Denied') = <table_column>
       )

  • How to Concatenate Table name and Where condition at runtime

    I am passing parameter as User and Zone to Stored Procedure.How to concatenate Table Name
    and WHERE CONDITION in SQL Statement.i have different type of users and zones.

    Hi !
    declare
      cur sys_refcursor;
      r emp%rowtype;
      v_sql varchar2(512);
    begin
    -- do your logic here
      v_sql := 'select * from emp';
      open cur for v_sql;
      loop
        fetch cur into r;
        exit when cur%notfound;
        dbms_output.put_line(r.ename);
      end loop;
      close cur;
    end;In this example you can see how can be done this with cursor vars .. You should concatenate v_sql string according to your requirements.
    But as in further posts has already been mentioned , be carefull at publishing such kind of procedures and think on security.
    Also when you want dynamicaly change from clause , you should consider using different records to accept data ? Maybe all your tables has the same structure and then this problem will be smaller.
    T
    T

  • Using alias name from view

    Can I create somehow a view like this one:
    CREATE VIEW clerk_view AS
       SELECT employee_id as ei, last_name as ln, department_id as di
       FROM employees
       WHERE job_id = 'PU_CLERK' ;and using this view with aliases, e.g.:
    select * from clerk_view where ln = 'Mickey';
    My Oracle database version is 11.2.0.3
    Best.

    Hi,
    lesak wrote:
    So can you tell me what I'm missing in above CREATE statement? Sorry, no, not without knowing exactly what you're doing. That's why you need to post a complete test script that people can run to re-create the problem. Except for the identifier LN, there's nothing wrong with the code you posted per se , but there could be millions of things wrong with how how you're trying to use it. Even if I could post millions of suggestions, you wouldn';t want to read them all, just to fond the one or two that apply to your case. So way exactly what your case is. Post a complete test script that creates and populates the table (if necessay), calls the view, tries to use the view, and gets the error.
    When I create view in the same way in production and use alias name, I've got following error: ORA-00904. Not everyone who wants to help you has all the error codes memorized. That's why you should post the complete error message.
    So Oracle don't know that my employee_id or other column have also alias name?!Sure, it will know the alias name. That's exactly what aliases are for.

  • How to specify alias name in system property while making 2way SSL con ?

    Hi All,
    I am tring to run a java client with 2way SSL which uses CAC card as keystore for the client. I have addded the following system property in my client program to make it work and change the java.security file to add pcks11 provider.
    System.setProperty("javax.net.ssl.keyStoreType", "pkcs11");
    System.setProperty("javax.net.debug", "ssl");
    The program works fine and handshake is successfully done . But the problem is when i have more than one trusted certificate in the CAC card, it take a default certificate. I want to specify the certificate that should be used to do the client auth maybe specify the alias name . I didnt find any system property to do so.
    Please let me know how to specify alias name as system property so that the 2way SSL used the specified alias for the client auth or is there any other way to specify the alias name. As in case i acccess the server URL from any browser i get a certificate selection prompt and the connection is established with the selected certificate.
    Thanks in advanced,
    Ruhul

    I didn't find any system property to do so.There isn't one.
    Please let me know how to specify alias name as system propertyYou can't.
    You would have to write a custom KeyManager. See the JSSE Reference Guide.

  • How to get alias name of stored certificate from iKey token 2032

    Hi All,
    Below is my code woks well to use the same keypair for both encrypt/decryprt-SunPKCS#11 in SDK1.5. In my code i hard coded alias name of certificate, kindly tell me how to read alias name of certificate from iKey token 2032??
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    import java.sql.*;
    import java.text.*;
    import java.math.*;
    import java.security.*;
    import java.security.cert.*;
    import java.security.interfaces.*;
    import javax.crypto.interfaces.*;
    import javax.net.ssl.*;
    import javax.crypto.*;
    import javax.crypto.spec.DESKeySpec;
    import java.security.KeyStore.*;
    public class Encrypt
    public Encrypt(){}
    public void loginToken() {
    Provider p = new sun.security.pkcs11.SunPKCS11(MQConfig.getvalue("SecurityPropertyPath"));
    String myAlias = "349eefd1-845b-4ba4-9f88-06e9f5cb82f6";
    /** to view alias name
    keytool -list -v -keystore NONE -storetype PKCS11 -storepass PASSWORD
    Security.addProvider(p);
    KeyStore ks = null;
    PrivateKey privKey = null;
    PublicKey pubKey = null;
    try{
    String password = General.ReadFiles(MQConfig.getvalue("logFilePath"),"Simple");
    password = password.trim();
    char pin[] = password.toCharArray();
    ks = KeyStore.getInstance("pkcs11");
    ks.load(null,pin);
    java.security.cert.Certificate cert = ks.getCertificate(myAlias);
    Key key = ks.getKey(myAlias, pin);
    if(PrivateKey.class.isInstance(key)) {
    privKey = (PrivateKey)key;
    pubKey = cert.getPublicKey();
    FileInputStream in = new FileInputStream("C:\\ReportDBBE.properties");
    FileOutputStream out = new FileOutputStream("C:\\ReportDBAE.properties");
    Cipher cp=Cipher.getInstance("RSA/ECB/PKCS1Padding", p);
    cp.init(cp.ENCRYPT_MODE,pubKey);
    CipherOutputStream cout=new CipherOutputStream(out,cp);
    byte[] input=new byte[8];
    int byteread=in.read(input);
    while(byteread!=-1){
    cout.write(input,0,byteread);
    byteread=in.read(input);
    cout.flush();
    in.close();
    cout.close();
    catch(NoSuchAlgorithmException nsae)
    System.out.println("No Such Algorithm Exception " + nsae.getMessage());
    catch(NoSuchPaddingException nspe)
    System.out.println("No Such Padding Exception " + nspe.getMessage());
    catch(InvalidKeyException ike)
    System.out.println("Invalid Key Exception " + ike.getMessage());
    ike.printStackTrace();
    catch(IllegalStateException ise)
    System.out.println("Illegal State Exception " + ise.getMessage());
    catch(KeyStoreException kse)
    System.out.println("Key Store Exception " + kse.getMessage());
    catch(CertificateException ce)
    System.out.println("Certificate Exception " + ce.getMessage());
    catch(IOException ioe)
    System.out.println("IO Exception " + ioe.getMessage());
    catch(UnrecoverableKeyException unrke)
    System.out.println("Unrecoverable Key Exception " + unrke.getMessage());
    public static void main (String args[]) throws Exception {
    try{
    Encrypt tl = new Encrypt();
    tl.loginToken();
    }catch(Exception e){
    e.printStackTrace();
    Your help is very much appreciated!!!!

    Hi All,
    Now i managed to get alias name.
              char pin[] = password.toCharArray();
              ks = KeyStore.getInstance("pkcs11");
              ks.load(null,pin);
    Enumeration ea = ks.aliases();
              while(ea.hasMoreElements()) {
              myAlias = (String)ea.nextElement();
              }

Maybe you are looking for

  • Can no longer connect to j2ee engine

    I recently posted about an XI 3.0 Demo problem that was fixed by changing the icm/host_name_full parameter in the instance profile to a FQDN (thanks again for the help Alwin!).  However, without being able to actually determine why, as we didn’t chan

  • Can't edit html

    I have Dreamweaver CS5. Someone asked me to look at their website as it wasn't displaying correctly in IE v8. I downloaded the page and opened it in Dreamweaver but I can't edit the html. I When I tried to delete some code it didn't move. Any ideas w

  • LogShipping: recover_replace of logs too slow. Can we tune it?

    Hello, after having trouble with bad pages on MaxDB we built up a standby db with LogShipping to be prepared for future trouble. All in all, it works. We wrote a script, that makes a dbmcli session. It begins with recover_start, after that it continu

  • Safari keeps crashing on the MacBook Pro

    Please can someone help! Everytime I load safari to look at a website it crashes. Thanks

  • Tree on Dyanamic region . Uncommited data means warn me

    hi jdev experts, am using jdev 11.1.1.5.0 - adfbc - oracle db10g. what i did: am using af:tree. on that tree leaves holds command links. if i hit that links means one dynamic regions(jsff) will opens. it's ok all are fine. but my need: i did some cha