With the help of the Case clause with clause type

Hello PL SQL gurus

I used a few scripts I found on these forums to create an amortization of mortgage statement. What I'm trying to accomplish is to get the script to run a calculation or use a value in a table based on the value in this table.

Here are two tables:


CREATE TABLE mortgage_facts (customer VARCHAR2 (20), result VARCHAR2 (20),)
quantity NUMBER (10.3));

INSERT INTO mortgage_facts VALUES ('Smith', 'Ready', 131828.81);
INSERT INTO mortgage_facts VALUES ('Smith', 'Annual_Interest', 3,348);
INSERT INTO mortgage_facts VALUES ('Smith', 'Payments', 72);
INSERT INTO mortgage_facts VALUES ('Smith', 'PaymentAmt', 0);


Mortgage of CREATE TABLE (customer VARCHAR2 (20), pmt_num, no.4, principalp NUMBER (10.3), interestp NUMBER (10.3), mort_balance NUMBER (10.3));
INSERT INTO mortgage VALUES ('Smith', 0, 0, 0, 131828.81);



If the value in the mortgage_facts table is zero, I want the script runs a calculation to be used in a MODEL clause. If it is not zero, I would use this value instead of the calculation. Here is the script I am getting an error on (I have bolded the part in question):



SELECT c, p, to_char (round(m,2), 'fm$ 9999999.00') principal_balance,
TO_CHAR (Round(pp,2), 'fm$ 9999999.00') towards_principal,
TO_CHAR (Round(IP,2), 'fm$ 9999999.00') towards_interest,
TO_CHAR (Round(MP,2), 'fm$ 9999999.00') monthly_payment
MORTGAGE COMPANY
MODEL - see 1
IGNORE THE NAV
REFERENCES R ON
* (SOME customers, fact, amt - see 2 *)
FROM mortgage_facts
* MODEL SIZE (customer, done) MEASURES (amount amt) - see 3 *.
REGULATION SEQUENCE
*(*
CASE WHEN mortgage_facts.fact = 'PaymentAmt' AND mortage_facts.amt = 0 THEN
*(*
* amt [ALL, 'PaymentAmt'] = mortgage_facts.amt*
*)*

ON THE OTHER

*(*
* amt [everything, "PaymentAmt"] = (amt [CV (), "Ready"] *)
* Power (1 + (amt [CV (), 'Annual_Interest'] / 100/12), *)
(* AMT [CV (), 'Payments']) *.
(* AMT [CV (), 'Annual_Interest'] / 100/12)) / *.
* (Power (1 + (AMT [CV (), 'Annual_Interest'] / 100/12), *))
(* AMT [CV (), 'Payments'])-1) *.
*)*
END
*)*
*)*

SIZE OF (customer cust, made) measures (amt)
Amortization of PRINCIPAL
PARTITION BY (customer c)
DIMENSION (p) 0)
MEASURES (pp, interestp ip principalp, mort_balance m, mc, mp 0 customer)
REGULATION SEQUENCE
ITERATE (1000) UP TO (ITERATION_NUMBER + 1 =
r.AMT [MC [0], 'Payments'])
(ip [ITERATION_NUMBER + 1] = m [CV () - 1] *)
r.AMT [MC [0], 'Annual_Interest'] / 1200,.
MP [ITERATION_NUMBER + 1] = r.amt [mc [0], "PaymentAmt"],
pp [ITERATION_NUMBER + 1] = r.amt [mc [0], 'PaymentAmt']-ip [CV ()].
m [ITERATION_NUMBER + 1] = m [CV () - 1] - pp [CV ()]
)
ORDER BY c, p

Any help is very appreciated. Thank you!!

OK, here we go, go with the iterative model:

select *
from mortgage_facts
model
partition by (Customer)
dimension by (1 p)
measures(loan, payments, INTEREST, PAYMENTAMT, INTERESTPMT, PRINCIPALPMT, balance)
rules iterate(1e9) until (iteration_number+2 >= payments[1])
 (loan[iteration_number+2]=loan[1]
 ,payments[iteration_number+2]=cv(p)-1
 ,interest[iteration_number+2]=interest[1]
 ,paymentamt[iteration_number+2]=ROUND(
  (LOAN[1] * (INTEREST[1]/12/100)*Power((1+INTEREST[1]/12/100), PAYMENTS[1])/(Power((1+INTEREST[1]/12/100),PAYMENTS[1])-1)), 2)
 ,INTERESTPMT[iteration_number+2]=round(balance[cv(p)-1]*interest[1]/1200, 2)
 ,PRINCIPALPMT[iteration_number+2]=paymentamt[cv()]-INTERESTPMT[cv()]
 ,balance[iteration_number+2]=balance[cv()-1]-PRINCIPALPMT[cv()]
)

