Column Level Subqueries

I am converting a MS SQL Server 7.0 database to Oracle 8i.
Currently, I run into problems to convert column-level subqueries
into Oracle. To give an example, I have the following SQL Server
7.0 query:
select col_a =
case
when ( a > 0 ) then 1
when ( a < 0 ) then -1
else 0
from table_a;
How do I convert it into Oracle? I tried to use DECODE and it
didn't work in this case. Any other alternative? Please help.
Thanks.
- Brian
null

It works! Thanks a lot. I just wish the documentation could have
provided examples like that.
-Brian
Anish (guest) wrote:
: You hv to use sign() function within decode.
: Hope that helps.
null

Similar Messages

  • Possible to emulate union all at column level?

    The UNION ALL function of Oracle SQL is great for joining two matching results sets into one.
    However, is it possible to use a similar approach to do this at column level?
    EG:
    The following query:
    <pre>
    select
    cods.salesman, sum(cods.net_amount) ordval
    from
    ifsapp.cust_ord_back_stat cods
    where
    to_char(cods.statistic_date,'YYYYMMDD') = '20060314'
    group by cods.salesman
    </pre>
    will produce details like:
    <pre>
    salesman ordval
    ARNOTT 100
    JONES 15
    SMITH 300
    </pre>
    Showing the balance of orders for each on the 14 March 2006.
    Then take the following:
    <pre>
    select
    cods.salesman, sum(cods.net_amount) ordval
    from
    ifsapp.cust_ord_back_stat cods
    where
    to_char(cods.statistic_date,'YYYYMMDD') = '20060315'
    group by cods.salesman
    </pre>
    will produce details like:
    <pre>
    salesman ordval
    ARNOTT 120
    JONES 5
    THOMAS 10
    </pre>
    Showing the balance of orders for each on the 15 March 2006.
    What I want to show is:
    <pre>
    salesman ordval1 ordval2 diff
    ARNOTT 100 120 20
    JONES 15 5 10-
    SMITH 300 0 300-
    THOMAS 0 10 10
    </pre>
    It seems quite complicated when I think of subqueries etc
    Thanks

    Apologies on formatting error. Resolved in some respects!
    The UNION ALL function of Oracle SQL is great for joining two matching results sets into one.
    However, is it possible to use a similar approach to do this at column level?
    EG:
    The following query:
    select
    cods.salesman, sum(cods.net_amount) ordval
    from
    ifsapp.cust_ord_back_stat cods
    where
    to_char(cods.statistic_date,'YYYYMMDD') = '20060314'
    group by cods.salesmanwill produce details like:
    salesman ordval
    ARNOTT 100
    JONES 15
    SMITH 300Showing the balance of orders for each on the 14 March 2006.
    Then take the following:
    select
    cods.salesman, sum(cods.net_amount) ordval
    from
    ifsapp.cust_ord_back_stat cods
    where
    to_char(cods.statistic_date,'YYYYMMDD') = '20060315'
    group by cods.salesmanwill produce details like:
    salesman ordval
    ARNOTT 120
    JONES 5
    THOMAS 10Showing the balance of orders for each on the 15 March 2006.
    What I want to show is:
    salesman ordval1 ordval2 diff
    ARNOTT 100 120 20
    JONES 15 5 10-
    SMITH 300 0 300-
    THOMAS 0 10 10It seems quite complicated when I think of subqueries etc
    Thanks

  • Column level filter at RPD level - OBIEE 11g

    Hi all,
    How do i add a filter at the column level in logical layer for one of the metric , it has the following calculation
    case when id in (1,2,3,4,5,5) and category='AS' then case when points=10 or points=9 then 1 else 0 end end
    I want the metric to reused for other id's as well... so i want to put case when id in (1,2,3,4,5,5) in filter of the column. how do i achieve it? plz help
    Thanks,
    Lona

    Your question is not clear, I assume you want points to be reused for other ids, so try this
    case when id in (1,2,3,4,5,5) and category='AS' then
    case when points in (10 ,9) then 1
    else 0
    end
    else points
    end
    if helps mark
    ~ http://cool-bi.com

  • How to apply 'disableColumnReordering="true"' at column level.

    Hi Experts,
    I am using jdev 11.1.1.5.0.
    I have a requirement, not to move(drag) the column within a table. I got succeeded to apply this on table level so that all columns are fixed, but not able to fix it at column level.
    So, is there any way or a property to fix this at column level.?
    Please help out me.
    Thanks & Regards,
    Bittu..!

    Hi
    You can use at column level frozen="true" but this will not disable reordering. This specifies whether the column is frozen. In the table columns until the frozen column are locked with the header and not scrolled with the rest of the columns. Frozen attribute is honored only on the top level column,since it is not possible to freeze a child column by itself without its parent being frozen
    See if this helps to your requirements.
    Reference: http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_column.html
    Nikolay

  • Column level access in Crystal Report Server

    <p>Hi,</p><p>I have three fields in my Crystal Report. The crystal report will be exported to PDF by my customised web application. The application has a built in user security and access control model. However if user 1 logs in he should see all the 3 columns(database fields) on the exported PDF. If user 2 logs in he should see only first 2 columns as he has access to only those. We would also be using Crystal Report Server.</p><p>I know this could be done in Crystal Report itself but is there any way to leverage column level access (and also row level) functionality using Crystal Report Server. The Crystal Report reports off an ODBC Datasource.</p><p>It would be great if any one could help me in this regard.</p><p> Cheers. </p><p>&#160;</p>

    If you were running the same version designer and server, you could open your reports straight from the repository, and save them straight back. Then you wouldnt have multiple versions of RPTs flying about.
    I have just purchased a new licence for 2008 and an 2008 upgrade for a Xr2.
    I don't think I completely understand, but we do have Crystal Reports 2008 and Crystal Reports Server 2008 available for purchase.

  • Grand Total not displaying correctly on Column level security.

    Hi All,
    I have implemented the Column level security for three columns. But in dashboard report. The grand total is not displaying correctly. The grand total values are still displayed for the hidden columns.
    Is there any work around for this.
    The sample how my report looks like after column level security is.
    ColumnA Metric1 Metric2 Metrics3(to be hidden)
    A 100 200
    B 150 100
    GrandTotal 250 300 400( this includes the value of A = 300, B = 100).
    Regards,
    Bhavik

    Any pointers please.

  • In SharePoint Calendar lists, fields [Start Time] and [End Time] do not exist at the Site Column level.

    <header style="box-sizing:border-box;color:#777777;line-height:1;font-size:13px;padding-right:46px;margin-bottom:3px;font-family:'Helvetica Neue', arial, sans-serif;">
    </header>
    I'm doing SP app development and have the following problem.
    I need to check Start time and End Time in SharePoint Calendar using CAML query and then add a new event to Calendar list using the Start time and End Time that user has entered in 2 datapickers
    in the form.
    function AddCalendarListItems() {
    var SD = document.getElementById("datepicker1").value;
    var SThh = document.getElementById("St1").value;
    var STmm = document.getElementById("St2").value;
    var ED = document.getElementById("datepicker2").value;
    var EThh = document.getElementById("Et1").value;
    var ETmm = document.getElementById("Et2").value;
    var T = document.getElementById("Title").value;
    var S1 = SThh;
    SD = SD.slice(6, 10) + "-" + SD.slice(0, 2) + "-" + SD.slice(3, 5) + "T" + SThh + STmm + ":00Z";
    ED = ED.slice(6, 10) + "-" + ED.slice(0, 2) + "-" + ED.slice(3, 5) + "T" + EThh + ETmm + ":00Z";
    //alert("SD= " + SD + " , ED= " + ED);
    var siteUrl = SiteCollurl + "/SharePointApp11";
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Calendar');
    var ListItemCInfo = new SP.ListItemCreationInformation();
    var newEvent = oList.addItem(ListItemCInfo);
    newEvent.set_item("Title", T);
    newEvent.set_item("EventDate", SD);
    newEvent.set_item("EndDate", ED);
    newEvent.update();
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQueryAddCalendarSucceeded2), Function.createDelegate(this, this.onQueryAddCalendarFailed2));
    function onQueryAddCalendarSucceeded2(sender, args) {
    alert("Success");
    function onQueryAddCalendarFailed2(sender, args) {
    alert('Add new item to the calendar failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    But I receive the following error:
    Add new item to the Calendar failed. Column 'Start time' does not exist. It may have been deleted by another user.
    I've checked and 'Start time' does exist. So it seems in SharePoint Calendar lists, field [Start Time] and [End Time]  exist but do not exist at the Site Column level.
    Please advise.

    Hi Khojasteh,
    Use “EventDate” for Start Time field, and “EndDate” for End Time field. They are the internal name of the two fields, you can check it in the column settings page url like “Field=EndDate”.
    If it isn’t the issue, please debug the code, in which line the error occurs.
    Thanks,
    Qiao
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Qiao Wei
    TechNet Community Support

  • Rank on column-level Grand total column in pivot table  -  Need help

    Hi ,
    I have developed the report, which is having a pivot view. In pivot view i have a column level grand total. I need to apply the rank for the grand total column..
    will that be possible.. if possible let me know..
    Thanks
    Kishore

    MAY BE IT IS NOT POSSIBLE IN PIVOT VIEW< AS WE DONT HAVE FORMULA EDIT OPTION FOR COLUMNS IN PIVOT VIEW.......
    Thanks & Regards
    Rushi

  • Row and Column Level Select Permission

    Hello Friends,
    I am using Oracle Oracle9i Enterprise Edition Release 9.2.0.1.0 and Windows XP. I have two questions. How to set :
    1. Row Level Select Permission?
    2.Column Level Select Permission?
    1. I have a table having 100 records in it. I don’t want to allow all the user to see them; means, if user1, user2 and user3 are going to select * from mytable then only they can get all the rows; while other users (including sys) should not able to get all rows, they should be capable of from 11th record.
    Though it can be managed by using another table, but I am just finding the other solution.
    2. Likewise, if I don’t want to allow to fetch all the columns; suppose column4 is having confidential info and only be visible by user1,user2 and user3 only, not by any othr user; what should I do?
    Please guide and help me.
    Regards

    You would need to use Virtual Private Database (VPD)/ row level security (RLS) to apply row-level security policies to the table. The DBMS_RLS package is used for this
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_rls.htm#sthref6168
    Unfortunately, column-level security wasn't available in 9.2. You would need to upgrade to Oracle 10g to get that functionality. Before that, you would have to create views that selected appropriate subsets of columns and grant permissions on those views to different users.
    Justin

  • Column Level Security - Grand Total row

    Hello All, I have a question about Column Level Security in a report where Grand Total is turned on. I am working inside of the OOTB Paint rpd and I am looking at the 'Finish Sales Trend for Current Year' report on the Brand Analysis dashboard page. Inside of the Admin Tool I added column level security on the Units presentation column in the Sales Measures table. I implemented security that will not allow the Central Region Manager group to view the Units column. When I access the report I noticed that the Grand Total row of the table is slightly skewed because the Units column is hidden. The Grand Total row is showing, however all the results are off by 1 cell.
    The forum is not allowing me to attach pictures to this post.
    Thanks for your help

    Hi User,
    It is an bug refer the metalink,
    Bug.9576412 - GRAND TOTAL NOT WORKING WHEN COLUMN LEVEL SECURITY IS IMPLEMENTED
    For eg:
    consieder a report with following columns,
    Year Product Measure1 Measure2
    In this if for measure1 the column level security is enabled (user1 who is not supposed to see the data).
    Then grand total value of measure2 will be in the grand total of measure1. (for user1)
    When column level security is enabled, that column will be pushed to the end of the table view.
    So that it is happening.
    By using case statements with groups or users we can get it work without enabling the column level security.
    Thanks,
    Vino

  • Column Level Security Using VPD under oracle 11g

    Hi
    I am using an example from Oracle Database 10g: Advance Security -- Virtual Private Databases
    1. The Application Context -- that sets the session environment for the use is ok.
    2. The Logon Trigger that executes the above is ok. It had been tested.
    3. The Security Policy that returns a predicate after checking the output of the Application Context is ok.
    4. The security policy applied to the STOCK_TRX table is ok.
    5. Select and Insert from the database work.
    However, after dropping both the insert and select policy, I am having problem getting a select policy to work with column-level VPD. I will get the ORA-28104 -- input value for statement type is not valid and ORA-06512 at SYS.DBMS_RLS line 20. See code below
    begin
    DBMS_RLS.ADD_POLICY
    ('PRACTICE', 'STOCK_TRX', 'STOCK_TRX_SELECT_POLICY', 'PRACTICE', 'SECURITY_PACKAGE.STOCK_TRX_SELECT_SECURITY', 'PRICE');
    end;
    Note:
    PRICE is the sec_relevant_cols
    STOCK_TRX is the table
    Can you please help.
    Thx

    The syntax for row level security is not the same for columns level security. All the parameters to the DBMS_RLS.ADD_Policy() function should be preceded by the type of the parameter for:
    begin
    DBMS_RLS.ADD_POLICy(object_schema=>PRACTICE, ... sec_relevant_cols=>'PRICE);
    end;
    I did not know this before. I thought they were there in the example for explanatory reasons. I decided to answer the question for myself because I know others have the same interpretation.

  • Q : Using column level VPD policies with Oracle Jdeveloper ADF BC ?

    For one of our big customer, we already successfully developped a new java application using Oracle Jdeveloper with ADF, ADF BC and the Virtual Private Database (VPD) with row level policies.
    Our customer has new business requirements that could be fullfilled using column level VPD policies.
    Has someone already successfully (or not) developped a business application using column level VPD policies with ADF, ADF BC on Oracle 10g R2 database and OracleAS 10g (10.1.2) ?
    Is it supported by Oracle ? what are the pitfalls, difficulties, problems you've met ?
    Is it a viable solution and if not, why ?
    Thanks in advance.
    Rémy

    Tomas,
    my 2 cent:
    if you know how to get the info from the db during run time you should be able to overwrite the frameworks message bundle look to get the description from the db instead of from the resource bundle.
    Or you load all descriptions from the db into a resource bundle and use the keys in the tooltip directly.
    Timo

  • Oracle Virtual Private Database (VPD), Column Level Security

    Hello,
    About Oracle Virtual Private Database (VPD), is it possible to set a Column Level Security without setting a Row Level Security (without using any predicate)?
    Thanks,
    Herve.

    Thanks, Zoran.
    A colleague shared with me a link containing a function without returning a predicate (in using SYS_CONTEXT function to skip row restriction).
    Herve.
    Link

  • Granularity of change rules in CDC (using Oracle streams) at columns level.

    Is it possible to implement granularity of change rules in CDC (using Oracle streams) at columns level.
    E.g. table abc with columns a1, b1, c1 where c1 is some kind of auditing column. I want to use CDC on table abc but want to ignore changes on c1.
    Is it possible? My other option is to split table abc into a child table that has the Primary key and c1 only but it needs additional table and joins.
    Thanks
    Shyam

    The requirement can be implemented by a simple trigger.
    You seem to plan to kill a mosquito by using a nuclear bomb.
    Sybrand Bakker
    Senior Oracle DBA

  • Map the hierarchical queries pseudo column level

    Is it possible to map the hierarchical queries pseudo column level in the Workbench?
    I have an object for which I use connect by queries. I would like to map the pseudo column level. is this possible? if yes, how
    If the mapping is not possible how do I get the level using a report query?
    Is there any other way to retrive level?
    Thanks
    Edited by: amehta5 on May 4, 2010 11:52 AM
    Edited by: amehta5 on May 4, 2010 11:55 AM

    Thanks James, appreciate your feedback.
    I tried report.addItem("level", builder.getFunction("LEVEL"));
    but the query TopLink generates has LEVEL() and it errors out.
    Code -
    Expression startExpr = null;
    Expression connectBy = builder.get("manager");
    Vector<Expression> order = new Vector<Expression>();
    order.addElement(builder.get("name"));
    report.setHierarchicalQueryClause(startExpr, connectBy, order);
    report.addAttribute("name");
    report.addItem("level", builder.getFunction("LEVEL"));
    Query generated by TOpLink - SELECT NAME, ID, LEVEL() FROM EMPLOYEE WHERE (EMPLOYEE_TYPE = ?) CONNECT BY PRIOR EMPLOYEE.MANAGER_ID = EMPLOYEE.ID ORDER SIBLINGS BY NAME
    bind => [M]
    Edited by: amehta5 on May 6, 2010 6:11 AM

Maybe you are looking for