convert the query to MSSQL to Oracle

I use Oracle 10.2 and want to convert after query SQLServer to oracle:
WITH Factor (Code, StartDate, EndDate, Rate, Ranks, Factors) AS
(
     SELECT Code, StartDate, EndDate, Rate, Ranks, CONVERT(FLOAT, 1.0)
     FROM GSplitDateRangeRank
     WHERE Ranks = 1
     UNION ALL
     SELECT S.Code, S.StartDate, S.EndDate, S.Rate, S.Ranks, CASE WHEN S.Rate > 0 THEN F.Factors / S.Rate ELSE F.Factors END
     FROM GSplitDateRangeRank S
     JOIN Factor F
     ON S.Code = F.Code
     AND S.Ranks = F.Ranks + 1
)
SELECT * FROM Factor order by code
Here's the query in Oracle:
with Factor AS
(
     SELECT Code, StartDate, EndDate, Rate, Ranks, 1.0 Factors
     FROM GSplitDateRangeRank
     )
select Code, StartDate, EndDate, Rate, Ranks, CASE WHEN Rate > 0 THEN Factors / Rate ELSE Factors END Factors
from Factor 
start with ranks = 1 
connect by code = code
            and  ranks = prior ranks +1;
But lines that are generated by the Oracle query are much more than those of MSSQL. Can any body please help me.

Hello

Here's how you adapted the recursive condition on the ranks:
SQL Server:

Elya wrote:

     AND S.Ranks = F.Ranks + 1

Oracle:

and  ranks = prior ranks +1;

Which looks right.

Now, here's how you adapted the condition on the code:

     ON S.Code = F.Code

Oracle:

and  ranks = prior ranks +1;

'code = code' will always be true (unless the code is NULL). If it is correct to change
"F. ranks" to"PRELIMINARY ranks", then it is good to change "
"F code" to "CodeFIRST" also: "

CONNECT BY  code  = PRIOR code

What a pity that you do not use Oracle 11.2, that has recursive subqueries. The SQL Server code can run without any modification.

Tags: Database

