How to write efficient code in pl/sql using case

Hi all

For all variables specified in the procedure, I have to do if the conditions as... one you suggest effective way of coding using case...





Thank you / kumar

Published by: kumar73 on August 17, 2010 05:56

Published by: kumar73 on August 17, 2010 05:58

Published by: kumar73 on August 17, 2010 09:55

Hello

Sorry, I don't know of anyway to avoid making all these instructions IF, or their equivalents.
You can make the code easier to write, debug and maintain by putting common code in a function, like this:

CREATE OR REPLACE FUNCTION  zero_out (in_num     IN     NUMBER)
RETURN       NUMBER
DETERMINISTIC
IS
BEGIN
     IF  in_num  NOT IN (-8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9)
     THEN
          RETURN  in_num;
     ELSE
          RETURN  0;
     END IF;
END     zero_out;

See below for an example of how to call it.
Note that there is no point in trying to "in_num IS NULL"; the expression NOT IN never returns TRUE if in_inum is NULL.
This will probably not everything faster than you do now, but it will probably not significantly slower, either.

If you want to make the procedure faster, try to use the COLLECTION in BULK.
Combine loops nested one. If you set the slider as

...     CURSOR  finc_csr
     IS     SELECT     finc.*
          FROM     pqr.finc
          JOIN     abc.fmly     ON     finc.famid     = fmly.famid;

then you can use it like this:

...     FOR  rec  IN  finc_csr
     LOOP
          v_temp_unemplx   := zero_out (rec.unemplx);
          v_temp_unemplbx  := zero_out (rec.unemplbx);
          v_temp_compsensx := zero_out (rec.compsensx);
          ...
     END LOOP;

Tags: Database