CUSTOMER     P     LOAN     PAYMENTS     INTEREST     PAYMENTAMT     INTERESTPMT     PRINCIPALPMT     BALANCE
Smith     1     131828.81     72     3.348     0     0     0     131828.81
Smith     2     131828.81     1     3.348     2023.55     367.8     1655.75     130173.06
Smith     3     131828.81     2     3.348     2023.55     363.18     1660.37     128512.69
Smith     4     131828.81     3     3.348     2023.55     358.55     1665     126847.69
Smith     5     131828.81     4     3.348     2023.55     353.91     1669.64     125178.05
Smith     6     131828.81     5     3.348     2023.55     349.25     1674.3     123503.75
Smith     7     131828.81     6     3.348     2023.55     344.58     1678.97     121824.78
Smith     8     131828.81     7     3.348     2023.55     339.89     1683.66     120141.12
Smith     9     131828.81     8     3.348     2023.55     335.19     1688.36     118452.76
Smith     10     131828.81     9     3.348     2023.55     330.48     1693.07     116759.69
Smith     11     131828.81     10     3.348     2023.55     325.76     1697.79     115061.9
Smith     12     131828.81     11     3.348     2023.55     321.02     1702.53     113359.37
Smith     13     131828.81     12     3.348     2023.55     316.27     1707.28     111652.09
Smith     14     131828.81     13     3.348     2023.55     311.51     1712.04     109940.05
....

Tags: Database

