How to use i for if condition in a for i in loop?

Hi friends,
I have a question on how to use i for IF condition in a loop, in order to get an efficient programming and results. Here is outlined SQL:
cursor is
select c1,c2,c3 from table1; -- 100 rows returned.
open cursor
loop
fetch c1,c2,c3 into v1,v2,v3;
for i in 1..3 loop
if 'v'||i between 90 and 100 then
v_grade := 'Excellent';
elsif 'v'||i between 80 and 89 then
elsif 'v'||i between 50 and 59 then
end if;
end loop;
close cursor;
This way, I don't need to use a lot of if..then for hard code v1,v2,v3,.... actually I have more v..
But Oracle gave an error of this usage of 'if 'v'||i' or 'v'||to_char(i).
Thanks for any advice in advance!

user508774 wrote:
Thanks for comments and advices. But I didn't get your inputs clearly. Are you saying I don't need to use PL/SQL to achieve this?Correct. Ronel and John showed you the basic approaches. SQL is not a mere I/O language for making read and write calls. It is a very capable, flexible and powerful language. One can solve a problem with a few lines of SQL code, that will take 100's of lines of PL/SQL or Java code.
So do not underestimate what can be done in SQL.
v_cmd := 'UPDATE parts_categ_counts SET w1='||v1||', w2='||v2||...||v9||' WHERE seq='||vseq||';
EXECUTE IMMEDIATE v_cmd;This code is also wrong. Besides the fact that there is no need for dynamic SQL, this approach creates a brand new SQL statement each loop iteration.
SQL is source code. It needs to be parsed (compiled). The end result is an executable program that is called a cursor. This cursor needs to be stored in server memory (the SQL Shared Pool in the SGA).
The problem with your code is that it is slow and expensive - it generates lots of unique SQL statements that need CPU for parsing and server memory for storage.
These add up to a very significant performance overhead. That is the wrong approach. The correct approach is the same one that you would use in any other programming language.
Let's say you need to use Java to process a bunch of CSV files - exact same CSV layout used by each file. A file needs to be read, processed, and a log file created.
Will you write a Java program that loops through the files, for each file found, write a Java program for processing that file, compile it, then execute it?
Or would you write a Java program that takes the name of the file as input, and then process that file and writes the log file?
The 2nd approach provides a program that can process any of those CSV files - one simply needs to pass the filename as an input parameter.
Your code and approach use the 1st method. Not the 2nd. And that is why it is wrong.
To create a SQL program with parameters is done by using bind variables. Instead of
v_cmd := 'UPDATE parts_categ_counts SET w1='||v1||', w2='||v2||...||v9||' WHERE seq='||vseq||';
The following SQL source code should be created:
v_cmd := 'UPDATE parts_categ_counts SET w1=:v1, w2=:v2 ..., w9=:v9 WHERE seq= :vseq';
The tokens with the colon prefix (such as :v1), are bind variables. Think of these as the parameters to the SQL cursor.
The server parses this SQL into a cursor. You can now execute the same cursor over and over again, using different bind variables. (just like the 2nd approach above that one would use in Java)
In PL/SQL, this is made even easier as you can code native SQL code with PL/SQL code and use PL/SQL variables in it. The PL/SQL compiler is clever enough to do the SQL parsing, variable binding, and cursor execution for you. So in PL/SQL, you would use:
UPDATE parts_categ_counts SET w1=v1, w2=v2 ..., w9=v9 WHERE seq= vseq;
Where v1 and the others are PL/SQL variables.
That all said - PL/SQL is only used for data crunching, when the processing of data is too complex for the SQL language to deal with. And this is very seldom the case.
The main reason for using PL/SQL it to provide processing flow control, conditional processing and error handling, for SQL code. As the SQL language does not have these features.

