Alias in long math expression

Sorry the bad english. Im from Brazil.
Oracle 8.1.7.
This is just an example for a simple demonstration.
The following sql runs perfectly:
select
1,
2,
3,
(1+2+3) as soma,
4-(1+2+3),
(6-(1+2+3)) soma2,
15-(6-(1+2+3))
from dual
Notice that expression (1+2+3) repeats frequently.
i would like to reduce the sql size using alias (or something like that) for expression (1+2+3) in the same level of dual without using subqueries.
So, the sql above would stay:
select
1,
2,
3,
(1+2+3) as soma,
4-soma,
(6-soma) soma2,
15-soma2
from dual
This is perfectly comprehensible, but doesnt work. Oracle says invalid column name for alias soma2 or soma.
Is there a form to write the sql using alias or hints (and without using subqueries) ?
Thanks.

mlinhares,
I don't think your English is bad :)
I think you can do what you want by not having to type 1+2+3 every time.
If you are using SQL*Plus then you could use parameters
select
1,
2,
3,
(&&1) as soma,
4-(&&1),
(6-(&&1)) soma2,
15-(6-(&&1))
from dual
16:59:34 SQL> l
1 select
2 1,
3 2,
4 3,
5 (&&1) as soma,
6 4-(&&1),
7 (6-(&&1)) soma2,
8 15-(6-(&&1))
9* from dual
16:59:35 SQL> /
Enter value for 1: 1+2+3
1 2
SOMA 4-(1+2+3)
15-(6-(1+2+3))
1 2
6 -2
15
1 row selected.
Elapsed: 00:00:00.00
This way you enter the value only once.
If you want to change this to, say, 2+3+4,
just do the following:
SQL > undef 1
and run the query again. You will be prompted to enter the input again.
Shakti
http://www.impact-sol.com
Developers of Guggi Oracle - Tool for DBAs and Developers