Similar Questions

  • convert the query to database

    Hi all
    Please help me,
    I need to convert this query for oracle, originally of postgres.
    Thank you anyone who can help me... Thank you very much

    Select
    CASE catg_id
    WHEN 1 THEN 'RESIDENCIAL.
    WHEN 2 THEN 'COMERCIAL '.
    WHEN 3 THEN 'INDUSTRIAL '.
    WHEN 4 THEN 'PÚBLICO '.
    END as 'category. "
    Sum (COALESCE(vlr_arrec_tot,0)) as "Bay Provisória Novembro_2010"

    Of

    -BAY NO.
    (
    Select
    COALESCE (arrec1.catg_id, Devol.catg_id) as catg_id,
    Sum (COALESCE(arrec1,0) - coalesce(devol,0)) as vlr_arrec_tot
    Of
    (
    Select catg_id,
    Sum (ARDD.ardd_vlpagamentos) as arrec1
    of arrecadacao.arrecadacao_dados_diarios ARDD
    where ardd.ardd_amreferenciaarrecadacao = 201011
    Group 1
    order by 1
    ) as arrec1
    full outer join
    (
    Select catg_id,
    Sum (DVDD.dvdd_vldevolucoes) as devol
    of arrecadacao.devolucao_dados_diarios dvdd
    where dvdd.dvdd_amreferenciaarrecadacao = 201011
    and dvdd.dvdd_tipodevolucao in ('C' 'd', ' not ')
    Group 1
    order by 1
    ) as devol on devol.catg_id = arrec1.catg_id

    Group 1
    order by 1
    ) as erera
    Group 1
    order by 1

    Hello

    saddones wrote:


    Even if I replace the string ' "Bay Provisória Novembro_2010", I have problems that order by and group by in a subquery,
    How can solve this problem?

    This depends on your data and the results you want. Whenever you have a problem, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.

    Did you remove the ORDER BY statements with subqueries, as I have suggested? If not, why? What were doing in the original system?
    Replace the statements 'GROUP 1' with 'GROUP BY catg_id' (or whatever the term appropriate in each case)?
    Post your modified code.

    What do you mean "I have problems?
    You get an error message? Display the full error message.
    You get incorrect results? After the correct resutls, highlight a few places where the current results are false and explain how to calculate the correct results.

    Where exactly the rror occurs? (Which is part of the information contained in the error message).
    Subqueries are running without errors by themselves?

    Like most of the sotware products, Oracle has different versions. Solutions that work in one version may not work in another, or the best solution in a version may not be the best in another. Do you want something that works on the basis of data of the Solver, or something that works on your database? Always show the full version of Oracle (e.g. 10.2.0.3.0) you use.

  • Using the drive with MSSQL and Oracle partitioning

    Hi all

    Although this isn't a likely configuration I would recommend/meeting, this issue has been driving me crazy because I can't find the answer and I don't know how to test it on my own (lack of material and knowledge).

    I met a paper on SQL Server 2012 and 2008R2, which States:
    When SQL Server performs sorting data IO operations, it first sorts data by partition. SQL Server accesses one disc at a time, and this can reduce performance. To improve the performance of data sorting, divide your partitions on disks data files by putting in place a RAID. In this way, although always SQL Server sorts data by partition, it can access all drives of each partition at the same time.
    http://msdn.microsoft.com/en-us/library/ms190787.aspx
    >

    I'm curious whether Oracle has the same "limitation." I see in the 10.2 docs they say:
    Although you are not required to keep each table or index partition (or subpartition) in a space separated, it is to your advantage to do so. Partitions in separate tablespaces storage allows you to:
    * reduce the risk of data corruption on several partitions

    * Save and retrieve each partition independently

    Controls the mapping of the partitions of hard disks (important for I/O load balancing)

    * Improve the manageability, availability and performance

    http://docs.Oracle.com/CD/B19306_01/server.102/b14231/partiti.htm
    >

    But it's not precisely say it can access more than one disc at a time. I can't tell if this applies to Oracle or not. Sorry for the reference to an earlier version, but I searched this statement in 11.2 documentation but could not find.

    Anyone can shed some light on this? It is eating at me :)

    Thank you
    Rich

    My PC at home came with two hard drives of 1 t. Default HP would deliver them together towards the top in a setting stripped for performance (even if I had the drive put in place like a mirror). For Windows, there is only a C"" drive. Yet, most of the documentation you have read still refer to the disk drives as your disc consists of physical disks to which you have access to. In a world record is often a block box, that is another question and discussion.

    HTH - Mark D Powell.

  • Convert the query

    Hello

    I have data in my table
    SELECT * FROM XXXTESTING
    
    MOD     SEGM     AMT
    AR     003-166155-000-001-SG000-0000-0000000-000000     1639.4
    AR     003-212403-000-000-SG000-0000-0000000-000000     114.76
    AP     001-212409-000-000-SG000-0000-0000000-000000     1639.4
    AP     001-166401-000-000-SG000-0000-0000000-000000     114.76
    expected as below
    AR     AP     
    003-166155-000-001-SG000-0000-0000000-000000     001-212409-000-000-SG000-0000-0000000-000000     1639.4
    003-212403-000-000-SG000-0000-0000000-000000     001-166401-000-000-SG000-0000-0000000-000000     114.76
    I tried my best level
    WITH XXX AS
    (
    SELECT CASE WHEN MOD='AR' THEN SEGM 
    ELSE NULL END  AR, 
    CASE WHEN MOD='AP' THEN SEGM 
    ELSE NULL END AP,
    AMT
    FROM XXXTESTING
    ) SELECT * FROM XXX 
    got the below output.
    AR             AP                                                                                AMT
              
    003-166155-000-001-SG000-0000-0000000-000000                                                                                          1639.4
    003-212403-000-000-SG000-0000-0000000-000000                                                                                            114.76
                                                                 001-212409-000-000-SG000-0000-0000000-000000                         1639.4
                                                                 001-166401-000-000-SG000-0000-0000000-000000                           114.76
    can you pls help me to get my desired result.

    Concerning
    Yram

    Hello

    with t as
    (select
    'AR' mod,'003-166155-000-001-SG000-0000-0000000-000000' segm,     '1639.4' amt from dual
    union
    select
    'AR' mod,     '003-212403-000-000-SG000-0000-0000000-000000' segm,     '114.76' amt from dual
    union
    select
    'AP' mod ,     '001-212409-000-000-SG000-0000-0000000-000000' segm,     '1639.4' amt from dual
    union
    select 'AP' mod     ,'001-166401-000-000-SG000-0000-0000000-000000' segm,     '114.76' amt from dual)
    SELECT MAX(DECODE(MOD,'AP',SEGM)) AS AP,MAX(DECODE(MOD,'AR',SEGM)) AS AR,MAX(AMT) FROM T
    GROUP BY AMT
    

    I hope this will help

    Published by: 810345 on May 30, 2011 15:54

  • convert the access query to oracle sql

    I'm trying to convert this query MS Access to oracle sql:

    Sum (IIf (IsNull ([INV_MTL_MATERIAL_TRANSACTIONS1]! [PRIMARY_QUANTITY]), 0,-[INV_MTL_MATERIAL_TRANSACTIONS1]! [PRIMARY_QUANTITY])) AS PRIMARY_QTY


    I tried to convert myself but still no luck.  Invalid number of arguments.


    Sum (if (NVL (INV. MTL_MATERIAL_TRANSACTIONS1. PRIMARY_QUANTITY), 0,-INV. MTL_MATERIAL_TRANSACTIONS1. PRIMARY_QUANTITY)) AS PRIMARY_QTY


    Can someone help me convert this request? Thank you.

    The immediate if (IIF) statement said:

    If primary_quantity is null return 0 for another return negative primary_quantity.

    Since there is no difference at all between 0 and - 0 I would write it as:

    sum (nvl (primary_quantity, 0) * - 1).

    Change a minute later, never send before thinking.

    Because you are just adding up the values obtained, he must not care about NULL values at all as aggregate functions generally ignore nulls, it should just be:

    Sum (primary_quantity * - 1).

    John

  • Help with the query to select only one record from the result set in double

    Hello

    Please help with the query. Version of Oracle database we use is 10g R2.

    I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec

    ID
    Org
    DF
    Sec Sub-Sec

    (163)CQCPDMCPDMHD(163)PCENGENGENG(163)CQASICASICIS8888TSTACTACTAC(163)TSHEHESW6789CQINFOINFOFOS6789PCSECSYSSECSYSINFO16789TSSECSYSSECSYSINFO29009PCBMSBMSBMS1

    My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.

    ID
    DSB

    DF
    SEC
    Sub-Sec
    (163)CQCPDMCPDMHD8888TSTACTACTAC6789CQINFOINFOFOS9009PCBMSBMSBMS1


    Thank you

    Orton

    Hello

    This sounds like a job for ROW_NUMBER:

    WITH got_r_num AS

    (

    SELECT id, DSB, df, s, sub_sec org

    ROW_NUMBER () OVER (PARTITION BY ID.

    ORDER BY org

    ) AS r_num

    OF view_x

    )

    SELECT id, DSB, df, sub_sec s,

    OF got_r_num

    WHERE r_num = 1

    ;

    He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data.  (I know that you said that you were a view selection.  Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.  (I didn't quite understand the explanation above.  I don't know why you want to

    ID ORG DF DRY SUB_SEC

    --      ---     --      ---     -------

    1234 CQ DPRK DPRK HD

    and is not

    1234 IS CQ ASIC, ASIC

    or

    TS 1234 IT IT SW

    or

    1234 CQ ASIC ASIC HD

    )
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    WITH cte (col1, col2) AS
    (
    SELECT col1, col2
    FROM dbo. [tb1]
    WHERE col1 = 12
    UNION ALL
    SELECT c.col1, c.col2
    FROM dbo. [tb1] AS c INNER JOIN cte AS p ON c.col2 = p.col1
    )
    DELETE one
    FROM dbo. [tb1] AS an INNER JOIN b cte
    ON a.col1 = b.col1

    Hello
    Something like this maybe:

    DELETE FROM dbo.tb1 a
     WHERE EXISTS (
      SELECT 1
        FROM dbo.tb1 b
      WHERE a.co11 = b.col1
          AND a.col2 = b.col2
       START WITH b.col1 = 12
      CONNECT BY b.col2 = PRIOR b.col1)
    

    Although you need to do here is to check that CONNECT it BY SELECT, returns records you wait first, then the DELETION should work too.

  • Convert the SQL query to Oracle

    Hi all

    I have two SQL queries to create the table.

    Query1.

    CREATE TABLE [dbo]. [DocumentType] (
    [DocType] [varchar] (20) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL,.
    [SubCat] [varchar] (20) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL
    ) ON [PRIMARY]
    GO
    ALTER TABLE [dbo]. [DocumentType] ADD
    CONSTRAINT [PK_DocumentType] PRIMARY KEY CLUSTER
    (
    [DocType],
    [SubCat]) ON [PRIMARY]


    Query2.

    CREATE TABLE [dbo]. [SBU] (
    [SBU] [varchar] (51) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL
    ) ON [PRIMARY]
    GO
    ALTER TABLE [dbo]. [SBU] ADD
    [PK_SBU] CLUSTERED PRIMARY KEY CONSTRAINT
    (
    [SBU]
    ) ON [PRIMARY]

    What will be the query in Oracle?

    Please suggest!
    Kind regards
    Shah

    Query1.

    CREATE TABLE dbo. DocumentType)
    DocType varchar2 (20) NOT NULL,
    SubCat varchar (20) NOT NULL,
    CONSTRAINT PK_DocumentType PRIMARY KEY (DocType, SubCat)
    )
    /

    Query2.

    CREATE TABLE dbo. SBU)
    SBU varchar2 (51),
    CONSTRAINT PK_SBU PRIMARY KEY (UDF)
    )
    /

    It is useful for you?

    Published by: insa on June 12, 2012 22:42

  • Is it possible to get the query Details of the old run from oracle?

    Is it possible to get the query Details of the old run from oracle? I mean, I wanted to know the details of a request executed work, I know the time taken by the query to run? Is it possible to know?

    Yes, it is possible to obtain, provided you use enterprise edition version + additional license *. A few tables to get information of are:

    dba_hist_sqltext

    dba_hist_sqlstat

    dba_hist_snapshot

    dba_hist_sql_plan

    dba_hist_active_sess_history

  • The query will run Oracle 10 g?

    Hello

    This is the structure of the table emp and dept. There is a request on this basis, please let me know if this request is going to work?

    EMP table
    =========
    EMPID NUMBER PRIMARY KEY,
    NAME
    ADDRESS

    DEPT table
    ==========
    DEPTNO NUMBER,
    DEPTNAME

    Select * from emp where empid in (select empid from dept where dept_no = 10);

    Nordik wrote:
    Hello

    This is the structure of the table emp and dept. There is a request on this basis, please let me know if this request is going to work?

    EMP table
    =========
    EMPID NUMBER PRIMARY KEY,
    NAME
    ADDRESS

    DEPT table
    ==========
    DEPTNO NUMBER,
    DEPTNAME

    Select * from emp where empid in (select empid from dept where dept_no = 10);

    Yes, it will run.

    Oracle must first check if the EMPID column exists in the DEPT table.
    If it's not, then it checks for columns in the outer query.

    And in this case, because you do not Alias of Table. An Alias has been used, the column would have been checked only in the table with an alias.

    In addition, you will lose everything except to check the query on a database, would you?

    Pretty easy to verify this, right?

    create table test_table (col1 number, col2 varchar2(5));
    
    create table test_table2 (col1 number);
    
    select *
      from test_table t1
     where col2 in (select col2 from test_table2 t2 where t1.col1 = t2.col1);
    
    no rows returned
    
  • The requests hung and implementation Oracle driver thin query timeout

    We are seeing occasional cases of threads blocked, where the code is in Oracle thin XA of the code driver waiting for a socket read a response from the database. Usually only one thread at a time. The connection is never ending and we close WebLogic to clear it. DBA tells us that all connections for the RAC 11 g of our guests cluster members are inactive, with no hanging transactions or long term.

    In this case every few cases of days between two WebLogic 10.3.5 grouped in our QA environment, is generally not the same time on both servers (we had four incidents, the other had one, in the last 15 days). Sometimes it resulted in a server hung, the driver is keeps a lock that is blocking other threads (today we had many discussions block in a restoration of TX).

    I'm guessing that our instance of WebLogic somehow does not receive the close connection of the remote host. BTW, there is no firewall between us and the DB. I don't have any suspect strong for the cause (even if we're under Linux on a virtual VMWare 4.0 computer, always worried).

    Usually, I would ask any application to set a timeout for the query or set the time-out request to connect with Betclic to work around the problem (we use a MultiDatasource), if the transaction will give up at least and the application can manage it. However, while the Oracle driver supports java.sql.Statement.setQueryTimeout (), a brief investigation on my part leads me to believe the time-out is implemented on the server side, not client side - so that if it is indeed the case that WebLogic does not see the outcome on the connection, it also would never see the timeout.

    Two questions:
    1. is my suspicion implementation timeout for Oracle 11 g correct server-side?
    2. If so, is there a property that I can put to the pilot who will implement a socket timeout? It is "safe"?

    Thanks for any help!

    [Oracle WebLogic 10.3.5, 64-bit JVM 1.6.0_29 HotSpot on RHEL 5.6 on VMWare;] Pilot of thin Oracle XA's bundled with WebLogic; Oracle RAC 11 g (three-node cluster)]

    Published by: SteveElkind on December 3, 2012 05:25

    Hi, Yes, there is a property, you can give the driver to taken all calls with a timeout of read.
    oracle.net.READ_TIMEOUT. The units are in milliseconds, so choose a high number
    enough that no reading legitimate, as a wait for the DBMS do an update or commit.
    etc., would take more time.

    Ignore the message by Mukesh. There's nothing relevant there.

  • Number displayed in the oracle.sql.NUMBER form in the result of the query

    Developer SQL version 3.2.10.09.57 displays numbers like "oracle.sql.NUMBER@66a35419 (the part after @ is not constant and change each time) even for simple count (*) select double."
    At the same time "run the Script (F5)" no indication that the header
    COUNT (*)
    ------------
    and no the query results.

    Hi Andriy,

    The forum search, I see a similar complaint noted against 3.1.07.42. Instruction execution produces the list oracle.sql.NUMBER, probably because of a corrupt installation query results (due to decompress questions, or perhaps no decompression in an empty directory). See the following thread:
    SQLDev 3.1: Number-fields in the tables have "oracle.sql.NUMBER @...". »

    Hope this helps,
    Gary
    SQL development team

  • Convert the Sql for Oracle script

    Could someone help me convert the sql script in oracle below

    -- EXEC SP_smpAGENCY_MYWS_LAPSE_GET_USP_AMSurrenderMngtReport '2005','2010','09048','IL'    
    ALTER PROCEDURE SP_smpAGENCY_MYWS_LAPSE_GET_USP_AMSurrenderMngtReport    
    --DECLARE     
    @StartYY AS VARCHAR(4),    
    @EndYY AS VARCHAR(4),    
    @AgentCode AS VARCHAR(9),    
    @CompanyCode AS VARCHAR(4)    
        
    AS    
        
    DECLARE @ProfileYYYYMM AS VARCHAR(6), @SQLStr1 AS VARCHAR(8000),@SQLStr2 AS VARCHAR(8000), @SQLStr3 AS VARCHAR(8000)    
        
    SET @ProfileYYYYMM = '201005'    
        
    SET @SQLStr1 = ''    
        
    SET @SQLStr1 = @SQLStr1 + ' DECLARE @CompAvgCount AS  DECIMAL(38,2), @CompAvgAP AS  DECIMAL(38,2), @CompInforceAP AS DECIMAL(15,2), @CompSurrenderAP AS DECIMAL(15,2), '    
    SET @SQLStr1 = @SQLStr1 + ' @CompInforceCount NUMERIC, @CompSurrenderCount NUMERIC,@ALCompInforceAP AS DECIMAL(15,2), @ALCompSurrenderAP AS DECIMAL(15,2), '    
    SET @SQLStr1 = @SQLStr1 + ' @ALCompInforceCount NUMERIC, @ALCompSurrenderCount NUMERIC,@ILCompInforceAP AS DECIMAL(15,2), @ILCompSurrenderAP AS DECIMAL(15,2), '    
    SET @SQLStr1 = @SQLStr1 + ' @ILCompInforceCount NUMERIC, @ILCompSurrenderCount NUMERIC '    
      
    SET @SQLStr1 = @SQLStr1 + ' DECLARE @tblAgentNumber TABLE '    
    SET @SQLStr1 = @SQLStr1 + ' ( '    
    SET @SQLStr1 = @SQLStr1 + '  [AgentName] VARCHAR(255), '    
    SET @SQLStr1 = @SQLStr1 + '  [AgentNumber] VARCHAR(9), '    
    SET @SQLStr1 = @SQLStr1 + '  [AgentRank] VARCHAR(10) '    
    SET @SQLStr1 = @SQLStr1 + ' ) '    
      
    SET @SQLStr1 = @SQLStr1 + '  DECLARE @tblmineInForce TABLE '    
    SET @SQLStr1 = @SQLStr1 + ' ( '    
    SET @SQLStr1 = @SQLStr1 + '  [company_code] VARCHAR(50), '    
    SET @SQLStr1 = @SQLStr1 + '  [mine_policy_no] VARCHAR(50), '    
    SET @SQLStr1 = @SQLStr1 + '  [Annl_premium] NUMERIC(28, 2) '    
    SET @SQLStr1 = @SQLStr1 + ' ) '    
        
    SET @SQLStr1 = @SQLStr1 + ' DECLARE @tblmineSurrender TABLE '   
    SET @SQLStr1 = @SQLStr1 + ' ( '    
    SET @SQLStr1 = @SQLStr1 + '  [company_code] VARCHAR(50), '    
    SET @SQLStr1 = @SQLStr1 + '  [mine_policy_no] VARCHAR(50), '     
    SET @SQLStr1 = @SQLStr1 + '  [Annl_premium] NUMERIC(28, 2) '    
    SET @SQLStr1 = @SQLStr1 + ' ) '    
        
    SET @SQLStr1 = @SQLStr1 + ' INSERT INTO @tblAgentNumber '    
    SET @SQLStr1 = @SQLStr1 + ' SELECT AgentName, AgentNumber, AgentRank '    
    SET @SQLStr1 = @SQLStr1 + ' FROM [SUMYOLAP0001].aetnaildb.dbo.agentprofile'+ @ProfileYYYYMM +' AgtProfile '    
    SET @SQLStr1 = @SQLStr1 + ' WHERE (LEN(agentnumber) = 5 and (left(agentnumber,1) between ''0'' and ''8'' or left(agentnumber,1) = ''A'')) '    
    SET @SQLStr1 = @SQLStr1 + ' AND (Amname not like ''%COMPANY%'' OR Amname not like ''%DIRECT%'' OR Amname not like ''%MARKETsmp%'') '    
    SET @SQLStr1 = @SQLStr1 + ' AND agencynumber not in (''ILS'',''PLS'',''99999'') '    
    SET @SQLStr1 = @SQLStr1 + ' AND LEFT(agencynumber,2) not in (''CD'',''DR'') AND LEFT(agencynumber,3) <> ''DIR'' '    
    SET @SQLStr1 = @SQLStr1 + ' AND RIGHT(RTRIM(agencynumber),2) not in (''CD'',''DR'') AND RIGHT(RTRIM(agencynumber),3) <> ''DIR'' '    
    SET @SQLStr1 = @SQLStr1 + ' AND companycode = ''IL'' '    
        
    SET @SQLStr1 = @SQLStr1 + ' INSERT INTO @tblmineSurrender '    
    SET @SQLStr1 = @SQLStr1 + ' SELECT company_code, mine_policy_no, Annl_premium '    
    SET @SQLStr1 = @SQLStr1 + ' FROM odsmine_policy '    
    IF @CompanyCode = 'All'    
    BEGIN    
     SET @SQLStr1 = @SQLStr1 + ' WHERE company_code IN (''IL'',''AL'') '    
    END    
    ELSE    
    BEGIN    
     SET @SQLStr1 = @SQLStr1 + ' WHERE company_code IN ('''+ @CompanyCode +''') '    
    END    
    SET @SQLStr1 = @SQLStr1 + ' AND cont_status = ''S'' '    
    SET @SQLStr1 = @SQLStr1 + ' AND YEAR(effective_date) BETWEEN '+ @StartYY +' AND '+ @EndYY +' '    
        
    SET @SQLStr1 = @SQLStr1 + ' SELECT @CompSurrenderCount = COUNT(1), @CompSurrenderAP = SUM(Annl_premium) '    
    SET @SQLStr1 = @SQLStr1 + ' FROM @tblmineSurrender S '    
    SET @SQLStr1 = @SQLStr1 + ' INNER JOIN odsagent_role R '    
    SET @SQLStr1 = @SQLStr1 + ' ON S.company_code = R.company_code '    
    SET @SQLStr1 = @SQLStr1 + ' AND S.mine_policy_no = R.mine_policy_no '    
    SET @SQLStr1 = @SQLStr1 + ' INNER JOIN @tblAgentNumber A '    
    SET @SQLStr1 = @SQLStr1 + ' ON R.servicsmpagent_code = A.AgentNumber '    
        
    SET @SQLStr1 = @SQLStr1 + ' INSERT INTO @tblmineInforce '    
    SET @SQLStr1 = @SQLStr1 + ' SELECT company_code, mine_policy_no, Annl_premium '    
    SET @SQLStr1 = @SQLStr1 + ' FROM odsmine_policy '    
    IF @CompanyCode = 'All'    
    BEGIN    
     SET @SQLStr1 = @SQLStr1 + ' WHERE company_code IN (''IL'',''AL'') '    
    END    
    ELSE    
    BEGIN    
     SET @SQLStr1 = @SQLStr1 + ' WHERE company_code IN (''' + @CompanyCode + ''') '    
    END    
    SET @SQLStr1 = @SQLStr1 + ' AND cont_status = ''I'' '    
    SET @SQLStr1 = @SQLStr1 + ' AND YEAR(effective_date) BETWEEN '+ @StartYY +' AND '+ @EndYY +' '    
        
    SET @SQLStr1 = @SQLStr1 + ' SELECT @CompInforceCount = COUNT(1), @CompInforceAP = SUM(Annl_premium) '    
    SET @SQLStr1 = @SQLStr1 + ' FROM @tblmineInforce I '    
    SET @SQLStr1 = @SQLStr1 + ' INNER JOIN odsagent_role R '    
    SET @SQLStr1 = @SQLStr1 + ' ON I.company_code = R.company_code '    
    SET @SQLStr1 = @SQLStr1 + ' AND I.mine_policy_no = R.mine_policy_no '    
    SET @SQLStr1 = @SQLStr1 + ' INNER JOIN @tblAgentNumber A '    
    SET @SQLStr1 = @SQLStr1 + ' ON R.servicsmpagent_code = A.AgentNumber '    
        
    SET @SQLStr1 = @SQLStr1 + ' SET @CompAvgCount = ROUND(ISNULL(@CompSurrenderCount,0) * 100 / ( ISNULL(@CompSurrenderCount,0) + @CompInforceCount),2) '     
    SET @SQLStr1 = @SQLStr1 + ' SET @CompAvgAP = ROUND(ISNULL(@CompSurrenderAP,0) * 100 / ( ISNULL(@CompSurrenderAP,0) + @CompInforceAP),2) '     
        
    SET @SQLStr1 = @SQLStr1 + ' DECLARE @tblODSmine_Policy TABLE '    
    SET @SQLStr1 = @SQLStr1 + ' ( '    
    SET @SQLStr1 = @SQLStr1 + '  [AgentName] VARCHAR(255), '    
    SET @SQLStr1 = @SQLStr1 + '  [AgentNumber] VARCHAR(9), '    
    SET @SQLStr1 = @SQLStr1 + '  [AgentRank] VARCHAR(10), '    
    SET @SQLStr1 = @SQLStr1 + '  [Company_Code] VARCHAR(4), '    
    SET @SQLStr1 = @SQLStr1 + '  [mine_Policy_No] VARCHAR(10), '    
    SET @SQLStr1 = @SQLStr1 + '  [Cont_Status] VARCHAR(1), '    
    SET @SQLStr1 = @SQLStr1 + '  [Annl_Premium] DECIMAL(15,2), '    
    SET @SQLStr1 = @SQLStr1 + '  [No_count] NUMERIC '    
    SET @SQLStr1 = @SQLStr1 + ' ) '    
        
    SET @SQLStr2 = 'INSERT INTO  @tblODSmine_Policy '    
    SET @SQLStr2 = @SQLStr2 + ' SELECT DISTINCT AgtProfile.AgentName, AgtProfile.AgentNumber, '    
    SET @SQLStr2 = @SQLStr2 + ' AgtProfile.AgentRank,mine.company_code, mine.mine_policy_no, mine.cont_status, mine.Annl_Premium, 1.0 as no_count '    
    SET @SQLStr2 = @SQLStr2 + ' FROM @tblAgentNumber AgtProfile '    
    SET @SQLStr2 = @SQLStr2 + ' INNER JOIN [SUMYOLAP0001].aetnaildb.dbo.COMAGH COMAGH '    
    SET @SQLStr2 = @SQLStr2 + ' ON AgtProfile.AgentNumber = COMAGH.AHAGTN '    
    SET @SQLStr2 = @SQLStr2 + ' AND (AHAMNO = ''' + @AgentCode + ''' OR AHUMNO = ''' + @AgentCode + ''' OR AHAGNO = ''' + @AgentCode + ''') '    
        
    IF @CompanyCode = 'ALL'    
    BEGIN    
     SET @SQLStr2 = @SQLStr2 + ' AND AHCO IN (''AL'',''IL'') '    
    END    
    ELSE    
    BEGIN    
     SET @SQLStr2 = @SQLStr2 + ' AND AHCO = ''' + @CompanyCode + ''' '    
    END    
        
    SET @SQLStr2 = @SQLStr2 + ' INNER JOIN odsagent_role Role '    
    SET @SQLStr2 = @SQLStr2 + ' ON AgtProfile.AgentNumber = Role.servicsmpagent_code '    
    SET @SQLStr2 = @SQLStr2 + ' INNER JOIN odsmine_policy mine '    
    SET @SQLStr2 = @SQLStr2 + ' ON Role.company_code = mine.company_code '    
    SET @SQLStr2 = @SQLStr2 + ' AND Role.mine_policy_no = mine.mine_policy_no '    
    SET @SQLStr2 = @SQLStr2 + ' AND mine.cont_status IN (''S'',''I'') '    
        
    IF @CompanyCode = 'ALL'    
    BEGIN    
     SET @SQLStr2 = @SQLStr2 + ' AND mine.company_code IN (''AL'',''IL'') '    
    END    
    ELSE     
    BEGIN    
     SET @SQLStr2 = @SQLStr2 + ' AND mine.company_code = ''' + @CompanyCode + ''' '    
    END    
        
    SET @SQLStr2 = @SQLStr2 + ' AND YEAR(mine.effective_date) BETWEEN '+ @StartYY +'  AND  '+ @EndYY +' '    
        
    SET @SQLStr3 = 'SELECT AgentName, AgentRank, AgentNumber, '    
    SET @SQLStr3 = @SQLStr3 + ' CONVERT(INT,SUM(CASE WHEN cont_status = ''S'' THEN no_count ELSE 0 END)) AS Surrrender_Count, '    
    SET @SQLStr3 = @SQLStr3 + ' CONVERT(INT,SUM(CASE WHEN cont_status = ''I'' THEN no_count ELSE 0 END)) AS InForce_Count, '    
    SET @SQLStr3 = @SQLStr3 + ' SUM(CASE WHEN cont_status = ''S'' THEN Annl_premium ELSE 0 END) AS SurrenderAP, '    
    SET @SQLStr3 = @SQLStr3 + ' SUM(CASE WHEN cont_status = ''I'' THEN Annl_premium ELSE 0 END) AS InForceAP, '    
    SET @SQLStr3 = @SQLStr3 + ' CASE WHEN count(*) = 0 THEN 0 ELSE CONVERT(DECIMAL(38,2),(SUM(CASE WHEN cont_status = ''S'' THEN no_count ELSE 0 END) * 100 / count(*))) END AS AgtSurrenderCount, '    
    SET @SQLStr3 = @SQLStr3 + ' CASE WHEN SUM(Annl_premium) = 0 THEN 0 ELSE CONVERT(DECIMAL(38,2),(SUM(CASE WHEN cont_status = ''S'' THEN Annl_premium ELSE 0 END) * 100 / SUM(Annl_premium))) END AS AgtSurrenderAP, '    
    SET @SQLStr3 = @SQLStr3 + ' CONVERT(varchar(100),@CompAvgCount) AS CompAvgCount, '    
    SET @SQLStr3 = @SQLStr3 + ' CONVERT(varchar(100), @CompAvgAP) AS CompAvgAP '    
    SET @SQLStr3 = @SQLStr3 + ' FROM @tblODSmine_Policy '    
    SET @SQLStr3 = @SQLStr3 + ' GROUP BY AgentName, AgentRank, AgentNumber '    
        
    EXEC (@SQLStr1 + @SQLStr2 + @SQLStr3)    
    --PRINT (@SQLStr1 + @SQLStr2 + @SQLStr3)    

    Yes.

    1. the scrap code.
    2. get the specification of the requirements of business origin.
    3. learn PL/SQL.
    4. write the PL/SQL code to meet the requirements of the company.

  • Error exporting Oracle on the QUERY parameter

    Hi all

    I would like to ask for help.

    This is my environment:
    OS: Linux 5.4 32-bit
    DB: Oracle 10.2.0.4

    Here's what I would do:
    Export the selected lines of SH. Table SALES using the query:

    SQL > select * from sh.sales
    where to_date(time_id,'DD-MON-RR:HH24:MI:SS') = to_date('28-DEC-01:00:00:00','DD-MON-RR:HH24:MI:SS');

    My parfile is:

    UserID = ' oracle/sys as sysdba'
    buffer = 10000000
    file = mysales148.dmp
    Journal = mysales148.log
    TABLES is sh. MySales
    Query = "(où to_date(time_id,\'DD\-MON\-RR:HH24:MI:SS\')=\to_date(\'28\-DEC\-01:00:00:00\',\'DD\-MON\-RR:HH24:MI:SS\')" "
    RecordLength = 65535
    Statistics = none


    When I run the script, I get this error:

    [oracle@shaoran selective_export] $ exp parfile = exp_mysale.par

    Export: Release 10.2.0.1.0 - Production the game 3 Feb 16:57:08 2011

    Copyright (c) 1982, 2005, Oracle. All rights reserved.


    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With partitioning, OLAP and Data Mining options
    Export in US7ASCII and AL16UTF16 NCHAR character set
    Server uses WE8ISO8859P1 (possible character set conversion) character set

    About to export specified tables by conventional means...
    Current user has changed to SH
    . . MYSALES table export
    EXP-00056: ORACLE 911 error encountered
    ORA-00911: invalid character
    Export completed successfully with warnings.


    Hope to hear from you soon.

    Thank you very much!

    First of all,

    export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
    

    It is probably the cause of your problem if you have unusual characters in your data.

    If this isn't the case, you do not have these "------" in your QUERY. Since you're using parfile, just go with what you would do in sqlplus:

    query="where time_id=to_date('28-DEC-01:00:00:00','DD-MON-RR:HH24:MI:SS')"
    
  • Error oracle FRM-40505 unable to execute the query

    Hi gurus,

    When query the values in host order of Super order management user

    The following error is displayed:

    FRM-40505: ORACLE error: cannot perform the query

    What is the solution for this error?

    Concerning

    SBJ *.

    Take a look at Metalink Note: "Troubleshooting FRM-40505 [ID 1004134.6].

    Khan

Maybe you are looking for

  • slow loading sites

    FF 7.0.1 whenever I start FF it restores the old eye what he should also. But then I have to wait more than a minute it load one. I'm just connection... There is no net activity. Once this FF works without problem. I checked it with FF 6 versions and

  • Inkjet HP 8600 so not able to print from office

    Just recently my office ceased to be able to print via WiFi so all in one printer and the HP officejet 8600 in the next room. I headed to the printer and confirmed that the wifi on the LCD is on, it was. I tried to print the wireless network test res

  • Equium A110-233: upgrade HDD - can I use 250 GB HARD drive?

    Hi all I would like to upgrade my hard drive (40 GB now). What is the maximum capacity of HD, that supports my Toshiba? Can I put still 250GB? Another question is, can I buy for example external USB 2.5 "hard drive and swap the drive of my laptop wit

  • acquire and graph of a voltage using LABVIEW 8.6 and DAQ 6020

    I recently installed Labview 8.6 on XP based computer and my device is 6020 DAQ. I installed the driver 7.4.4 to my DAQ 6020. This is my first attempt to write a labview on this configuration code, and my request is very simple. I want to measure a v

  • HP Pavilion dv7 Notebook PC: IDT HD Audio Drivers w / Beats - reinstall

    I've had my laptop HP refurbished for a couple of years now, and it was working fine, no problems at all. Then, one night a few months previously, the audio literally clicked and stopped working. I was able to reactivate it with a driver that I found