Similar Questions

  • error in pl/sql of the CASE clause.

    Hello
    I m not a sql progremmer. an interior according to the database worked for previous but not mentioned dates and may be for dates too.
    Error is given after the following code.

    We have 4 store-ID, that ID is to have values rest three IDs have values 0. Gets the ID having missed in FUND and error values. The cursor query works fine when executed alone.

    kindly advice!

    declare
    ip_date varchar2 (30): =' 27-AUG-2011.
    cursor dwn_cnt (param_date varchar2, param_hr number), select store b.aw_store_id, count (*) bv1to1.aw_user_dwnld_cnt count_dwn, b bv1to1.bv_user_profile where a.date_download between to_date(param_date||) e '|| param_hr |': 0 0:00 ', "HH24:MI:SS of MON-DD-YYYY") and to_date(param_date||) e '|| param_hr | (": 59: 59 ',' MON-DD-YYYY HH24:MI:SS') and a.user_id = b.user_id group by b.aw_store_id;
    dwn_cnt_var dwn_cnt % rowtype;
    type dwn_cnt_hr is table of number of pls_integer indexes;
    dwn_cnt_hr_var dwn_cnt_hr;
    Start
    dbms_output.put_line ('US' |) ',' ||' DE'||','||' UK'||','||' FR'||','||' TIME ');
    dbms_output.put_line(' ');
    I'm in 0.23
    loop
    dwn_cnt_hr_var (0): = 0;
    dwn_cnt_hr_var (103): = 0;
    dwn_cnt_hr_var (104): = 0;
    dwn_cnt_hr_var (105): = 0;
    dwn_cnt_hr_var (200): = 0;
    Open dwn_cnt (ip_date, i);
    extract the dwn_cnt in dwn_cnt_var;
    loop
    box (dwn_cnt_var. Store)
    When 0 then
    dwn_cnt_hr_var (0): = dwn_cnt_var.count_dwn;
    When there are 103 then
    dwn_cnt_hr_var (103): = dwn_cnt_var.count_dwn;
    When there are 104 then
    dwn_cnt_hr_var (104): = dwn_cnt_var.count_dwn;
    When 105 then
    dwn_cnt_hr_var (105): = dwn_cnt_var.count_dwn;
    When 200 then
    dwn_cnt_hr_var (200): = dwn_cnt_var.count_dwn;
    end case;
    extract the dwn_cnt in dwn_cnt_var;
    When the output dwn_cnt % notfound;
    end loop;
    dbms_output.put_line (dwn_cnt_hr_var (0) + dwn_cnt_hr_var (200) |) «, » || dwn_cnt_hr_var (103) | «, » || dwn_cnt_hr_var (105) | «, » || dwn_cnt_hr_var (104) | «, » || (i);
    close dwn_cnt;
    end loop;
    end;
    /

    OUTPUT:-

    US, UK, FR, HOUR
    declare
    *
    ERROR on line 1:
    ORA-06592: not found CASE when executing CASE statement
    ORA-06512: at line 20
    Elapsed time: 00:00:00.90

    Rgds,
    Abdallah.

    You need an ELSE clause:

    ...
    when 200 then
       dwn_cnt_hr_var(200):=dwn_cnt_var.count_dwn;
    else
       /* code here for what to do if none of the WHEN clauses are true */
    end case;
    ...
    
  • Yahoo mail compose page announced the Indian Railways. Same is the case with some Gmail site. For this reason, it is difficult to compose mail. I need your help to clear advertising so that I can compose mail on the blank page, cordially. Maes

    Yahoo mail is normally empty. One can type mail in the blank part of . In my case the Compose page has rail logo. because I can't type my mail. Even if there is no problem in gmail-INBO isn't the case with Gmail site "A Google approach to email" or make up may site.
    For this reason, it is difficult to compose mail on yahoo mail. I need your help to clear advertising logo so that I can compose mail on a white page, cordially. eldiablo kumar

    You can also try to install Adblock Plus with Easylist subscription and check

  • Help with the Structures of the case

    I have a problem switching between the true and false cases between the structures of the case. I'm writing a VI that generates a random number between 0 and 10 once every 0.5 seconds, and then adds the numbers until the total reaches or exceeds 100. At that time, it should start to subtract the number generated at random until it reaches 0, then switch again adding etc.

    I have a problem switching to the case of 'false' once the sum exceeds 100. If anyone can help with that would be great!

    To make things more simple exchange the Boolean value for an enumeration with only two values you can call "Count Up" and "Count Down".

    Create a second shift register to hold the enumerated value specifying whether to "Count Up" or "Count Down". Initialize the new register shift to count up, and in the case of "Count Up" in the structure of the case, increment the value of data and test to see if it is greater than 100. If this is not the case, do not change the value in the registry to shift direction. If data has exceeded the limit, change the values in the shift of direction register account to "Count Down".

    In the case of 'Count Down', decrement the value of data and test a value less than 0. When the value of the data is less than the lower limit, change the values in the change of direction of the County Register to "Count Up" and you're done.

    Mike...

  • With the help of strings concatenated in the Structure of the case

    Hello world

    I'm all new to LabView. Right now, I just trying to build a graphic program of different waves (such as the sine or square) with or without different types of noise. I concatenated two strings and then participating in a housing structure. Nothing graphic when have two concatenated options, but it does not work when it's just the different types of wave are chosen. I think it might have to do with how I'm the each case titration structure option, but I'm not sure. For any help or suggestion is greatly appreciated.

    I would use a sequence of structures of the case. Take it step by step. Use enumerations for readability.

  • Lenovo u300s came with the crack in the case. Queued for more than two hours. Help, please!

    I received my phone Friday and noticed shortly after opening the package that there is a crack in the bottom right of the laptop cover. The bottom of the laptop is now separating it from the case.

    I spent more than two hours on hold trying to request a RMA. This is unacceptable.

    I want a full refund, that this failure to Lenovo may have been spotted before it was delivered to me.

    My customer information are below. Please contact me to correct this situation.

    Order number: 4288307601

    number of cases: 8000174706

    Note of the moderator; personal information under the protection of its own branch

    Hey elhortez,

    Working to get support for you to get the process of refund for you. I'll follow to the top as soon as I can with confirmation.

    Thank you

    Ty

  • Help, please! How can I re - install my photoshop CS6 if my Mac is not the case with CD?

    That's the problem...

    I have Photoshop CS6 on CD but my new macbook pro is not the case of CD... How can I do? My old macbook is broken and I can't use it. Please help me.

    My version of photoshop CS6 is for student and my new macbook is a macbook pro 13 "retina.

    I hope someone help me.

    Thank you for the support.

    You can download it here, but will not require your serial number:

    Download Adobe Creative Suite 6 applications

  • Problem with the case where the clause

    Hello

    I want to use cases in which clause. I wrote a very simple query to test how it works. However, I always got an error message. Here's what I did.

    Select eid, firstname, lastname from employee where eid = 1 works fine

    Select eid, name, name of the employee

    where

    cases where 1 = 1 then eid = 1

    When 1! = 1 then eid = 2

    end

    I ORA-00905: lack of keyword.

    Did I miss something?

    Thank you

    Jennifer

    Hi, Jennifer.

    Why do you want to use BOX in a WHERE clause?  The wonderful thing about the CASE is that it allows you to do IF-THEN-ELSE logic.  In a SELECT clause, or an ORDER BY clause, this is really useful, but the WHERE clause already allows you to use the IF-THEN-ELSE logic.

    However, if you use the BOX in a WHERE clause, it is as it does nowhere else.  Always BARGAIN instead of a single expression in a SQL data types.  All the clauses THEN (and ELSE, if there is one) must return a single expression, such as the NUMBER.  (There is no BOOLEAN data type in SQL).  So, you can use a CASE statement like this:

    ...

    CASES WHERE

    WHEN 1 = 1 THEN 1

    WHEN 1! = 1 THEN 2

    END = eid

    Here, the CASE expression takes the place of a NUMBER.

    However, if I was not sure if 1 = 1 or not, I would write the condition in this way, without a CASE expression:

    WHERE (1 = 1 AND eid = 1)

    OR (1! = 1 AND eid = 2).

  • Inbox is related to Mozilla? If this is not the case, how I find myself with it when I upgraded my Firefox?

    What is the Inbox that has appeared on my firefox? Is it related to firefox? If this is not the case, how can I get rid of him? This happened after I've upgraded to the latest version. Thank you

    Hi, no this is not part of firefox. Please always make sure that you only have to download firefox from the official site at getfirefox.com. Please try these steps to get rid of this adware:

    1. Go to firefox > help > troubleshooting information > profile folder - "view folder", then a new window will open. in this search on a file named user.js window (it can be used to overwrite your custom settings). where it is present, delete or rename this file and then restart firefox. How to fix preferences that will not save
    2. then install the reset search addon - he'll come back more often customizations make these adware programs in default firefox: https://addons.mozilla.org/firefox/addon/searchreset/
    3. Finally, run a full scan of your system with security tools like the free version of malwarebytes & adwcleaner to ensure that it is not adware in other places as well.

    Remove a toolbar that has supported your Firefox or the homepage search
    Fix Firefox problems caused by malicious software

  • Synchronize the case structure with enum update

    Hi, I created a control enum initially with the "First" and "Second" values. In the block diagram, I created a node of this enum control property and it is connected to a box structure. The structure of business allows me to manage the condition "First" or "Second" correctly.

    I then modified the items in my enum so there is now a 'third party '. My problem is that structure business conditions still show as 'First' and 'second '; That is to say, I can't handle the "Third" condition My question is how to synchronize my case structure to show the updated enum values?

    VI, attached, the sample created with LabVIEW 2009 version 9.0f3 (32-bit) running on Windows 7.

    Thank you all for your help in advance.

    Michael O'Shea

    First tip: remove the value 'default' first case

    If you have done your VI pauses when you change your enum, which is a good thing.

    Now to synchronize, do a right-click on the border of the structure of the case and select 'add the case for all values', this is the option you are looking for.

    Tone

  • So I recently found my game Age of Mythology. The disc is very good and works, but I have not the case with the number of products to this topic. What should I do?

    So I recently found my game Age of Mythology. The disc is very good and works, but I have not the case with the number of products to this topic. What should I do?

    Hi GuyT6,

    ·         What version of the operating system is installed on the computer?

    I suggest you contact the customer assistance form help and more information.

    How and when to contact Microsoft and support Customer Service

    http://support.Microsoft.com/kb/295539

  • Query with the having clause

    Hi all

    I have this select statement to help to filter different from zero records.

    Select GroupName, Nom_liste,

    Sum ((a_cost/1000) * degradation * quantity * total_count * index) such as total_cost,.

    FROM MyTable

    having sum ((a_cost/1000) * degradation * quantity * total_count * index) <>0

    Group GroupName, Nom_liste

    Having done so the query to run more slowly.

    How can I filter records with zero total_cost (they can be negative or greater than zero).

    Thank you!

    Hello

    user9542267 wrote:

    Hi all

    I have this select statement to help to filter different from zero records.

    Select GroupName, Nom_liste,

    Sum ((a_cost/1000) * degradation * quantity * total_count * index) such as total_cost,.

    FROM MyTable

    having sum ((a_cost/1000) * degradation * quantity * total_count * index) <> 0

    Group GroupName, Nom_liste

    Having done so the query to run more slowly.

    How can I filter records with zero total_cost (they can be negative or greater than zero).

    Thank you!

    The query you posted should not take more time with or without the HAVING clause.  The right of the comma before 'from' causes a compilation error very quickly anyway.

    If you get no result other than an error message, then this is not the code you are running.  Show the code you actually run, or a simplified version that has the same problem.

    For all performance issues, see the FAQ forum:

    https://community.Oracle.com/message/9362003#9362003

    If the problem was really in the HAVING clause, then you can try something like this:

    WITH got_total_cost AS
    (
    SELECT GroupName, Nom_liste
    , SUM ((a_cost/1000) * degradation * quantity * total_count * index) SUCH as total_cost
    FROM MyTable
    GROUP BY GroupName, Nom_liste
    )
    SELECT *.
    OF got_total_cost
    WHERE as total_cost <> 0
    ;

    but it would be very surprising he made all the difference.  I suspect that the problem is not really in the HAVING clause.

  • I installed creative cloud for Lightroom 6 trial and now my computer runs like an old lady of 90 with a market framework. It is clear, he can not cope, and I need to buy a new computer. How can I transfer the case to the computer again that I don't have

    I installed creative cloud for Lightroom 6 trial and now my computer runs like an old lady of 90 with a market framework. It is clear, he can not cope, and I need to buy a new computer. How can I transfer the case to the computer again that I did not yet?

    Please click the link for photography Software Digital | Free download Adobe Photoshop Lightroom CC trial

    .

    I hope this helps.

  • INSERT the SEQ WITH the question of the Select clause

    Hello
    I have Insert statement that I want to use seq with the select clause, but does not please help in this...

    Insert in aaa (rowname, rowid, rowadd)
    aa_seq.nextval, empaddress, and Select empname from emp;
    Please, do not help to accommodate seq in the insert statement.
    Insert into aaa(rid,rowname,rowadd)
    select aa_seq.nextval, empname,empaddress from emp;
    

    Do not use as ROWID column name.

  • How can I transfer photos from my iPod touch 6th generation for my macbook pro WITHOUT using iCloud, please? It's simple with another camera but not the case, it seems, for the Apple iPod

    How can I transfer photos from my iPod touch 6th generation for my macbook pro WITHOUT using iCloud, please? It's simple with another camera but not the case, it seems, for the iPod Touch from Apple.

    Use import option from your Mac:

    Import photos and videos from your iPhone, iPad or iPod touch - Apple Support

Maybe you are looking for

  • When you try to install the updates, receive the error code 0000646

    What should I do to get the computer to install updates error code 0000646 * original title - when attempting to install updates to keep saying it failed and giving the code 0000646 so it never installs updates day but trys every stop *.

  • Restart the printer after a put a new disc of haard

    Printer does not have the test page.  Only printed black is not colored.  How can I check and restart the printer with the new hard drive. Anita laws

  • ApplicationManager and code signing

    I'm calling a MDS application from a java application. I had to order the keys and have signed the application, but I always get an error no matter where I try to call ApplicationManager. ApplicationManger.getApplicationManager().launch(TheMDSApp); I

  • I have a problem with the connection of the laptop with the LCD.

    I'm trying to connect my laptop with a cable adapter VGA - HDMI to a LCD to watch my PC to TV programs but I don't get the window to duplicate the monitor and apply the correct resolution.  How can I solve this?

  • How to display the javascript error in the Simulator?

    Hi, I have experience several problem in developing countries using webwork. I use Blackberry webwork in plugin eclipse to develop the program, my Simulator is 9800 6.0.0.337. I have the problem when I try to load his PIN and file reading / writing.