Similar Messages

  • How to use complex function as condition in Oracle Rule Decision Table?

    How to use complex function as condition in Oracle Rule Decision Table?
    We want to compare an incoming date range with the date defined in the rules. This date comparison is based on the input date in the fact & the date as defined for each rule. Can this be done in a decision table?

    I see a couple of problems here.
    First, what you posted below is not a syntactically valid query. It seems to be part of a larger query, specifically, this looks to be only the GROUP BY clause of a query.
    Prabu ammaiappan wrote:
    Hi,
    I Have a group function in the Query. Below is the Query i have used it,
    GROUP BY S.FREIGHTCLASS,
    R.CONTAINERKEY,
    S.SKU,
    S.DESCR ||S.DESCRIPTION2,
    S.PVTYPE,
    RD.LOTTABLE06,
    R.WAREHOUSEREFERENCE,
    RD.TOLOC,
    R.ADDWHO,
    R.TYPE,
    S.CWFLAG,
    S.STDNETWGT,
    S.ORDERUOM,
    R.ADDDATE,
    C.DESCRIPTION,
    (CASE WHEN P.POKEY LIKE '%PUR%' THEN 'NULL' ELSE to_char(P.PODATE,'dd/mm/yyyy') END),
    NVL((CASE WHEN R.ADDWHO='BOOMI' THEN RDD.SUPPLIERNAME END),SS.COMPANY),
    RDD.BRAND,
    S.NAPA,
    RD.RECEIPTKEY,
    R.SUSR4,
    P.POKEY,
    RDD.SUSR1,
    r.STATUS, DECODE(RDD.SUSR2,' ',0,'',0,RDD.SUSR2),
    rd.SUSR3Second, the answer to your primary question, "How do I add a predicate with with a MAX() function to my where clause?" is that you don't. As you discovered, if you attempt to do so, you'll find it doesn't work. If you stop and think about how SQL is processed, it should make sense to you why the SQL is not valid.
    If you want to apply a filter condition such as:
    trunc(max(RD.DATERECEIVED)) BETWEEN TO_DATE('01/08/2011','DD/MM/YYYY') AND TO_DATE('01/08/2011','DD/MM/YYYY')you should do it in a HAVING clause, not a where clause:
    select ....
      from ....
    where ....
    group by ....
    having max(some_date) between this_date and that_date;Hope that helps,
    -Mark

  • HOW TO USE LOGICAL AND OR CONDITION TOGETHER

    Please do not post subject in ALL CAPITALS
    Hi All there,
    How to use logical and or condition together
    I wanted to use logical AND OR condition together in where clause of Select Query.
    eg where xyz and or abc
    Regards
    Sagar
    Edited by: Matt on Mar 17, 2009 1:05 PM
    Edited by: Matt on Mar 17, 2009 1:05 PM

    hi,
      You cannot use the logical and  or condition together at the same time in SQL statement. Sachin is correct while using the and and or in the same condition. You can get the data using or condition in SQL statement, and then use the delete statement of internal table using the end condition. please find the following code for the same.
    select *
      from dtab
    where cond1 eq 'A1'
         or cond2 eq 'A2'.
    if sy-subrc eq 0.
      delete itab where cond1 eq 'A1' and 'A2'.
    endif.
    regards,
    Veeresh

  • How to use the selection profile and status profile for production order?

    Hi expert,
       I want to know how to use the selection profile and status profile for production order. what's the usage for these two selection profile and status profile ?
      Please help me.
      thanks in advance.
      george.shi

    Hi George,
    There are are two types of statuses.One is system status and second one is user status.These statuses will tell us current situation of an order.
    We can't change system statuses.But we can create our own statuses through status profile.With this profile we can control user statuses.
    In this status profile,
    1.We define the sequence in which user statuses can be activated,
    2.We define initial statuses
    3. Allow or prohibit certain business transactions.
    Selection profiles are used to select the objects (say production orders) with different status combinations.We assign status profiles to selection profiles in BS42 T-Code.
    Regards,
    Raja.
    Edited by: Rajarao on Oct 30, 2008 6:21 AM
    Edited by: Rajarao on Oct 30, 2008 6:22 AM

  • How to use AND,OR,NOT condition in Pattern Matching in java

    how to use AND,OR,NOT condition in Pattern Matching in java
    Please anyone give example..

    Stop asking these stupid vague questions and do some of your own research.
    Start here:
    http://www.regular-expressions.info/
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html

  • How to use BAPI to add a new version for a claim number in WTY transaction.

    How to use BAPI to add a new version for a claim number in WTY transaction.
    I am using  function module " BAPI_WARRANTYCLAIM_ADD_VERSION ".
    It needs to copy all contents of previous version to a new version.
    While doing so i am unable to copy fields like valic valoc etc. Any ways by which  i can copy this values.
    WTY will update PNWTYH , PNWTYV and PVWTY tables.
    Thanking you,
    Lokesh.

    Hi Vishnu,
    You can do that through EEWB. Please go through SAP Note 484597. You would get the details of using Easy Enhancement Work bench.
    Rewards point if you think this info is useful
    Regards,
    Dipender Singh

  • HT1343 how to use the options with F10, F11, F11 for turning the sound up or down or mute?

    Hi, I'm Hannah. I'm using a Mac. Can you show me how to use the options with F10, F11, F12 for turning the sound up, or down or mute? Thank you very much

    Normally simply pressing them should do what you want, F10 to mute; F11 to decrease volume; F12 to increase volume. However, it's possible that you have a box ticked in Keyboard preferences which modifies the behaviour of the keys, requiring you to also hold down the Fn key (bottom left key on the keyboard) to enable the function.
    Check System Preferences>Keyboard to makes sure the box indicated in the image isn't ticked.

  • I got a software license crtificate ,how to use it??? i   paied    for it.

    I got a software license crtificate ,how to use it??? i   paied    for it.

    Which program, and where did you buy?
    Do you have a redemption code?
    Redemption Code http://helpx.adobe.com/x-productkb/global/redemption-code-help.html

  • [WebIntelligence Reporting] How to use count function with condition !?

    Post Author: xuanthuyit
    CA Forum: WebIntelligence Reporting
    Hi everyone,
    I want to make a report like this  with WebIntelligence reporting.
    I want to show the number of Outlet of each chanel (Horeca, Grocery, Convenience) at the end of report !
    But I don't know how to do that with WebIntelligence Reporting.
    Please help asap. . .
    Thank you verry much,

    Post Author: jsanzone
    CA Forum: WebIntelligence Reporting
    xuanthuyit:
    Apparently =count() [and use of a where] was permissible in previous versions of BusObjects, however, things in XI are different (as other users tell me, being XI is my first experience w/ BusObj...), so anyhow, here is the solution to your question.
    You will have have to create two variables for each condition you have.  One variable will be the "helper" and the other variable will be the "worker".  For instance, create a variable called channel_x and the formula:  =if(channel="haney";<metric>;0)  (where "haney" is the name of your organization and <metric> is the metric you are using to count or sum things in your report).  Once channel_x is saved create another variable called channel_x_count and the formula:  =sum(&#91;channel_x&#93;).  Once channel_x_count is saved, then on your report towards the bottom you can use the Template bar to drag in a new table (perhaps you want to use the Horizontal Table type), and then you can drag channel_x_count into your new table.  You will have to repeat the creations of more channel_x type variables (maybe call it channel_y and channel_y_count) or something more descriptive, but in any case substitute the "haney" constant for the next store you want to track, etc, etc.

  • How to use a subreport field as selection criteria for the main report

    Dear All,
       I created a report with one subreport and im comparing information from both reports but i need to apply selection criteria in the main report using one of the fields in the subreport, the problem is that the subreport field doesnt appear in the select expert screen. By any chance, someone knows how make a subreport field be used by the select expert.
    Thanks,
    Martha Medrano

    Dear Dom,
       I created the subreport table called IIM (748 items) in sql in the main report as you suggested with the below code:
    SELECT "IIM"."IPROD", "IIM"."IDESC", "IIM"."IID"
    FROM   "S102F360"."BPCS405CDF"."IIM" "IIM"
    WHERE   NOT ("IIM"."IDESC" LIKE 'GEN%' OR "IIM"."IDESC" LIKE 'OBS%') AND "IIM"."IID"<>'IZ' AND "IIM"."IPROD" LIKE '3%'
    and i have another table called ITEM_MASTER (3221 items):
    SELECT "ITEM_MASTER"."ITEM_ID", "ITEM_MASTER"."DESCRIPTION"
    FROM   "WHSPRO"."dbo"."ITEM_MASTER" "ITEM_MASTER"
    ORDER BY "ITEM_MASTER"."ITEM_ID"
    and im trying to display all items in the ITEM_MASTER table that are not in the IIM file but i haven't been able to accomplish this, i am using as primary the ITEM_MASTER table with 'Inner Join' as Join Type,  and '!=" as Link Type. Do you have any ideas on how can i display the requested items.
    Thanks for your help

  • How to use a collection type of bind variable for execute dynamic statement

    Hi,
    We have a case where we copy selective data from Schema A To Schema B in one oracle database. The copy is achieved by using
    execute immediate 'insert into '||target_schema||'.tablea select * from '||from_schema||'.table a where a.id in (select test_id from '||from_schema||'.table c);';
    This works fine it takes an average of 10 seconds to copy around 14 tables. We have a requirement to bring this time to 2 seconds. One observation has been the clause
    "select test_id from '||from_schema||'.table c" in the above sql statement repeats for many inserts . Thus we were thinking to bulk fetch this set of tests ids and use a bind vatiable of collection type for the execute immediate clause. Any suggestions on how to achieve it?
    Thanks,
    Chandana

    >
    One observation has been the clause
    "select test_id from '||from_schema||'.table c" in the above sql statement repeats for many inserts
    >
    So what? Constructing a string for a table level insert and parsing it can't possibly be a performance problem. If you were creating a string in a loop to insert rows into a table by getting the data FROM a collection - that's a problem that keeps showing up in the forums.
    I'm with bravid and Nikolay on this one. First find out which side, select/insert, the problem is on.
    As they said you need to provide more information about the process.
    And using collections for your use case is definitely not the thing to do.
    1. How many rows are we talking about?
    2. Are the rows being inserted into an empty table?
    3. Are you running these queries during peak production hours or in a batch windows?
    Tune the SELECT if the problem is on that side.
    Post an execution plan for the SELECT part of a query you think should run faster.
    SET SERVEROUTPUT ON
    SET AUTOTRACE TRACEONLY
    SQL> select * from emp;
    Execution Plan
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |    14 |   546 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| EMP  |    14 |   546 |     3   (0)| 00:00:01 |
    SQL>On the INSERT side you might be able to use bulk inserts
    ALTER TABLE myTable NOLOGGING;
    INSERT /*+ append */ INTO myTable . . .
    ALTER TABLE myTable LOGGINGIf the insert tables are always reused you could just leave them as NOLOGGING. Since you can't recover bulk data you need to make sure to get a good backup after the loads if you need to recover the data from the logs rather than just reload it yourself.

  • How to use the update mechanism in Photoshop CS10 for Camera Raw?

    Good Evenning!
    I would like to open .NEF files with Adobe Photoshop CS10 (RAW for Nikon D5200) but my version of Camera Raw is too old.
    I need at least the 7.3 version.
    When I try to download it, I have this message: Please use the update mechanism in Photoshop CS10 for Camera Raw. But how?? When I go to "Help" tab, to "Updates", it says that no update available.
    Can please someone help me?
    Thanks a lot!!
    Kinds Regards
    Vanessa

    Which version of photoshop or photoshop elements are you using?
    Which operating system?
    There is no such version as cs10.
    Do you mean photoshop shop elements 10?
    If you go to Help>About Photoshop Elements (windows) or Photoshop Elements Editor>About Photoshop Elements (mac), that should tell you which version you have.

  • How to use the cell editor in FICO reports for YTD

    HI experts,
    I am working with BI7.0, in the below report, i have displayed result based on user input.but how to calculate the YTD values. User will give the input like 072007, results will be display one year from 072007 to 062006 (one yearback) and one more column is YTD
    Report structure is :
         user input(single value): 072007
              AUG06....JAN07....JULY07....YTD
    KEYFIGURE-1        453      -
    777     -
       232       -
      777 (Only Jan07 value of Keyfigure-1)   
    KEYFIGURE-2        879      -
    233        -
    123       -
      ???? (only sum from Jan07 to July07)
    KEYFIGURE-3        212            -
    879      -
    989                -
    KEYFIGURE-4        234            -
    656      -
    788                   -
    KEYFIGURE-5        345            -
    878      -
    878                 -
    KEYFIGURE-6        767            -
    767       -
    323                 -
    KEYFIGURE-7        879            -
    878     -
    999                -
    999 (Only last value of keyfigure-7 (July07)
    in the above report, total 7 keyfigures so 7rows of YTD column
    1) in the first YTD column, how will display only one value (keyfigure-1) of Jan07?
    2) in the last YTD Column, how will display only one value (keyfigure-7) of July07?
    3) from 2 to 6 columns of YTD, how will display the sum from Jan07 to July07?
    Note: months will be changed based on user input(single Value)
    how can use cell editor for above the senior.
    if any option is availabel please let me know
    Thanks
    kishore

    I think the following should work:
    Context:
    Rows (node,c=0:n)
    --- rowIndex (integer)
    selectedRowIndex (integer)
    Bind the "selectedKey" property of the radio button (cell editor) to attribute "selectedRowIndex" (outside table data source node) and bind "keyToSelect" to attribute "Rows.rowIndex". Make sure that the "rowIndex" attribute will contain the index of the node element in node "Rows".
    Armin

  • How to Use synchronous RFC calls during test run for remote accesses

    there is a Setting for the usage of RFC accesses from a tested system
    using eCATT.
    'X' - Use asynchronous RFC calls during test run for remote accesses
    ' ' - Use synchronous RFC calls during test run for remote accesses
    I developed an eCATT as following :
      SAPGUI ( SAPGUI_1 , Target_system_1 ).
      SAPGUI ( SAPGUI_2 , Target_system_2 ).
    My question is how to run the eCATT in a synchronous RFC calls
    PS: I do not want to change the Target_system to the same one in the
    above script of ecatt.Because I need to run it in 2 different Target
    systems sometime.
    for example, I give a Target_system_3 when run this eCATT
    I want the SAPGUI_1 and SAPGUI_2 run the Target_system_3 but not the
    Target_system_1 or Target_system_2 .
    Could you please tell me how to make it without the changes in script?
    Edited by: Weitong Liu on Mar 24, 2011 9:44 AM

    Hi Liu,
    Weitong Liu wrote:
    > ' ' - Use synchronous RFC calls during test run for remote accesses
    This is the standard option value. Asynchronous are not the standard way and used only for very special purposes.
    Weitong Liu wrote:
    > I developed an eCATT as following :
    >   SAPGUI ( SAPGUI_1 , Target_system_1 ).
    >   SAPGUI ( SAPGUI_2 , Target_system_2 ).
    > My question is how to run the eCATT in a synchronous RFC calls
    The commands will be executed in sequence. So each call will be synchronously replayed against TS1 and TS2.
    What is you issue with this standard procedure?
    Kind regards,
    Christoph

  • How to use more than one condition together?

    Dear,
    I want to set more than one condition type and use it together for any objects in page, for example page item,page button and etc.
    Is it possible to handle in "PL/SQL Experssion" at condition type?(e.g =>"Request= Expression" and "Current page!= Expression 1",..) if no is answer, please tell me other ways.
    Regards,
    Saeed.

    Hi Saeed,
    Saeed Hassanpour wrote:
    I'd like to know about CGI and Browsers conditions. Can I refer to document or essay about condition type in pl/sql?
        Yes, you can also refer CGI Environment Variables and Browser conditions in "PL/SQL Expression".
        For example :
    The condition type "When cgi_env SERVER_NAME = Expression 1" can be transformed to "PL/SQL Expression" as:
    OWA_UTIL.GET_CGI_ENV('SERVER_NAME') = 'MyServer'
    The condition type for Browser condtions can be can be transformed to "PL/SQL Expression" as:
    instr(upper(OWA_UTIL.GET_CGI_ENV('HTTP_USER_AGENT')),upper('Firefox/37.0')) > 0
        Following is old but comprehensive documentation about Condition Types:
        https://docs.oracle.com/cd/E14373_01/appdev.32/e11838/condition.htm#HTMDB25942
        Hope this helps!
    Regards,
    Kiran

Maybe you are looking for

  • How to Change Component on a SNP Planned Order ( Just 1 time )

    Hello, We are trying to change a component on a SNP Planned Order just 1 time. So we do not want to change the PDS since this is one time change only. We tried changing it in R/3. Once we do that, R/3 shows new component but APO still shows dependant

  • Assign ment of Parallel currencies  & Business Area related to cost center

    1.when we are creating cost center we will give business area,,,after posting to that business area,,can we change the business area??????? 2. whe1.Conducted power user, End –user training and involved for preparation of Business operating procedures

  • Job_queue_processes

    Hi friends I have a BD that it has created several jobs, 5 of which they execute themselves to 1:00am and the parameter job_queue_processes is 1. I see in DBA_JOBS view and apparently executes all jobs without problems and in simultaneous form. i don

  • Making Business Area required on KR KG RE

    How do we make the Business Area a required field on the HEADER field of the Financial and Logistic Invoices?

  • Wrong Posting Opposite Posting

    Hi Gurus, I would appreciate, if anyone could explain the meaning of Wrong Posting Opposite Posting in "Define Reason for Reversal".  Also, why do we choose Alt. Post Date for the same. Please explain Thanks Mohit