Similar Messages

  • How do I render Math expressions in my JSP pages?

    Hi,
    I am sort of a beginner using JSF. I am currently working on a project, where I need to render Math expressions such as fractions, square-roots, power-functions etc.
    The problem is, that currently all I am able to do is to use the standard text operators such as '/', '^' etc. I would like to have 'real' math expressions rendered.
    Does anyone know how to do this easiest? Is there any tag-libs available for doing so?
    I realize it is doable using HTML, but because of the design of my application, it is not an option to insert HTML directly into the JSP pages.
    Thanks in advance :)
    Best Regards
    Thomas

    Thank you for the quick answer!
    My problem is not to do the math, my problem is how to display the math on the JSP page. I want to display fractions, power-functions, square roots with the actual mathmatical symbols, not the symbols mentioned above (/, ^, sqrt, etc.).
    Does anyone know how to do this, or if there exists any taglibs?

  • How long does express replacement take for an Iphone 4s??

    My iPhone 4s broke today, and I called for an express replacement for it. They charged $30 for it, and put the order in.
    The representative failed to mention what I'm supposed to do and how long it would take for my new iphone to come in. I also failed to ask him these questions, I dont know why..
    So how long will it take for my new iPhone to come in, and what do I do with my current broken iPhone once the new one does come in?

    Instead of waiting here for a response, why don't you just call them back and ask?

  • Math expression in query

    Running Oracle 10g on Solaris 10 SPARC
    I have this expression within a query that I would like to round off to the nearest hundreths:
    select (x.VALUE/4800.00)*100 as Percentage,
    Value is equal to: 4145.22 I want the display to be:86.35 not 86.35875 (or 86.36 if we can round up/down versus truncation)
    Thanks

    ME_XE?select round(86.35875, 2) from dual;
    ROUND(86.35875,2)
                 86.36
    1 row selected.
    Elapsed: 00:00:00.81
    ME_XE?
    ME_XE?select round(86.35375, 2) from dual;
    ROUND(86.35375,2)
                 86.35
    1 row selected.
    Elapsed: 00:00:00.31

  • Evaluate math expression

    Hi Guys,
    I need to write java command line program to evaluate a mathematical
    expression input by user without parantheses using Stack approach.
    Can anyone give me the clue how to start of with.
    Is it possible to evaluate the expression in infix notation directly using stack, without converting to prefix notation.
    Thanks in advance

    Is there something nicer?You can also use java 6 and javascripts. I saw a
    thread where someone posted an example.
    KajI posted something a couple of weeks back (reply #2):
    http://forum.java.sun.com/thread.jspa?threadID=5137192
    Of course, you don't need to bind any variables and can do it like this:import javax.script.ScriptEngine;
    import javax.script.ScriptEngineManager;
    import javax.script.ScriptException;
    public class ScriptDemo {
        public static void main(String[] args) {
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName("js");
            try {
                String expression = "3+4";
                Object result = engine.eval(expression);
                System.out.println(expression+" = "+result);
            } catch(ScriptException se) {
                se.printStackTrace();
        output: 3+4 = 7.0
    */

  • CFScript Math expression - Summing up looped over data

    If I loop over numeric data and  I want to sum that data I am looking for the correct manner to do so. Of course I want to do this in cfscript.
    I know that I could go the route of doing a one demensional array and using the array sum function and I could also use stauctures.
    I am interested in different solutions to this problem.
    My end state is that I need to sum and average looped dynamic data for reporting purposes.
    For purposes of example static values will be helpful for better understanding.
    Thanks in advance.

    Owain,
    This is what I came up with and it outputs the looped data. Now I am trying to add it up and average the results.
    BTW Adam,
    Be delusional on a Microsoft or Oracle forum board.
    Now that would be some fun reading cutting through those flames! (In a patronising Kinda Way!).

  • Date Format in PeopleSoft Query Expressions

    Hello,
    I have devloped a query where one of the field has date field. The format that's showing is 'MM/DD/YYYY'. We want the format in 'MM-DD-YYYY'. I tried to create a expression using to_char(A.fieldname,'MM-DD-YYYY'). But its not working. Is there any other way we can get the format in 'MM/DD/YYYY' from query manager.
    Thanks,
    -Sam

    Hi Sam,
    PS Query will automatically wrap date fields in the select list with TO_CHAR(...,'YYYY-MM-DD'), even in an expression. However, it only does this when the fieldname includes the alias, so in your expression you could use
    to_char(fieldname,'MM-DD-YYYY') (no A.) as long as it doesn't cause an ambiguous reference (i.e. there are no other tables in your query with "fieldname" as a column). Otherwise, you could write your expression to convert the TO_CHAR result back to a date and then use TO_CHAR again. i.e.
    TO_CHAR(TO_DATE(A.fieldname,'YYYY-MM-DD'),'MM-DD-YYYY')If you look at the resulting SQL, this will become
    TO_CHAR(TO_DATE(TO_CHAR(A.fieldname,'YYYY-MM-DD'),'YYYY-MM-DD'),'MM-DD-YYYY')which should give the desired result.
    Regards,
    Bob

  • Values of expressions????

    Could anyone tell me what is the type and value of these expressions?
    1. 'z'-'A'
    2. 12E3F
    3. (long)Math.random()
    4. new byte[4][5].length
    5. new int[4].length
    6. new Object() == new Object ()
    Thanks!

    int, float, long, int, int, boolean

  • UCalc Fast Math Parser for LabVIEW?

    Several customers have been using the uCalc math parser product with LabVIEW.  Recently one LabVIEW / uCalc user has attracted my attention to the fact that the new version of uCalc FMP is now harder to use with LabVIEW.  Direct support for LabVIEW was never figured into the design of uCalc.  It just so happened that the older uCalc version worked with it.  Now, I’d like to figure out if there are enough potential uCalc FMP users to make it worth adding direct support for LabVIEW.
    uCalc FMP lets you evaluate math expressions that are defined at runtime.  You can define functions, operators, and variables, and use them in your formulas.  The older version that is easier to use with LabVIEW can be found at www.ucalc.com/mathparser/ucfmp20.zip (you won’t find the old version in the current download page for now).
    I myself have no experience with LabVIEW.  However, with some 3rd party help, the user who contacted me recently was able to interface the new uCalc version with LabVIEW.  Perhaps LabVIEW developers may want to weigh in.  Might you be able to create an “official” uCalc FMP wrapper for the current version of uCalc, or give some tips on what it would take for me to do it?
    Daniel Corbier
    www.ucalc.com

    In the previous DLL, I exported a series of functions such as an eval routine that returns the result of evaluating an expression, as in
    ucEval("5+4")
    which would return 9; a routine to define functions as in
    ucDefineFunction("Area(length, width) = length * width")
    or variables as in
    ucDefineVariable("MyVar = 123") 
    plus a list of other routines.
    The new version was completely redesigned.  You can do a lot more.  However, one exported function named uCalc() encapsulates most of the component's functionality.  Instead of exporting many routines from the DLL, wrappers for routines like ucEval, ucDefineFunction, ucParse, etc., are defined in include files for the supported compilers.  On the surface, things run roughly the same for the supported compilers, despite the changes under the hood.  But apparently not so for LabVIEW.
    ucDefineVariable for instance, which previously was directly exported from the uCalc DLL is now defined as follows in the include file for Visual Basic (classic):
    Public Function ucDefineVariable(Definition As String, Optional ItemAddress As Long = 0, Optional ByVal t As Long = 0) As Long
       Dim ItemDef$
       ItemDef$ = "Var: " + Definition
       If ItemAddress Then ItemDef$ = ItemDef$ + " At " + Str$(ItemAddress)
       ucDefineVariable = uCalc(uc_Define, ItemDef$, 0, 0, 0, t)
    End Function
    By the way, what is the link to download the evaluation version of LabVIEW?  I found links for the tutorial.  And there's a "Test-Drive LabView" link that brings me to an online evaluation version.
    Daniel Corbier
    www.ucalc.com

  • Unable to create my third alias

    hello all
    For several weeks I deleted one of my three aliases, and it's been weeks since icloud says I have to wait seven days to create a third alias on the three available. Out within seven days to have the freedom to create my third alias is long past, but still can not make this alias.
    If you have an idea, thank you
    Best regards
    Bruno

    Looks like this thread answers my question.

  • How to use math symbols in a right to left text properly?

    Hey there
    When I write a simple mathematical equation or a number(which has sign) in the middle of a right to left text in a text box(I simply set keyboard language to EN for typing expressions & numbers) it's like mathematical symbols are somehow not considered math symbols and that's weird since in word it's not that way, take the following sentence for example that means result of the 0-127 expression is -127:
    حاصل عبارت 127-0 برابر 127- است.
    In word I can type it just fine(for typing expressions and numbers I set keyboard language to EN) but when I type it the same way in adobe acrobat I get this:
    حاصل عبارت 0-127 برابر -127 است.
    copy & paste from word also doesn't do any help, so If I want to get it right I should type math expressions from right to left meaning as instance to type 0-127 I should first type 127 then - and finally 0 also should type digits of a number before typing its sign as example for typing -127 I should first type 127 then - ,now I wonder is it the way acrobat works or I'm doing something wrong.
    By the way OMG o_O even when I did copy & paste my messasge from word to the text box of forum for posting, it ended up treating math parts in upper right to left paragraph the same way as acrobat  I just had to write them from right to left!
    Anyone has any idea?
    Message was edited by: Pooria

    In a word document I wrote:
    حاصل عبارت 127-0 برابر 127- اسـت
    Then tried printing it using "Adobe PDF" printer, in output pdf that sentence was written in right order and interestingly it was broken into three text boxes   thanks for reply.

  • 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

  • Java Math

    I have an assignment due tomorrow to create a stock market screen. It is suppose to display the stock symbol, purchase price, number of shares, the current stock price, and then calculate the following worth bought gain/loss. I do not have a clue were to start. If anyone could help, please do feel free to e-mail me any comments. Thank you in advance. It seems the instructor is overloaded with others asking questions.
    P.S. there should be at least nine methods for this class.

    public class Stock
         //Instance variables
         public String price;
         public String shares;
         public String numOfShares;
         public long val;
         public Stock(String price)
              this.price = price;
              //count = + 1
    //          count ++; //increments the variable count
    //          counter++; //increment the class variable counter
         public String toString()
         //Default Constructor
         //public String toString()
         String str = "The price is:"+ price +" \tand the shares is:" + shares +" \tand the number of shares is " + numOfShares;
              return str;
              price = "36 ";
              //Parameterized Constructor
              public Stock(String pr,String sh,String num,long val)
              //set some default values for the instance variables
              price = "pr";
              shares = "sh";
              numOfShares = "num";
              generateval();
         public void setPrice(String pr)
         public void setShares(String sh)
         public void numOfShares(String num)
    //this will generate a value number useing theMath.random() method
         public void generateval()
         val =(long)(Math.random() * 100 + 1);
                   Stock pr = new Stock ("price of stock");
                   System.out.println(pr.toString());
                   Stock sh = new Stock("price of shares");
                   System.out.println(sh.toString());
                   Stock num = new Stock("number of shares");
                   System.out.println(num.toString());
                             pr.toString();
                             sh.toString();
                             num.toString();
         public String getPrice()
              //price
              return price;
         public String getShares()
              //shares
              return shares;
         public String numOfShares()
              return numOfShares;
         public float getval()
              return val;
    } //end of class

  • BUG?? Syntax Highlighting Regular Expressions

    I'm working on a rather long regular expression in
    dreamweaver code view. It has about 200+ characters in it.
    I wrote it in another application and copied it over for use
    in js, and it wouldn't highlight correctly (sort of like when you
    leave off quote on a string). Naturally I thought I screwed up my
    regexp or forgot to escape a character or something so I went
    through it re-writing it and checking everything but it was
    correct. I saved the page and ran it in the browser and sure enough
    it worked.
    So I started typing the regexp from scratch this time in
    dreamweaver to see when it stopped highlighting correctly. It
    stopped at exactly 100 characters including opening and closing
    forward slashes. I tried writing another exp this time filled with
    just one letter. Again 100 characters exactly - not one more.
    Example:
    var reg1 =
    /ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss ssssssssss/
    var reg2 =
    /ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss sssssssssss/
    reg1 will highlight correctly, while reg2 won't.
    Is this a bug or am I missing something? The highlight rule
    (in Configuration\CodeColoring\CodeColoring.xml) is
    (\s*/\e*\\/
    -or-
    =\s*/ \e*\\ /
    There seems to be no limitation to length there.
    While this is not a huge deal, I might as was well be coding
    in notepad (or my other script editors which highlight this
    correctly) because the highlighting is worthless from this point
    on.
    I could make these strings instead of literals but I have a
    lot of these long expressions and would rather not go through them
    and escape all of my back slashes (there are tons) as well as
    quotes - and make them more un-maintainable as they already are.
    Anyone have this problem? Or a solution to it?

    random_acts wrote:
    > I'm working on a rather long regular expression in
    dreamweaver code view. It
    > has about 200+ characters in it.
    I have never written a regex as long as that, but was
    fascinated by your
    question, so attempted to replicate your problem.
    I gave up at 614 characters, but the syntax coloring didn't.
    I suggest
    that you submit a bug report with the details of your actual
    code:
    http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
    David Powers
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    http://foundationphp.com/

  • Regular expressions its URGENT !!!

    i have a long string of regular expressions seperated by "|" and i need to know which regular expression the particular string matched how can i find that and can i do it using java .util.regex
    thanks in advance

    Consider to use "capturing groups" or a better solution should be to split this long regular expression with alternations in small ones that will cause considerable reduction in backtracking. Also in this way will be easier to find what regular expression matches the target string.
    Regards.

Maybe you are looking for

  • How do I find outlook email on an Seagate external hard drive?

    Hi - I have a Seagate external hard drive that I used to back up an old mac book pro.  I have found all my documents and was able to transfer them all to a mac  mini.  However I can not find the email files.  I had outlook and am trying to find the e

  • TV@nywhere Dual Monitor Problem

    I have the regular TV@nywhere card.. Has anyone else had this problem? I have a dual monitor setup (extended desktop) on an ATI 9000 pro.. At some point over the last few months I began having problems dragging the WinDVR (player) window from one mon

  • Samsung Monitor Driver

    Where can I find the Samsung SyncMaster 750s driver for Solaris 7? Thanks,

  • I need to cancel an order urgently!!

    I need to cancel an order from the Apple store, but there's not contact number in my country. How can I do?

  • Ignore Find Sequence dialog box

    During the execution if TestStand does not the .seq file, it display's the dialog for Find <missing sequence name>.seq dialog. I would like to avoid displaying that dialog to the user and continue the execution with the next available sequnce. Is the