How does one evaluate an expression stored as a VARCHAR 2 in a table?

I am attempting to write a single SQL statement that will select three columns of data from a table and based on the value of a string in one column perform a calculation using the other two columns. Here is an example. TableX contains three columns. For simplicity sake let's say Col1 and Col2 are Number(5) and Col3 is a VARCHAR2(25).
TableX
Col1 Col2 Col3
5 7 Col1+Col2
10 3 Col1*Col2
20 5 Col1/Col2
I would like to write an SQL statement like 'select Col1, Col2, evaluate(Col3) as "Eval" from TableX' and get the following result set back.
Col1 Col2 Eval
5 7 12
10 3 30
20 5 4
Is there an Oracle provided function like the hypothetical evaluate() provided above that will do this?
One potential solution would be to write a stored procedure that accepts the three columns as parameters and then performs an execute immediate and returns the result. However, I would like a more dynamic utility so I don't have to be resticted to a preset number of columns (3 in this example).
Any ideas would be greatly appreciated.
Thanks,
Matt

Matthew:
There is no evaluate function in Oracle, and as far as I know, there is no way to do what you want solely in sql. However, this function should do the trick.
SQL> CREATE OR REPLACE FUNCTION my_eval (
  2     p_tab_name IN VARCHAR2,
  3     p_rowid IN ROWID,
  4     p_calc_col IN VARCHAR2) RETURN NUMBER IS
  5
  6  sqlstr VARCHAR2(4000);
  7  result NUMBER;
  8  BEGIN
  9     sqlstr:= 'SELECT '||p_calc_col||' FROM '||p_tab_name||' WHERE rowid = :b';
10     EXECUTE IMMEDIATE sqlstr INTO result USING p_rowid;
11     RETURN result;
12  END;
13  /
Function created.
SQL> CREATE TABLE jtest (col1 number,col2 number,col3 varchar2(50));
Table created.
SQL> INSERT INTO jtest values (5, 7, 'Col1+Col2');
1 row created.
SQL> INSERT INTO jtest values (10, 3, 'Col1*Col2');
1 row created.
SQL> INSERT INTO jtest values (20, 5, 'Col1/Col2');
1 row created.
SQL> commit;
Commit complete.
SQL> SELECT col1,col2,col3,MY_EVAL('jtest',rowid,col3) evald
  2  FROM jtest
  3  /
      COL1       COL2 COL3                           EVALD
         5          7 Col1+Col2                         12
        10          3 Col1*Col2                         30
        20          5 Col1/Col2                          4
SQL> DROP TABLE jtest;
Table dropped.
SQL> CREATE TABLE jtest (col1 number,col2 number,col3 number,col4 varchar2(50));
Table created.
SQL> INSERT INTO jtest values (5, 7, 2, '(Col1+Col2)/Col3');
1 row created.
SQL> INSERT INTO jtest values (10, 3, 5, 'Col1*(Col2+Col3)');
1 row created.
SQL> INSERT INTO jtest values (20, 5, 2, 'Col1/Col2/Col3');
1 row created.
SQL> commit;
Commit complete.
SQL> SELECT col1,col2,col3,col4,MY_EVAL('jtest',rowid,col4) evald
  2  FROM jtest;
      COL1       COL2       COL3 COL4                           EVALD
         5          7          2 (Col1+Col2)/Col3                   6
        10          3          5 Col1*(Col2+Col3)                  80
        20          5          2 Col1/Col2/Col3                     2This could easily be extended to handle character functions as well.
John

