Convert query from other database

Hi all,
Please help me,
I need convert this query for oracle, this originaly from postgres.
I appreciate anyone who can help me... thanks a lot
select
     CASE catg_id
          WHEN 1 THEN 'RESIDENCIAL'
          WHEN 2 THEN 'COMERCIAL'
          WHEN 3 THEN 'INDUSTRIAL'
          WHEN 4 THEN 'PÚBLICO'     
     END                                         as "Categoria",
     sum(coalesce(vlr_arrec_tot,0))                         as "Arrecadação Provisória Novembro_2010"
from
-- ARRECADAÇÃO DIÁRIA     
     select
          coalesce(arrec1.catg_id,devol.catg_id)                                   as catg_id,
          sum(coalesce(arrec1,0) - coalesce(devol,0))                              as vlr_arrec_tot
     from                              
               select catg_id,
                    sum(ardd.ardd_vlpagamentos) as arrec1
               from      arrecadacao.arrecadacao_dados_diarios ardd
               where      ardd.ardd_amreferenciaarrecadacao = 201011
               group by 1
               order by 1
          ) as arrec1           
          full outer join
               select catg_id,
                    sum(dvdd.dvdd_vldevolucoes) as devol
               from arrecadacao.devolucao_dados_diarios dvdd
               where dvdd.dvdd_amreferenciaarrecadacao = 201011
               and dvdd.dvdd_tipodevolucao in ('C','D','N')
               group by 1
               order by 1
          ) as devol      on devol.catg_id = arrec1.catg_id
          group by 1
          order by 1
     ) as arrec     
group by 1
order by 1

saddones wrote:
Hi all,
Please help me,
I need convert this query for oracle, this originaly from postgres.
I appreciate anyone who can help me... thanks a lot
select
     CASE catg_id
          WHEN 1 THEN 'RESIDENCIAL'
          WHEN 2 THEN 'COMERCIAL'
          WHEN 3 THEN 'INDUSTRIAL'
          WHEN 4 THEN 'PÚBLICO'     
     END                                         as "Categoria",
     sum(coalesce(vlr_arrec_tot,0))                         as "Arrecadação Provisória Novembro_2010"
from
-- ARRECADAÇÃO DIÁRIA     
     select
          coalesce(arrec1.catg_id,devol.catg_id)                                   as catg_id,
          sum(coalesce(arrec1,0) - coalesce(devol,0))                              as vlr_arrec_tot
     from                              
               select catg_id,
                    sum(ardd.ardd_vlpagamentos) as arrec1
               from      arrecadacao.arrecadacao_dados_diarios ardd
               where      ardd.ardd_amreferenciaarrecadacao = 201011
               group by 1
               order by 1
          ) as arrec1           
          full outer join
               select catg_id,
                    sum(dvdd.dvdd_vldevolucoes) as devol
               from arrecadacao.devolucao_dados_diarios dvdd
               where dvdd.dvdd_amreferenciaarrecadacao = 201011
               and dvdd.dvdd_tipodevolucao in ('C','D','N')
               group by 1
               order by 1
          ) as devol      on devol.catg_id = arrec1.catg_id
          group by 1
          order by 1
     ) as arrec     
group by 1
order by 1What exactly about the query doesn't work now? It all looks compliant to me (though i'm not sure about the group by 1 stuff, you may or may not, have to put the actual column name). I also think your alias is too long (just based on visual inspection), it's going to need to be 30 chars or less
"Arrecadação Provisória Novembro_2010"Keep in mind that we don't have your tables (nor your Oracle version since we don't know it) so if you really want help you'll have to put in a little more effort to make this manageable.