Similar Questions

  • I am a newbie to this and I was wondering how to write CSS Code for text, text color, size text and text effects...

    Please keep in mind that I am a newbie. For the moment, I don't know how to write code, so I use Muse to try to build a Web site that is not super fancy writing know, then improve or build or create a new site later. I called Adobe and they said someone in the forums may know how to write code and that he could help me. That said, if someone could answer my questions and help me somehow, I'd be really grateful.

    1. How can I write code, what code should I write to

    Text?

    Color of the text?

    Text size?

    Text/Font Style

    Text effects (such as fly in or fly out, bounce in and out bounce, spin in and spin out, fade in and fade out, etc)?

    Direction of text effect?

    Time that the effect occurs, if it is applied, initiated, comes in? example fly in or fade?

    Time than the last.

    After the effect stops, turns off? example: fly away or fade out?

    2. how to enter the code Muse?

    3. should I have a program to write the code?

    4. is there a function I could use on my computer, such as Notepad, to write the code, copy and paste it into Muse?

    5. What is the best book or books to learn how to write css, code and everything I need to do to be able to do the above and more?

    6. is there anything else I need to know or do to be able to do these things with the text?

    You can find more information on the style of your text (paragraphs, titles, etc. in some of the tutorials here: TUTORIALS |) Adobe Muse CC

    You can also check out tutorials on this page for scrolling effects that can do some of the other effects you need. Without exactly knowing your use case it's hard to give specific advice.

    Basically if it is not covered undressed under the text, scrolling Effects tutorials or in a third party widget already made, then you will need to create it yourself using CSS. You will need to use some sort of browser Firebug like developer tools in Firefox to find the ID of the element you want to add the CSS to write the CSS code and insert it into the head section of the page properties.

  • How to write VBA code that is compatible DEP

    Hello

    We have a number of VBA macros, Excel. Some users report an error

    After some research, I believe that it is related to the Microsoft Data execution prevention feature. I presume our adds that something that does not like the DEP. Is there a guide on how to write/re-write macros to avoid problems with DEP?

    Thank you

    Emmet

    This issue is beyond the scope of this site and must be placed on Technet or MSDN

    http://social.technet.Microsoft.com/forums/en-us/home

    http://social.msdn.Microsoft.com/forums/en-us/home

  • How to write the result of a SQL query to a text file?

    I'm using Oracle 11 g and SQL Plus.

    I have a large table called side.

    Whenever I do


    SQL > select * rating.

    The output goes well beyond what can show the screen sqlplus. So, I want to store the result of this query in a text file.

    How is that possible? Help, please. Thank you.

    SQL > SPOOL results.txt
    SQL > select * rating.
    SQL > SPOOL OFF

  • How to write a letter and print it using Windows XP

    How to activate the programs that will allow me to write and print letters

    Windows comes with several.

    How to use wordpad: http://www.ehow.com/how_5726466_use-xp-basic-word-processing.html (after's done it, make sure that a printer is connected to your PC, then open the document and press Ctrl + P on your keyboard and click OK to print the file)

    Office Online (free, online version of MS Office): http://office.microsoft.com/en-us/web-apps

  • How do write an image bank 2d images using maton indexing or other type of indexation. Please help me, I'm stuck my project with this problem?

    Dear friends,

    I'm in a phase of my project of mtech evil. How can make a large image 2d draws from small images by indexing. (just like arrays\matrix, etc.). I have only 16 small images in my library. I want to do the big picture of mosaic of smaller images with appropriate indexing. I think to make a large image in Formate of table 2d (100 * 100 images) of small images using indexing. Anyone CAN HELP me IT WILL REALLY appreciable

    URS faithfully

    Ragil

    The question is more how you want that they be indexed like that?

    1 > 2 > 3 >... > 15 > 16 > 1 > 2...

    5>6>......

    or

    1 > 2 > 3 > 4 > 5

    2 > 3 > 4 > 5

    3 > 4 > 5

    4 > 5

    5

    or another type of indexing

  • How to get the code PIN Blackberry 10 using javascript for BB10 Webworks App?

    Hi all

    I have developed web application for blackberry 10 using the emulator to ripple and Blackberry 10 Webworks SDK 1.0.4.11.Here I put the automatic connection of my web application... So I want to get the Pin 10 of Blackberry number using javascript... Please help me... Someone knows... Thank you very much...

    Kind regards

    Marimuthu_P

    Which is documented here for WebWorks 2.0: https://developer.blackberry.com/html5/apis/beta/blackberry.identity.html#jbo1385148789774

    and here for WebWorks 1.0:

    https://developer.BlackBerry.com/HTML5/APIs/gold/BlackBerry.identity.html

    You want the uuid property.

  • SQL using CASE

    Select * from EMP_TEST;

    EMPNO, ENAME EMPSTATUS EMPDELFLAG

    1 a 0 model
    2 Perm 0 B
    3 c model 1
    4 d, Perm 1

    How to get data based on Empstatus and Empdelflag.

    Condition is then

    1: EMPDELFLAG = 0 and EMPSTATUS = dummy or Perm.
    2: EMPDELFLAG = 1 and EMPSTATUS = Perm can view EMPNO 1,2 and 4.

    On the other
    3: EMPDELFLAG = 1 and EMPSTATUS = dummy can display 3 EMPNO.

    I wanted to do this by using SQL, but I am not able to do. Please help me on this. Can it be done using the condition of the case?

    Select * from version of v$.

    BANNER

    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE Production 11.2.0.2.0
    AMT for IBM/AIX RISC System/6000: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    Hello

    583003 wrote:
    Hi Frank,.

    I'm sorry that I haven't posted Create Table and its insert statement.

    CREATE TABLE ITPCS. EMP_TEST...

    Thank you.
    Not everyone who wants to help you have a schema called ITPCS. Simply omit the schema name.

    Don't forget to post the exact results you want from these sample data.

    To your question, I would like to display EMPNO = 3 when EMPDELFLAG = 1 and EMPSTATUS = DUMMY. In all other conditions, it should display EMPNO 1,2,4.
    Please suggest on this.

    Assuming that empdelflag and empstatus cannot be NULL:

    SELECT       *
    FROM       emp_test
    WHERE       (    empdelflag     = 1
           AND  empstatus     = 'Dummy'
           AND  empno          = 3
           )
    OR       (   (  empdelflag     != 1
               OR empstatus     != 'Dummy'
               )
           AND empno          IN (1, 2, 4)
           )
    ORDER BY  empno          -- If wanted
    ;
    

    If empdelflag or empstatus can be NULL, so it's a little more complicated, but only a little.

    The results I get are:

    EMPNO ENAME      EMPSTATUS  E
    ----- ---------- ---------- -
        1 A          Dummy      0
        2 B          Perm       0
        3 C          Dummy      1
        4 D          Perm       1
    

    in other words, the entire table.

    Those are the reuslt you want? If so, maybe a few different examples of data, that includes lines that should be excluded for reasons varipous, would provide a better test.

    If these aren't the desired results, post the correct results. In places where the above results are false, explain why you don't want every given line.

  • Re-write the code DOM node with SQL - XML funtions

    Hi friends,

    Could you please help to re - write the code using the following SQl - XML functions

    DECLARE

    l_domdoc dbms_xmldom. DOMDocument;

    l_xmltype XMLTYPE.

    l_root_node dbms_xmldom. DOMNode;

    l_departments_node dbms_xmldom. DOMNode;

    l_dept_element dbms_xmldom. DOMElement.

    l_dept_node dbms_xmldom. DOMNode;

    l_name_node dbms_xmldom. DOMNode;

    l_name_textnode dbms_xmldom. DOMNode;

    l_location_node dbms_xmldom. DOMNode;

    l_location_textnode dbms_xmldom. DOMNode;

    l_employees_node dbms_xmldom. DOMNode;

    l_emp_element dbms_xmldom. DOMElement.

    l_emp_node dbms_xmldom. DOMNode;

    l_emp_first_name_node dbms_xmldom. DOMNode;

    l_emp_first_name_textnode dbms_xmldom. DOMNode;

    l_emp_last_name_node dbms_xmldom. DOMNode;

    l_emp_last_name_textnode dbms_xmldom. DOMNode;

    BEGIN

    -Create an empty XML document

    l_domdoc: = dbms_xmldom.newDomDocument;

    -Create a root node

    l_root_node: = dbms_xmldom.makeNode (l_domdoc);

    -Create a new node departments and add it to the root node

    l_departments_node: = dbms_xmldom.appendChild (l_root_node

    , dbms_xmldom.makeNode (dbms_xmldom.createElement (l_domdoc, 'Deptartments'))

    );

    FOR r_dept IN (SELECT dept.department_id

    dept.department_name

    loc.city

    SERVICE dept

    JOIN the loc site

    ON loc.location_id = dept.location_id

    WHERE dept.department_id IN (10.20)

    )

    LOOP

    -For each folder, create a new item Dept with the service as an attribute ID.

    - and add this new Dept element in the node of departments

    l_dept_element: = dbms_xmldom.createElement (l_domdoc, "Dept");

    dbms_xmldom.SetAttribute (l_dept_element, 'Deptno', r_dept. Department_id);

    l_dept_node: = dbms_xmldom.appendChild (l_departments_node

    dbms_xmldom.makeNode (l_dept_element)

    );

    -Each node Dept will get a node names that contains the name of the service as a text

    l_name_node: = dbms_xmldom.appendChild (l_dept_node

    , dbms_xmldom.makeNode (dbms_xmldom.createElement (l_domdoc, 'Name'))

    );

    l_name_textnode: = dbms_xmldom.appendChild (l_name_node

    dbms_xmldom.makeNode (dbms_xmldom.createTextNode (l_domdoc, r_dept.department_name))

    );

    -Each node Dept will also get a node to the location that contains the location (city) in the form of text

    l_location_node: = dbms_xmldom.appendChild (l_dept_node

    , dbms_xmldom.makeNode (dbms_xmldom.createElement (l_domdoc, 'Location'))

    );

    l_location_textnode: = dbms_xmldom.appendChild (l_location_node

    dbms_xmldom.makeNode (dbms_xmldom.createTextNode (l_domdoc, r_dept.city))

    );

    -For each Department, add a node of employees

    l_employees_node: = dbms_xmldom.appendChild (l_dept_node

    , dbms_xmldom.makeNode (dbms_xmldom.createElement (l_domdoc, 'Employees'))

    );

    FOR r_emp IN (SELECT employee_id

    first name

    last_name

    Employees

    WHERE department_id = r_dept.department_id

    )

    LOOP

    -For each folder, create a new item Emp with the employee as an attribute ID.

    - and add this new element of the Emp to the employees node

    l_emp_element: = dbms_xmldom.createElement (l_domdoc, 'Emp');

    dbms_xmldom.SetAttribute (l_emp_element, "empid", r_emp.employee_id);

    l_emp_node: = dbms_xmldom.appendChild (l_employees_node

    dbms_xmldom.makeNode (l_emp_element)

    );

    -Each node emp will get a first name and a last name node that contains the first name and the last name text

    l_emp_first_name_node: = dbms_xmldom.appendChild (l_emp_node

    , dbms_xmldom.makeNode (dbms_xmldom.createElement (l_domdoc, "FirstName"))

    );

    l_emp_first_name_textnode: = dbms_xmldom.appendChild (l_emp_first_name_node

    dbms_xmldom.makeNode (dbms_xmldom.createTextNode (l_domdoc, r_emp.first_name))

    );

    l_emp_last_name_node: = dbms_xmldom.appendChild (l_emp_node

    , dbms_xmldom.makeNode (dbms_xmldom.createElement (l_domdoc, "LastName"))

    );

    l_emp_last_name_textnode: = dbms_xmldom.appendChild (l_emp_last_name_node

    dbms_xmldom.makeNode (dbms_xmldom.createTextNode (l_domdoc, r_emp.last_name))

    );

    END LOOP;

    END LOOP;

    l_xmltype: = dbms_xmldom.getXmlType (l_domdoc);

    dbms_xmldom.freeDocument (l_domdoc);

    dbms_output.put_line (l_xmltype.getClobVal);

    END;

    /


    Thank you and best regards,

    Arun Thomas T

    It's as simple as that:

    SQL> select xmlserialize(document
      2           xmlelement("Departments"
      3           , xmlagg(
      4               xmlelement("Dept"
      5               , xmlattributes(d.department_id as "Deptno")
      6               , xmlforest(
      7                   d.department_name as "Name"
      8                 , l.city as "Location"
      9                 )
     10               , xmlelement("Employees"
     11                 , (
     12                     select xmlagg(
     13                              xmlelement("Emp"
     14                              , xmlattributes(e.employee_id as "empid")
     15                              , xmlforest(
     16                                  e.first_name as "FirstName"
     17                                , e.last_name as "LastName"
     18                                )
     19                              )
     20                            )
     21                     from hr.employees e
     22                     where e.department_id = d.department_id
     23                   )
     24                 )
     25               )
     26             )
     27           )
     28           indent
     29         )
     30  from hr.departments d
     31       join hr.locations l on l.location_id = d.location_id
     32  where d.department_id in (10,20) ;
    
    XMLSERIALIZE(DOCUMENTXMLELEMEN
    --------------------------------------------------------------------------------
    
      
        Administration
        Seattle
        
          
            Jennifer
            Whalen
          
        
      
      
        Marketing
        Toronto
        
          
            Michael
            Hartstein
          
          
            Pat
            Fay
          
        
      
    
    
  • How to write the SQL without using dynamic SQL?

    How can you write this under SQL without using execute immediately?

    You can use static SQL (using something like a CASE statement)?

    test procedure (one in varchar2, b number, each number) is

    v_num_recs pls_integer;

    Start

    Select count (*)

    in v_num

    FROM table1

    where

    col1 = one and

    If b is not null then col2 = b

    If c is not null then col3 = c;

    / * i.e. If b is not null, where condition to add this line only. If c is not null, where condition should add only this line. OR condition No. it * /.

    dbms_output.put_line (v_num);

    end;

    Or should I use dynamic SQL statements for this?

    I was wondering if the two are NOT NULL? Well check this.

    Select count (*) in v_num

    table

    where col1 = one

    and col2 = (CASE WHEN (b is not null) THEN b ELSE END col2)

    and col3 = (CASE WHEN (c is not null) THEN ELSE END col3 c)

  • How a BUTTON can execute some PL/SQL code?

    Hello

    I m new on APEX and I would like to know how can I do a button APEX run an anonymous code from PL/SQL to a page of the region.

    Best regards

    Sergio

    Just create a button named, submit.

    Then, create a process Page
    Category PL/SQL
    Enter a name for your Page process
    Sequence Determines when the process starts
    Point Present on - after calculations and Vailidations
    Type Anonymous PL/SQL block
    Enter the process of PL/SQL Page Paste here your PL/SQL code
    Success message Enter a message to display if necessary
    When you press the button Click the button that you created
    Create processes

    Jeff

  • How to write a function to estimate the number of rows returned SQL?

    How to write a function to estimate the number of rows returned SQL through SQL Execution Plan?
    My idea is
    Call dbms_sql.parse to create the SQL PLAN, then ask the PLAN for the number of estimated return lines.
    But how to get SQL plan through "id cursor?
    Thank you.

    You can use EXECUTE IMMEDIATE to explain plan statement. About the STATEMENT_ID generation, it could be anything. Even a SYSTIMESTAMP cast as TANK would work.

  • How to call external C/java code in pl/sql or sql?

    Mr President

    I'm a newbie, but I want to know how to call the external C/java code in pl/sql or sql?

    Embedded SQL to Oracle environment is called Pro * C.

  • How to write expressions/rules/SQL workflow

    Hi all.

    We are recent users of CRM onDemand, we would write a few workflow rules, but can't seem to find all the information on how to do it. The help section is limited in the responses, and some of the issues here are not as specific in what we do.

    Someone has any advice on books, websites, etc. on where to find the knowledge we need on how to write workflow rules and the use of SQL and expressions in CRM on Demand?

    Thanks in advance!

    For your first case:
    1. you cannot create a workflow in r15 for activity but you can in R16

    Create new to create a workflow
    Name: Auto email send
    registration type: activity
    trigger: when the new record
    rules: put your rules by clicking the fx icon IE this is where you enter the rule by saying that the owner is different from the person who creates the activity or the delegate field is filled (another way of seeing things)
    then save the workflow

    In the section actions
    Choose the action 'create e-mail notifications '.
    In the: Section choose "Registration of the user on Relative" and "owner of the activity.

    Save it. Make sure that the activity and workflow are marked active.

    2. in the second scenario:
    How do you create an account and to automatically fill in the name of the sales of the sale - don't know
    But you can create a fill of opportunity and self with the name of the owner of the account using this validation in the field (you need not the workflow), you can use the FieldValueJoin function.

    Hope this helps - btb there's no book you can go thro the help and you will find some directions

  • Question 1: How do I add or use jQuery in folder level Adobe Javascript.  Question 2: How to write normal Javascript in file level Adobe Javascript ie., getElementbyid etc...  Please find the below code that shows what I am referring

    Here's my level Javascript file, which comes as a Pop up when I click on a created custom button in a PDF reader on your...

    I created a Test.js file and then pasted the code below into it. Then I copy paste this file in the following path: C:\Program Files (x 86) \Adobe\Acrobat 11.0\Acrobat\JavaScripts

    Now I want to know How to add jQuery Code or the Normal Javascript in the code below. Please give an example.

    Note: I do not use forms Javascript here. It is an ACROJS Javascript folder.

    Beginning of the Code

    app.addMenuItem ({cName: "PERSONAL INFORMATION", cParent: "File", cExec: "helloWorld()"});

    helloWorld = app.trustedFunction (function () {var

    app.beginPriv ();

    Dialog1 var = {}

    Description:

    {

    elements:

    [

    {

    type: "cluster."

    name: "invisible."

    align_children: 'align_left,

    elements:

    [

    {

    type: 'static_text. "

    name: 'First Name '.

    },

    {

    type: 'edit_text. "

    alignment: "align_fill",.

    Width: 300,

    height: 20

    }

    ]

    },

    {

    alignment: 'align_left,

    type: "ok_cancel."

    ok_name: "Ok."

    cancel_name: "Cancel".

    }

    ]

    }

    };

    app.execDialog (dialog1);

    app.endPriv ();

    });

    End of the Code

    Let's take a step back and understand what is 'normal' JavaScript. Normal to you probably means browser based, but it is only your point of reference. Any implementation of JavaScript includes at least the core JavaScript language, and that's what you have in the two Acrobat JavaScript, but also browser JavaScript. Things like the JavaScript syntax are dealt with in this part of the language, how are managed types (numbers, strings, arrays, classes,...), but also a number of items of library like for example the Date object. In addition to this basic language, almost all JavaScript implementations have a second part, which is the specific application. In the browser, you deal with HTML and windows and other things that have no meaning in the browser environment. In Acrobat, you work with PDF documents, annotations, form fields and more. The specific web browser Javascript is no more or less 'normal' that the implementation in Acrobat. It takes some getting used to a different environment, and what is the Acrobat JavaScript API reference. You will find all the specific objects in Acrobat and methods described in there. What makes things a little more difficult for you, is that you probably don't know corresponding to the line between the core language and browser-specific extensions, so you'll have some re-learning the language in front of you.

Maybe you are looking for