Similar Messages

  • How does one install a express sql server to run with Visual Web Developer 2008?

    I successfully installed .NET framework v 3.5 and VWD 2008 on a new Vista laptop. When I want to add a Sql Server database to a website, errors tell me to install SS 2005 Express. MSDN SS 2005 Express download tells me I MUST  first install .NET framework v 2.0 before SS 2005. When I try to install framework v 2.0, I'm sent to v. 3.5 and no way to download SS 2005.
    How does one install a express sql server to run with Visual Web Developer 2008?   

    Momark,
    Do you still need help with this?
    Thank you!
    Ed Price, Power BI & SQL Server Customer Program Manager (Blog,
    Small Basic,
    Wiki Ninjas,
    Wiki)
    Answer an interesting question?
    Create a wiki article about it!

  • How does one use airport express to extend a non-Apple wifi network?

    Hello. The wifi signal reaching my room shows good on my macbook but weak on my ipod touch. Therefore I want to pick it up on my airport express and extend/boost it.
    I have tried everything in the auto and manual methods of setup to do this, but the only thing I can manage to do is to join a wireless network wirelessly and then then connect to it through a ethernet cable from my airport express. I want to pick it up wirelessly and extend it wirelessly - is this possible? This is the reason why I bought it!
    thanks a lot, JJ

    Thanks for that info. So, I have been trying to use my airport express n to extend an airport n network (for greater distance of coverage) and cannot get this to work either. I can join the other apple airport's network and then connect to the airport express by cable. I have tried all the help available here but that seems to be the only way to extend a network. But I cannot see any point in that! JJ

  • How does one simultaneously view two or more tables?

    When viewing a table, a tab is created. How does one create a second tab with which to view a second table?
    A related question - how does one enter and run two or more SQL statements to be viewed side-by-side (as in the above example with straight tables)?

    1) For table click the thumb tack an pin it. Then the next one will open in a new window.
    2) When you have 2 worksheets open drag the title bar to be on the left/right/top/bottom of that section. Then you'll have side-by-side worksheets.
    -kris

  • HT5429 So how does one get apple maps to give directions between two stored bookmark locations?

    So how does one get apple maps to give directions between two stored bookmark locations?

    Does anyone know if this is possible to do?

  • How does one sync the new time capsule with the old airport extreme and airport express in order to extend range?

    How does one sync the new time capsule with the old airport extreme and airport express in order to extend range?

    Thanks for the additional information.
    Unfortunately, the AirPort Utility application in the Lion and Mountain Lion operating systems, which is used to configure the new Time Capsule does not support the older versions of the products that you have.
    Even if it did, there are no settings on the older AirPorts to "Extend a wireless network", so they are not compatible with the new Time Capsule if you intend to extend the network only using wireless connections.
    If you have the ability to connect each AirPort to the Time Capsule using a permanent wired Ethernet cable connection, it might be possible to use a complicated workaround to install an older version of AirPort Utility to configure the older AirPorts to work with the new Time Capsule.
    If you have another Mac there that is using the Leopard or Snow Leoapard operating system, things would likely be simpler. I have not done this type of procedure to mix a new Time Capsule with older AirPorts, so I would not be able to say whether this would work or not.

  • How does one transfer CS5 actions for use with CS6?

    CS6 installation, which was uneventful, has transferred none of my actions from my copy of CS5. The CS5 actions are located in the actions folder of the APPLICATION/PHOTOSHOP CS5/PRESETS/ACTIONS.  The "actions" folder in application support/adobe in my library is empty, and has always been so.
    Only the CS6 default actions are located in the same folder for CS6.
    I use imac i7, lion.
    Note that i also have CS3 and CS4 on my machine. This due to recent upgrade to CS5 and recent upgrade to LION, and my general paranoia.
    Must i load each action into CS6, one at a time?
    thanks to any and all.
    vince

    Re: how does one transfer CS5 actions for use with CS6?
    On a Mac - There are multiple ways to do this.  I have done them both ways. In order to do this you need to know where you have your actions stored, and you can move them all at once if you have them stored in the same location.
    1. You can load an action ONE AT TIME into your actions palette by:
         A. Open up the action palette and click on the little arrow with 4 little horizontal lines next to it on the upper right corner of the actions palette.
         B. Select "Load Actions" and a Finder window will open up and you can search your computer through this window for your actions.
         C. Click on the action from the Finder window then click 'Open' at the bottom right of the finder window.
         D. To save these so that they appear every time you open up your actions palette, go back to the little arrow at the top right of the actions palette and when the drop down window opens- click on 'Save Actions'. It will select the location where the          actions are currently stored as the place to save them. If you want to change that path, you can do it at this time in the little path window.  I just leave it, since I keep all my actions stored in the same file.
    2. TO MOVE MULTIPLE ACTION SETS AT ONCE
         A. Open up CS6 (or CS5) and move the Photoshop workspace it to the right side of your computer screen so you can see your desktop on the left side.
         B. Open up your Finder search window from your dock (the square blue head icon thingy for those who are new to photoshop). Move this to the left side of your screen so you can see the Photoshop work space on the right and the Finder window          on the left. In the Finder window, navigate to the file where all your actions are stored, select all the actions in the file (command+A will select everything in the file if you are actively inside the open file) or you can select multiple files           individually by continuously holding down the command key and clicking on the different actions you want to move.
         C. With the Photoshop workspace visible on the right, and the actions palette open so you can see that the actions actually transferred - In the Finder window, click the selected actions you want to load and drag them over to the Photoshop           workspace.  I did this without an image open, I just dragged them onto the empty workspace.  The actions should all appear immediately in the actions palette that is open.
         D. To save these so that they appear every time you open up your actions palette, go back to the little arrow at the top right of the actions palette and when the drop down window opens click on 'Save Actions'. It will select the location where the           actions are stored as the place to save them. If you want to change that path, you can do it at this time in the little path window.  I just leave it, since I keep all my actions stored in the same file.
    I hope this helps. 
    and I hope there are no typos. 

  • How does one create LOV Map between 2 fields for custom lookup mapping

    Hi there
    In Internet Expenses, Expense Report Line Detail we have two unrelated fields; namely Expense Location & Tax Code.
    The requirement is to map a default tax code to locations; basically when a user enters Expense Location then the mapped tax code value should default into field Tax Code.
    The location-tax code mapping is stored in a custom lookup (FND_LOOKUP_VALUES).
    My question is how does one go about implementing this?  For example is it possbile to create a new (hidden) LOV based on the lookup mapping & then create a Personalization LOV Mapping between the 3 LOV...  Or is it necessary to modify the Tax Code drop down Message Choice in JDeveloper?  Of course details are appreciated!
    FYI below is the relevant Personalization Structure from "Personalize Stack Layout: (NormalDetails)".
    Message Lov Input: Expense Location
    - Lov Mappings
    -- Lov Map: (lovMap1)
    -- Lov Map: (lovMap2)
    -- Lov Map: (lovMap3)
    - Message Text Input: Expense Location
    - Message Styled Text: Transaction Location
    - Message Text Input: Merchant Name Yes
    - Message Styled Text: Description
    - Message Check Box: Original Receipt Missing Yes
    - Message Choice: Tax Code
    - Message Check Box: Amount Includes Tax
    - Message Choice: Tax Code
    Many thanks
    G

    Hello all
    The correct & supported method is this:
    Extend the location LOV in JDeveloper & add a "default tax" attribute, this could be derived from a new location DFF storing the default tax code for each location. Now simply create a location Personalization LOV Map which takes this new location lov tax attribute & target it to the tax message choice field.
    That's my 2c worth anyway, so please give comment if you feel there is a better way.
    There is just one more little problem however... The requirement has changed! Now we require the tax code to default according to not one location field, but other fields too. For example if the user selects Expense Type of Beverage & Location of Netherlands then Tax Code should be NL19%, for Expense Type of Hotel then it should be NL6%; if the user ticks "Missing Receipt" field then it should over ride all others & set the code to NL0%.
    Any ideas?
    Many thanks
    G
    Edited by: user13363208 on 11-Aug-2010 06:51

  • How does one get rid of opaque strip?

    I cannot begin to express how much I hate this so-called "improvement". How does one rid the screen of the tiresome opaque strip at the bottom? As to the new icons, Apple seem to have employed an incompetent child to design them.

    How does one rid the screen of the tiresome opaque strip at the bottom?
    You can't. But it's still the same dock area as before, just not transparent with a physical-looking "shelf" as iOS 6 had.
    As to the new icons, Apple seem to have employed an incompetent child to design them.
    I disagree completely.
    But you can comment to Apple via their feedback pages, if you wish:
    http://www.apple.com/feedback/ipad.html
    Regards.

  • HT1338 How does one uninstall Garageband and other things?

    How does one uninstall Garageband and other things on the Macbook air?

    Uninstalling Software: The Basics
    Most OS X applications are completely self-contained "packages" that can be uninstalled by simply dragging the application to the Trash.  Applications may create preference files that are stored in the /Home/Library/Preferences/ folder.  Although they do nothing once you delete the associated application, they do take up some disk space.  If you want you can look for them in the above location and delete them, too.
    Some applications may install an uninstaller program that can be used to remove the application.  In some cases the uninstaller may be part of the application's installer, and is invoked by clicking on a Customize button that will appear during the install process.
    Some applications may install components in the /Home/Library/Applications Support/ folder.  You can also check there to see if the application has created a folder.  You can also delete the folder that's in the Applications Support folder.  Again, they don't do anything but take up disk space once the application is trashed.
    Some applications may install a startupitem or a Log In item.  Startupitems are usually installed in the /Library/StartupItems/ folder and less often in the /Home/Library/StartupItems/ folder.  Log In Items are set in the Accounts preferences.  Open System Preferences, click on the Accounts icon, then click on the LogIn Items tab.  Locate the item in the list for the application you want to remove and click on the "-" button to delete it from the list.
    Some software use startup daemons or agents that are a new feature of the OS.  Look for them in /Library/LaunchAgents/ and /Library/LaunchDaemons/ or in /Home/Library/LaunchAgents/.
    If an application installs any other files the best way to track them down is to do a Finder search using the application name or the developer name as the search term.  Unfortunately Spotlight will not look in certain folders by default.  You can modify Spotlight's behavior or use a third-party search utility, EasyFind, instead.
    Some applications install a receipt in the /Library/Receipts/ folder.  Usually with the same name as the program or the developer.  The item generally has a ".pkg" extension.  Be sure you also delete this item as some programs use it to determine if it's already installed.
    There are many utilities that can uninstall applications.  Here is a selection:
        1. AppZapper
        2. AppDelete
        3. Automaton
        4. Hazel
        5. AppCleaner
        6. CleanApp
        7. iTrash
        8. Amnesia
        9. Uninstaller
      10. Spring Cleaning
    For more information visit The XLab FAQs and read the FAQ on removing software.

  • In Pages 5 when I try to attach a pages document to an email it gives me 2 folders and 4 files ???  How does one email a pages document.

    How does one email a pages document? In pages 5 when I try to attach a pages document to a gmail email it gives me 2 folders and 4 other files to choose from. 

    Sounds like you are using Gmail.
    Pages 5 uses a zipped package of files as its format. 3rd party servers don't understand the format and show it as the component parts.
    Use Mail toenail the file or zip the .pages document before sending.
    Peter

  • How does one change the font size for folders and/or file lists in the Bookmarks Library?

    How does one change the font size for folders and/or file lists in the '''Bookmarks''' Library?
    Since the upgrade to version 9.0.1 of Firefox, the Bookmarks feature changes are confusing me. They seem to be confusing themselves as well. The list of bookmarks has changed. The font size is so small that my aging eyes cannot read it without fogging the screen with my breath. Some folders are out of alphabetical order (where I know they were previously good), and some are missing altogether (folders to which I frequently add references).
    As for missing or deranged files or folders, was there something that I should have done or now need to do to recover those after the upgrade (or before)?
    With regard to font size,
    1. there is no “Edit Bookmarks” or like option to edit the list in this version
    2. the “zoom” option in the “view” list of functions is greyed out when in “Show All Bookmarks” window
    3. expanding the browser window has no effect on font size
    4. “Preferences” settings for font size has no effect in that window either, including advanced settings
    5. “Help” offers none that I can find.
    Can any of you Help?!?

    Maybe this extension helps:
    *Theme Font & Size Changer: https://addons.mozilla.org/firefox/addon/theme-font-size-changer/

  • How does one use an external microphone with the internal camera?

    I want to use the internal camera because I don't have anything better but I want to use an external mic to record video and sound simultaneously, for a video blog. How does one accomplish this? I'm getting no help from the manual.

    Try this. Connect your external mic, either through the audio line in port or, into a USB port if it is a USB mic and then go to System Preferences under the Apple and select the Sound icon under Hardware. Click on your mic shown in the list of input devices.
    Hope that works for you.
    Forest

  • In the new Keynote how does one find the Wrap Inspector to wrap text around a photo??? Thanks

    In the new keynote, the help section refers to the Wrap Inspector.  How does one find that or how does one wrap text around a photo??   Thanks

    You can also use the shape tool to draw a shape roughly following the outline of the graphic you want to wrap text around, change the fill and stroke to "none", then paste your text within the shape. It's a few more steps, but it opens you up to many creative alternative layouts.

  • I have a MacAir, mid 2011 model, and want to view video on my TV.  I see that I need a mini display port to Hdmi but there are many of these.  What exatly do I need and how does one view a movie downloaded to the MacAir on a TV screen?

    I have a MacAir, mid 2011 model, and want to view video on my TV.  I see that I need a mini display port to Hdmi but there are many of these.  What exatly do I need and how does one go about viewing a movie downloaded to the MacAir on a TV screen?

    Welcome to Apple Support Communities
    That's exactly what you need. A Mini DisplayPort to HDMI adapter and a HDMI cable. See > http://support.apple.com/kb/HT4241?viewlocale=en_US
    This is the only way to view a video on the TV. After connecting your MacBook Air to the TV, image on your TV should show immediately. Then, press Command and F1 keys to mirror your MacBook Air display, and open the video

Maybe you are looking for

  • How to get a List of Users Currently Logged into the portal

    Hi, Im trying to get the list of all users logged into the portal to do a web service, but I can't find the way to do this, is there any way to find this info thrugh a java class or some object in the RCU/schema/WCP database? Greetings Mike

  • Error in ChartImage.axd - Image not Found

    I am getting an intermitant error on our production website.  I have a web form with two pie charts & every once in a while i will get an error from /ChartImg.axd: The image is not found.    at    System.Web.UI.DataVisualization.Charting.ChartHttpHan

  • Is there any OOB way to aggragate content in SPF (Foundation)?

    Is there any OOB way to aggragate content in SPF (Foundation)? I don't see even CQWP in the WP... (Content Search  is not included in this version. am i right?) keren tsur

  • Importing from DVD...

    Hi All, I am working on a College project and trying to import from a commercial dvd. I was able to rip it to MPEG-4 but it will not import to iMovie for editing. I have tried VLC, HandBrake and Quicktime but still no luck. Is there a particular form

  • How to shutdown all adapters?

    We need to shutdown all adapters for 2 hours.  But the PI7.0 must be up. Could you help tell how to achieve this? Thanks a lot!