Similar Messages

  • How to I convert data from oracle database into excel sheet

    how to I convert data from oracle database into excel sheet.
    I need to import columns and there datas from oracle database to microsoft excel sheet.
    Please let me know the different ways for doing this.
    Thanks.

    asktom.oracle.com has an excellent article on writing a PL/SQL procedure that dumps data to an Excel spreadsheet-- search for 'Excel' and it'll come up.
    You can also use your favorite connection protocol (ODBC, OLE DB, etc) to connect from Excel to Oracle and pull the data out that way.
    Justin

  • How to run report from other database

    hi,
    i have an application running on oracle 10g forms (many forms & reports),i want to run a report from other database using a form,it should be run on this application & same report server. so if it is possible so tell me how can i do this ?
    thxs

    If you have another Oracle database you can use the following command to create a link to it from the one you are currently logged into
    CREATE PUBLIC DATABASE LINK my_db_link
    CONNECT TO other_oracledb_usernane IDENTIFIED BY other_oracledb_password
    USING 'remote_oracledb_name';
    When you issue this command the 'remote_oracledb_name' must exist in your TNSNAMES.ORA file so that the remote database can be 'found'
    If this is still not enough info I would suggest that you talk to someone on your DBA team to help set up the link.
    Mark

  • Querying from a database

    Hi,
    I would like someone to help me coding the search from a database.
    I have a html document which asks for a title or an author. My servlet should execute the query using the given title or author retrieving data from the database.
    I am trying to execute this query which i know as in sql.
    Select Authors.FirstName, Authors.LastName, Titles.Title from Titles, Authors, AuthorISBN where (FirstName = req.getParameter("keyword") OR Title =req.getParameter("keyword") ) AND Authors.AuthorID=AuthorISBN.AuthorID AND AuthorISBN.ISBN=Titles.ISBN
    I am getting sqlexceptions if i execute this query in the jdbc. Please someone help me in coding this in jdbc appropriately.
    Thank you.

    You are getting errors because that string is not valid SQL. Write a string expression that does produce valid SQL, something like this:
    String sql = "Select Authors.FirstName, Authors.LastName, Titles.Title from Titles, Authors, AuthorISBN where (FirstName = " + req.getParameter("keyword") + " OR Title = " + req.getParameter("keyword") + " ) AND Authors.AuthorID=AuthorISBN.AuthorID AND AuthorISBN.ISBN=Titles.ISBN;
    You'll have to hack around with it to make it work. I am willing to bet you don't get it right the first time. Use System.out.println(sql) to check what you are producing.

  • Calling application from other database

    It's possible to call an application on another database, without informing user and password again?

    Sorry for being fastidious, but I don't think you can "call" an Apex application as you would call a database procedure for instance. So I assume you mean navigate from one Apex application to another Apex application in a different database.
    If you use single sign-on (SSO), that is a piece of cake.
    If you don't, there is no straightforward way I think. You can use some ingenious ways to get round it though, for instance:
    - In the calling application, using a database link, insert a token in some table in the other database along with the username and a timestamp.
    - Pass that token and the username in the URL as a parameter to an "auto login page" in the other application
    - In the "auto login page" of the other application, check whether the token/username combination is valid and, if it is, auto-login the user using the provided username.
    You also could use other fancier techniques like queues. Maybe others may have other suggestions.
    I hope this helps
    Luis

  • How To Save Modified Fields After query From The Database

    I Have This Customer Information Form That's Sort of an Ordering Forms , I Made It By LiveCycle v9.0
    And I Want To be able to search for Specific Record and Modify it and Save It Again to The DataBase
    I believe That We All Saw The (( Data Connected Forms Presentation )) For Pual Guerette
    At One Part Of The Presentation (Minute 0:26:00 specifically) When He Try To Search A Specific Record In the Database
    And He Got all this annoying Messages Then The Record what He looking Shows up ; He Said That We No Longer able to Modify The Record After We Doing the Search
    My First Question Is Why ???
    Is there anyway After I got that Specific Record I Want from the Database I Can make my modification on it and update it Back in the DB.
    OR i Have to Browse the whole DB looking for it Specially that I got this (ID Auto Increasment Number field Issue) Which leads me to ;
    My Second Qustion;
    Why I Can't just connect ''The Form Order Number'' to an Auto Increasment Number field in the DB
    Obviously i can't, So Can I do Anything to achieve this goal ??
    I Believe that we can Find some scripting to make that Happen 
    I Will Be So Grateful If There Is Any Helpful Answer
    FYI: I'm Not Java Expert So If There Is any Coding That's Can be Helpful Please POST ALL OF IT if you can ,,,,

    Hi,
    The information there is excellent and I would strongly recommend it.
    I don't have any public database examples and I am not inclined to spend time preparing an example if you are not prepared to read up on the methods.
    Stefan's site is the only link I have for databases.
    Good luck,
    Niall

  • Use Package from other database

    Hi all,
    I want to use a function from a package which is stored on another database in the mapping of my datawarehouse.
    How can I do that? I do not want to import the function, because then I do not get the changes which could be done to the package on the other database.
    Thanks in advance
    Yvonne

    If I understand it correctly I should create the package with the same name to
    the public transformations. Either to the public or to the transformations local to your project, yes.
    There I then create a transformation in the package. What should I do with the
    implementation? Leave it like the default is?You can leave it empty, as long as the number, order and type of parameters matches that of the actual packaged function in the database you will be calling.
    How I does the OWB now know where he can find the package?That's the trickier part. You need a database link (connector) between your target and the database with the package. Then you can create a synonym, using the database link, in the target schema pointing to the package in the remote database.
    Now, if you named the newly added package in OWB the same as the synonym used to access the package in the remote database AND you named the function in the new package the same as the real function, you should be able to use the transformation in a mapping, deploy it and execute it, without actually deploying the transformation itself.
    Hmm, reading that back, it sounds rather convoluted to me.
    Anyway...I hope it helps.

  • Call from other database

    Hi!, I have PL/SQL like ...
    select rm.period, mo.n_org, ...
    from rc_mhp@prs rm, ms_cmhp@prs mc, m_org@prs mo, grp_ms@prs gm,
    (select code_ldr, code_frm from opt_ms@prs
    group by code_frm, code_ldr) om
    where mc.cd_mhp=rm.cd_mhp
    and ( om.code_frm=:p_ldr or :p_ldr is null )
    and ( om.code_ldr=:p_ldr2 or :p_ldr2 is null )
    group by rm.period, mo.n_org, rm.code_ldr;
    The SQL is run in other database, and I have an error ORA-01008.
    I think, it is caused by "select substitution".
    What should I do ?

    Please repost this question in the appropriate section of the Discussion Forum.
    This forum is for general suggestions and feedback about the OTN site.
    You can also use our new offering called OTN Service Network:
    For Oracle Advice/Minimal Support (fee based) on Reports, Forums,
    SQL*Plus, and PL/SQL, please go to: http://www.oracle.com/start/otnServiceNetwork/intro.html?src=9123 86&Act=6
    For customers with paid support (Metalink) please go to:
    http://www.oracle.com/support/metalink

  • Form Builder Connectivity from other database

    Could anyone please guide me in detail to connect Oracle Forms 9i/10g with MS SQL Server database?
    Also how do we connect with other databases like SQL Server, MS Access, and so on?
    Thanks in advance.
    Edited by: user10876897 on Apr 13, 2009 10:08 PM

    create an odbc for oracle and connect form to any database through odbc using
    userid/passwd and database as odbc:dsnname

  • How to query data from other Database

    Dear Community;
    Please help me, I want to connect with another Database in apex query. I have been created TNS and also query run proper in Toad, but when I give schema name with table it does not run and give error.
    So how I can use this query in Apex.
    Regards
    Shahab Ahmed Khan

    We do this by creating a database link from DB1 (Apex database) to DB2 (main database) then writing queries like this in Apex:
    select foo, bar from atable@db2

  • Query from remote database

    Hi
    i have a table named "gatepass" in database A.
    i created public synonym
    (create public synonym gatepass for schema.gatepass@databaselink) in database B for the table "gatepass" in database A.
    when i query that table in db B through SQL prompt, it fetches data.
    but when i query that table through form, form hangs(goes into working state) and ends.
    where is the problem
    plz help
    thanx

    i use forms 6i.
    in your database B create a view:
    create or replace view gatepass_v as
    select * from schema.gatepass@databaselink
    and then create a synonym public over the new view.
    and in your form use the sinonym public or the view.
    test please.

  • SELECT query from multiple databases

    Hi,
    Is it possible to run a SELECT query using multiple DBs' tables, like outer joining them. One of the DBs is Sybase.
    Thanks in advance

    A TopLink session can span multiple databases if they can be accessed through a single connection. A single select would require the database to handle the aggregation as mentioned in the other post.
    Alternatively TopLink's session broker will support making a single session present persistent types from multiple independent databases. This approach will not support a single SELECT spanning the databases though.
    Doug

  • PLS HELP CONVERT QUERY FROM UPDATE TO MERGE

    Hi all,
    Can you help me in converting this update statement into merge? I will really appreciate your help. Thanks
    UPDATE dm_organizations tt
    SET (cost_ctr_desc, cost_ctr_hier_lvl_1, cost_ctr_hier_lvl_2,
    cost_ctr_hier_lvl_3, cost_ctr_hier_lvl_4, cost_ctr_hier_lvl_5, rgn_nm,
    cntry_nm, load_date, update_date) =
    (SELECT t.cost_ctr_desc, t.cost_ctr_hier_lvl_1,
    t.cost_ctr_hier_lvl_2, t.cost_ctr_hier_lvl_3,
    t.cost_ctr_hier_lvl_4, t.cost_ctr_hier_lvl_5, t.rgn_nm,
    t.cntry_nm, t.load_date, SYSDATE
    FROM dmi_cc_upload_stg t
    WHERE t.run_id = 1831
    AND t.status = 'Published'
    AND t.cost_ctr_id = tt.cost_ctr_id
    AND t.div_code = tt.div_code
    AND t.fcn_code = tt.fcn_code
    AND t.mkt_code = tt.mkt_code
    AND t.corp_id = tt.corp_id
    AND ROWNUM = 1)
    WHERE EXISTS (
    SELECT t.cost_ctr_desc, t.cost_ctr_hier_lvl_1,
    t.cost_ctr_hier_lvl_2, t.cost_ctr_hier_lvl_3,
    t.cost_ctr_hier_lvl_4, t.cost_ctr_hier_lvl_5, t.rgn_nm,
    t.cntry_nm, t.load_date, SYSDATE
    FROM dmi_cc_upload_stg t
    WHERE t.run_id = 1831
    AND t.status = 'Published'
    AND t.cost_ctr_id = tt.cost_ctr_id
    AND t.div_code = tt.div_code
    AND t.fcn_code = tt.fcn_code
    AND t.mkt_code = tt.mkt_code
    AND t.corp_id = tt.corp_id);

    why not use existing UPDATE?
    UPDATE dm_organizations tt
    SET    ( cost_ctr_desc, cost_ctr_hier_lvl_1, cost_ctr_hier_lvl_2,
             cost_ctr_hier_lvl_3,
             cost_ctr_hier_lvl_4, cost_ctr_hier_lvl_5, rgn_nm, cntry_nm,
             load_date, update_date ) = (SELECT t.cost_ctr_desc,
                                                t.cost_ctr_hier_lvl_1,
                                                t.cost_ctr_hier_lvl_2,
                                                t.cost_ctr_hier_lvl_3,
                                                t.cost_ctr_hier_lvl_4,
                                                t.cost_ctr_hier_lvl_5,
                                                t.rgn_nm,
                                                t.cntry_nm,
                                                t.load_date,
                                                SYSDATE
                                         FROM   dmi_cc_upload_stg t
                                         WHERE  t.run_id = 1831
                                                AND t.status = 'Published'
                                                AND t.cost_ctr_id = tt.cost_ctr_id
                                                AND t.div_code = tt.div_code
                                                AND t.fcn_code = tt.fcn_code
                                                AND t.mkt_code = tt.mkt_code
                                                AND t.corp_id = tt.corp_id
                                                AND ROWNUM = 1)
    WHERE  EXISTS (SELECT t.cost_ctr_desc,
                          t.cost_ctr_hier_lvl_1,
                          t.cost_ctr_hier_lvl_2,
                          t.cost_ctr_hier_lvl_3,
                          t.cost_ctr_hier_lvl_4,
                          t.cost_ctr_hier_lvl_5,
                          t.rgn_nm,
                          t.cntry_nm,
                          t.load_date,
                          SYSDATE
                   FROM   dmi_cc_upload_stg t
                   WHERE  t.run_id = 1831
                          AND t.status = 'Published'
                          AND t.cost_ctr_id = tt.cost_ctr_id
                          AND t.div_code = tt.div_code
                          AND t.fcn_code = tt.fcn_code
                          AND t.mkt_code = tt.mkt_code
                          AND t.corp_id = tt.corp_id); 

  • Copying data from other database

    I'm trying to create Job Schedule, which involve 2 diff database (Oracle & Visual Foxpro). But when i create database link, and try VF connection i got this error ORA-06401: NETCMN : invalid driver designator.
    PS: I already create connection VF thru ODBC, its work fine if im using SQLPlus and connect directly. only error if using database link, any suggestion?

    Susmita,
    I gave
    [copy]
    COPY from scott/tiger@ora52 to scott/tiger@ora87 insert emp using (select * from emp);
    [copy]
    The following error has occured..
    [copy]
    SQL* plus command ignored.
    invalid sql command...
    [copy]
    Thank you
    Edited by: user636482 on Apr 29, 2009 5:17 AM

  • Generate query from other table

    Hello,
    I have stored all the column names of table A in table B .
    Here is table A columns
    ID
    NAME
    LENGTH
    STREET
    ZIPCODE
    TALUK
    DISTRICT
    Here is columns of table B
    COLUMN_NAME
    DISPLAY
    DISPLAY_ORDER
    Here is data of table B
    COLUMN_NAME         DISPLAY        DISPLAY_ORDER
    ID 0 1
    NAME 1 2
    LENGTH 1 7
    STREET 1 3
    ZIPCODE 1 6
    TALUK 0 4
    DISTRICT 0 5
    Now I need a query to select the columns of Table A whose DISPLAY equal to 1 in table B. Something like this.
    Select (select COLUMN_NAME from B where DISPLAY=1 order by DISPLAY_ORDER) from A
    Or
    can I generate query like this from table B based on values of display and display_order?
    select name, street,zipcode,length from A
    Thanks,
    Sujnan

    From your table structure i can understand you are using TABLE_B as a user template where user tells what are all the column he wants and in which order he wants.
    We have some templates like this. What we have done is like this.
    1. A back end program will return all the columns (a static set of columns. and columns names represented individually. using * is not a good practice) to the front end application.
    2. And the front end will map those columns available in the template to the screen. And there by the user gets to see only the columns that he selected.
    If you cant use such a model then only option you will be left with is to build your query dynamically. And Dynamic SQL has its own set of issues.
    Thanks,
    Karthick.

Maybe you are looking for

  • Why Dynamic Parameter is not working, when i create report using stored procedure ?

    Post Author: Shashi Kant CA Forum: General Hi all Why Dynamic Parameter is not working, when i create report XI using stored procedure ? Only i shaw those parameters which i used in my stored procedure, the parameter which i create dynamic using stor

  • Raid Setup Guide 865/875 LSR/FIS2R Rev 1.04

    On-Board Raid Setup MSI 865PE/875P Revision History Revision 1.0 (January 2004) -   Original Raid Article Revision 1.01 (February 2004) -   Reformatted text and fixed spelling/grammar Revision 1.02 (October 2004) -   Added warnings to temporarily dis

  • Auto Invoice Program taking too much time : problem with update sql

    Hi , Oracle db version 11.2.0.3 Oracle EBS version : 12.1.3 Though we have a SEV-1 SR with oracle we have not been able to find much success. We have an auto invoice program which runs many times in the day and its taking too much time since the begi

  • Battery Update 1.2 for Mac os X 10.5.x?

    Hi, I have a MBP with 10.5.4 and I do not have any battery update installed on it. My wife's MB (not Pro) with the same 10.5.4 has battery update 1.2 installed. Wasn't supposed that any Leopard has the battery patch embedded so it does not require an

  • When I start MacBook OSX I get a message

    I am stuck....Everytime I start my MacBook OS X 10.4.6 I get the message Panic(cpu O caller 0X003AB787) unable to find driver for this platform "ACPI" I have tried to to start with the install disc but get back to the same message.... Thanks for your