Can anyone tell me what this is doing

hey this is part of some parser code from an earlier java forum post
http://forum.java.sun.com/thread.jspa?threadID=506162&messageID=2399163#239 9163
i modified the code slightly to work with my program which involves its use in an applet and to solve logical equations. However i'm still uncertain as to what certain sections of the code are doing
i know that this code evaluates the variables within the given equation, begins a for loop that does not exit until i = codeSize which is the length of the given String. However i'm not so certain as to how it achieves this. I'd like to know
private int eval(int variableX, int variableY, int variableZ)
                try {
                        int top = 0;
                        for (int i = 0; i < codeSize; i++)
                                if (code[i] >= 0)
                                        stack[top++] = constants[code];
else if (code[i] >= POWER)
int y = stack[--top];
int x = stack[--top];
int ans = (int)Double.NaN;
switch (code[i])
case PLUS: ans = x | y; break;
case MINUS: ans = x & y; break;
case TIMES: ans = x & y; break;
case DIVIDE: ans = x / y; break;
// case POWER: ans = Math.pow(x,y); break;
if (Double.isNaN(ans))
return ans;
stack[top++] = ans;
else if (code[i] == VARIABLEX)
stack[top++] = variableX;
else if (code[i] == VARIABLEY)
stack[top++] = variableY;
else if(code[i] == VARIABLEZ)
stack[top++] = variableZ;
/* else {
double x = stack[--top];
double ans = Double.NaN;
int d;
d = (int) ans;
switch (code[i])
case SIN: ans = Math.sin(x); break;
case COS: ans = Math.cos(x); break;
case TAN: ans = Math.tan(x); break;
case COT: ans = Math.cos(x)/Math.sin(x); break;
case SEC: ans = 1.0/Math.cos(x); break;
case CSC: ans = 1.0/Math.sin(x); break;
case ARCSIN: if (Math.abs(x) <= 1.0) ans = Math.asin(x); break;
case ARCCOS: if (Math.abs(x) <= 1.0) ans = Math.acos(x); break;
case ARCTAN: ans = Math.atan(x); break;
case EXP: ans = Math.exp(x); break;
case LN: if (x > 0.0) ans = Math.log(x); break;
case LOG2: if (x > 0.0) ans = Math.log(x)/Math.log(2); break;
case LOG10: if (x > 0.0) ans = Math.log(x)/Math.log(10); break;
case ABS: ans = Math.abs(x); break;
case SQRT: if (x >= 0.0) ans = Math.sqrt(x); break;
case UNARYMINUS: ans = -x; break;
if (Double.isNaN(ans))
return d;
stack[top++] = d;
catch (Exception e)
double b = Double.NaN;
int i = (int)b;
return i;
} double d2;
if (Double.isInfinite(stack[0]))
d2 = Double.NaN;
int i2 = (int) d2;
return i2;
}else
return stack[0];
any help much appreciated
cheers
podger

Well this is a very basic interpreter. What this piece of code does is:
1) take an opcode from the code array, and retrieves the description for it from the constants array. This description is stored in the stack array.
stack[top++] = constants[code];
2) check what opcode it is
switch (code)
3) "execute" the opcode with simple java math operators.
case PLUS:    ans = x | y;  break;
case MINUS:   ans = x & y;  break;
case TIMES:   ans = x & y;  break;
case DIVIDE:  ans = x / y;  break;4) store the result of the opcode in the stack array, after the description of the opcode retrieved in step 1)
stack[top++] = ans;There is also some sort of error check in there: initially the result of the opcode is "NaN", (not a number). If the opcode passed to this code is not known, the result is not added to the stack according to this piece of code:
if (Double.isNaN(ans))
return ans;

Similar Messages

  • Can anyone tell me what this Time Machine error means? The network backup disk does not support the required AFP features?

    Can anyone tell me what this Time Machine error means? The network backup disk does not support the required AFP features?

    AFP - Apple Filing Protocol
    The Network Attached Storage (NAS) that you are pointing Time Machine at does not have the features needed by Time Machine in order to do its Thing.  Time Machine needs some specific features that are not typically available on generic networked storage devices.
    There are manufactures that support the Mac OS X HFS+ file system formats and implement all the needed AFP protocol packets necessary so that they can be used with Time Machine, but apparently yours does not.
    If you are not using a networked mounted volume for Time Machine, then more information will be needed about your Time Machine setup.

  • My imac will not load after I enter my password. The only thing I get is the arrow from my mouse on top of a blank white screen.  Can anyone tell me what this is?  I've restarted and turned off several times.  I left it on in this state for 8 hours and

    My imac will not load after I enter my password. The only thing I get is the arrow from my mouse on top of a blank white screen.  Can anyone tell me what this is?  I've restarted and turned off several times.  I left it on in this state for 8 hours hoping it would reload and work.  No luck.

    Hello KCC4ME,
    You may try booting your Mac in Safe Boot, as it can resolve many issues that may prevent a successful login.
    OS X: What is Safe Boot, Safe Mode?
    http://support.apple.com/kb/HT1564
    If a Safe Boot allows you to successfully log in, you may have issues with one or more login itmes (while the following article is labelled as a Mavericks article, it is viable for earlier versions of the Mac OS, as well).
    OS X Mavericks: If you think you have incompatible login items
    http://support.apple.com/kb/PH14201
    Cheers,
    Allen

  • Can you tell me what this code does?

    Can you tell me what this code does?
    import java.io.*;
    class Assignment1
    public static String[][] tdi = {     {"Paris", "418", "Rome", "55"},
                             {"Liverpool", "121", "Copenhagen", "35"},
                             {"Liverpool", "418", "Paris", "50"},
                             {"Liverpool", "553", "Frankfurt", "55"},
                             {"Frankfurt", "553", "Budapest", "50"},
                             {"Amsterdam", "121", "Madrid", "65"},
                             {"Amsterdam", "418", "Paris", "35"},
                             {"Madrid", "121", "Stockholm", "90"},
                             {"Budapest", "553", "Warsaw", "30"},
                             {"Copenhagen", "121", "Amsterdam", "35"},
                             {"Rome", "418", "Amsterdam", "60"},
    //--Start Method--
    public static void main( String args[] ) throws IOException
    System.out.println("Welcome to NoWings Airline.");
    InputStreamReader input = new InputStreamReader(System.in);
    BufferedReader keyboardInput = new BufferedReader(input);
    System.out.println("Please enter the airport you wish to depart from:");
    String[] info = TDIDLL.searchDest( keyboardInput.readLine() );
    if (info == null)
    System.out.println("Sorry, no plane to this destination");
    else
    System.out.println(info[0]+" departing at platform "+info[1]); }}
    public static String[] searchDest( String dest )
    String[] result = null;
    for(int i = 0; i < tdi.length; i++)
         if (tdi[1].equals(dest)) {
         result = new String[2];
         result[0] = tdi[i][0];
         result[1] = tdi[i][2];
         return result;
    return result; }
    // Info Method //
    // Fly Method //
    // Exit Method //
    Thanks. Also, can you tell me where I have gone wrong in the code.
    Much appreciated.

    Can you tell me what this code does?Why don't you run it and find out for yourself?

  • Can anyone tell me what this error means?

    Hi All
    The following error was encountered by a printer who has opened a supplied PDF in Acrobat, Saved it as a postscript and then run it through distiller server 6. Can anyone tell me what this error means and what sort of things can cause it?
    %%[ Error: syntaxerror; OffendingCommand: ! ]%%
    Stack:
    /PaintProc
    5.32031
    /YStep
    258.404
    /XStep
    [257.404 5.32031 258.404 5.32031]
    /BBox
    1
    /TilingType
    1
    /PaintType
    1
    /PatternType
    -mark-
    -mark-
    -mark-
    -save-
    %%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
    %%[ Warning: PostScript error. No PDF file produced. ] %%

    Something to do with software from wireless.umass.edu.

  • Can anyone tell me what this string is in the server permissions?

    Can anyone tell me what the character sting is third from the top?
    This is taken from the server app < select the server < storage < then edit permissions.
    I feel like this is something simple, but all of my searches have turned up nothing.
    Any insight would be greatly appreciated,
    -Tom

    I have recently deleted a user.
    Can I remove them from the ACL with no effect to the system?
    Is there a more efficient way to do that rather then by each individual folder and file?
    Thank you,
    -Tom

  • Can anyone tell me what this javascript is

    The following  script is at the top of  the code for my index page, can anyone tell me what it is for and can I deletye it.
    <script type="text/JavaScript">
        <!--
        function MM_preloadImages() { //v3.0
        var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
        function MM_findObj(n, d) { //v4.01
        var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
        if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
        for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
        if(!x && d.getElementById) x=d.getElementById(n); return x;
        function MM_nbGroup(event, grpName) { //v6.0
        var i,img,nbArr,args=MM_nbGroup.arguments;
        if (event == "init" && args.length > 2) {
        if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
        img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
        if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
        nbArr[nbArr.length] = img;
        for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
        } else if (event == "over") {
        document.MM_nbOver = nbArr = new Array();
        for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
        nbArr[nbArr.length] = img;
        } else if (event == "out" ) {
        for (i=0; i < document.MM_nbOver.length; i++) {
        img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
        } else if (event == "down") {
        nbArr = document[grpName];
        if (nbArr)
        for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
        document[grpName] = nbArr = new Array();
        for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
        nbArr[nbArr.length] = img;
        //-->
        </script>

    It's standard boilerplate javascript inserted by Dreamweaver when you add behaviors to your page. The block you posted contains three function definitions. The first covers preloading images (function MM_preloadImages), the second is what you need when an event in one place affects something in another (function MM_findOb) place on your page, and the third is for managing a group of checkboxes (function MM_nbGroup) I think!
    To say whether you could delete them or not, we would have to see the rest of your page to see if you are using any behaviors that might require those functions.

  • Can anyone tell me what this Error Code is??

    I just recently started having my computer go to sleep on me every so many seconds out of nowhere and i have tried everything i know of to fix it. I ran the apple hardware test and got this error..
    4mot/1/400000002: CPU-0
    can anybody tell me what this means?????

    Just FYI, a 4MOT error code indicates a problem with one of the fans. My guess is that the CPU fan has failed and the CPU is overheating. A trip to the Apple Store is definitely called for.
    Regards.

  • I have a bb curve and can not do check in on places in facebook can anyone tell me what i am doing wrong

    I can not get my check in of places to work on facebook what am i doing wrong??

    Hi
    probably nothing, except not providing enough information to enable a solution to be posted
    More information will be needed before making suggestions. Please provide as much as you are able of the the following
    Blackberry Model.
    Carrier Name.
    Do you have a Data Plan?
    Operating System Version go to Menu > Options > About - it looks like v5.0.0.681
    Memory for Device and SD Card Options > Memory
    Any error statement or code.
    The Exact nature of problem - the more info the better.
    When this started and whether it started just after an update or new App download and which App/s theme/s download.
    Blackberry Best Advice - Back-up weekly
    If I have helped you please check the "Kudos" star on the right >>>>

  • Can anyone tell me what this messsage means and how to fix it?

    I use CS3 to prepare a black and white newsletter for our village onmy MAC and frequently change colour photos to greyscale.  However when printing on my HP Colour Laserjet 2550L the photo shows as a dark green colour.  I've tried everything imaginable, new drivers etc. but still get the green print instead of greyscale. 
    The ColorSync Utility had just appeared on my desktop with the following message:
    Searching for profiles...
    Checking 54 profiles...
    /Library/ColorSync/Profiles/EW-sRGB
       Tag 'desc': Tag size is not correct. Could not be fixed.
    /Library/Application Support/Adobe/Color/Profiles/Recommended/CoatedFOGRA27.icc
       Tag 'desc': Tag size is not correct.
       The file is locked. Could not be fixed.
    Repair done - 0 out of 2 profiles fixed.
    Could this be the problem?  And if so, how do I fix it?
    Don't really want to uninstall and reinstall but expect that's the only answer.  Is it?  Can anyone help?

    The driver is one the Apple Mac store downloaded for me.
    I attach the print summary which might give a clue.  When converting 
    files to grayscale, I use Image>Mode>grayscale.  The other thing is 
    that I can't print in Photoshop, so I do all my editing in Photoshop 
    and print through Indesign.  Printing in Photoshop is just a page of 
    text.
    The other odd thing is that coloured pdf files printed in Adobe 
    Acrobat are just a mass of colour, no recognisable picture but if I 
    change the print option in Acrobat to print in grayscale I get 
    pictures!  I just feel I'm overlooking some checked option, but I've 
    tried to restore to default without success.  I used to use Pagemaker 
    6.0 to do my newsletter on my PC but had to change to Indesign when I 
    changed to MAC and the printer hasn't worked properly since!!!
    Many thanks for your reply.  Maybe someone out there might be able to 
    help.

  • I have recently upgraded to Yosemite and when launching PS I get error message 150:30.  Can anyone tell me what this means?

    I have recently upgraded to Yosemite and when trying to launch PS I get an error message 150:30.  Can anyone help me out with this please?

    Yes. The upgrade broke your CS4 install. You have to reinstall.
    Easiest way to fix this is to download the installer Download CS4 products and have your serial number at the ready.
    Then you will need to download and install the updates for Photoshop, Camera Raw, and Bridge here: Product updates
    There is a Terminal fix, but you have to be familiar with Terminal and running the python license Repair script. You will need the bash shell on your user account. If that makes sense to you, we can try that.
    Gene

  • Can anyone tell me what this is for?

    The link below is a picture. I need to know what the metal thing is that the black and red cords are wrapped around it almost looks like a Ferrite Bead but I'm not sure. The wire goes to the power jack. 
    http://i377.photobucket.com/albums/oo212/kraze1978/repair-damaged-power-jack-14.jpg
    [IMG]http://i377.photobucket.com/albums/oo212/kraze1978/repair-damaged-power-jack-14.jpg[/IMG]
    please help...thank you

    Shutting down only returns a Mac to a certain default running state.
    If the beach balling problem is there, it can and, most probably, will return.
    Sometimes a shut down or restart can reset things, but if this was something that was nagging issue, it may return.
    It's better for a Mac to sleep or hibernate than to constantly shut it down.
    Shutting down and starting up a computer all the time puts more strain on electronic components than just letting the computer sleep and go into a reduced power mode.
    Sometimes Safari ( or any web browser) can be the culprit as Adobe Flash Player, running inside Safari, can eat up a lot of CPU and RAM resources when on a website that needs extensive use of Adobe Flash Player.  Also, animations and pop- up ads in a web browser can have the web browser using up more CPU and RAM cycles, too! Other web browser factors like having a lot of windows or tabs active can increase the amount of RAM that the web browser is using.
    Also, it a good idea not to have too many CPU and RAM intensive apps running concurrently in the background.
    Also, some unknown process can eat up system resources.
    From time to time if the beach balling returns, launch Activity Monitor app inside your Applications>Utilities folder a see if there are any processes that are eating up an excessive amount of RAM or CPU cycles.
    Any antivirus apps are known causes of OS X slowdowns and beach balling as well as a lot of " crapware" like MacKeeper. Keep software like that off of your system.

  • Can anyone tell me what this "Kikin" popup is about?

    I've been getting this pop up for something called "Kikin" that says it's a browser update. If it's an update to my firefox browser, why is it coming in this way? It tells me to click update or upgrade now and that by clicking I agree to their terms and services. Well, I don't want to agree to the terms and services and I want it to just stop. How do I do that?

    I'm afraid that the answers from by TonyE and TheSchnaz were off the mark. I'm getting the kikin popup ad even though I don't have kikin installed. (It doesn't show up in the add-ons menu). Since I don't have kikin installed, I can't uninstall it. This sort of popup ad is the sort of thing that you usually see with trojans. I don't know if kikin is a trojan or not, but I certainly wouldn't trust it.
    Regardless, how do you block the pop up and any other software associated with kikin?

  • Struts - Can anyone tell me what this URL is doing??

    Hi
    In a Struts framework, we normally have a class being mapped in the action tag, for example, in the struts-config.xml, we can have the following
    <action-mappings>
    <action
    path="/mapping10"
    type="mypackage.MyMappingAction10"
    name="MappingForm10"
    scope="request"
    validate="false"
    input="/Error.jsp">
    <forward name="success" path="/MappingOut10.jsp" />
    </action>
    </action-mappings>
    that means, if we type something like
    http://...../mapping/maping10.do
    it would go to the MyMappingAction10 execute method and do whatever it's supposed to do.
    But the other day I come across a URL path which looks something like this....
    http://...../mypackage/route.logging.do
    I have been trying to figure out how/why it can get executed because normally, as you can see from the above example, it's only forward10.do (something.do) but in this case, it's route.logging.do (something.something.do) how can I actually find out what program (class) this actually maps to? How does this work??
    I understand that my information might not be sufficient, but I would still appreciate anyone could offer me some pointers to find out what's happening. Thx.
    Sheep

    From what you have given in the code, with struts the only place the requets to /mapping10.do can end up is MappingOut10.jsp.
    You are saying it ends up somewhere else?
    Easiest way to find it would be to do a global search through your code for the text "route.logging.do" It must be specified somewhere.
    It is possible your action is creating an ActionForward on the fly rather than using the one in the action mapping - so check the MyMappingAction10 class execute method to see what it returns, and where it gets that return value from.
    Is there a global actionForward defined for the route.logging maybe?
    Hope this helps,
    evnafets

  • Can anyone pls explain what this procedure does?

    i could only figure out that it will be performing a transpose.
    create or replace
    PROCEDURE TEST_TRANSPOSE(o_test OUT SYS_REFCURSOR) AS
    report_exists number(3);
    report_name varchar(30) := 'REPORT_TBL' ;
    query_main varchar(16000) := 'create table ' || report_name || ' as select MAGAZINE ' ;
    query_part varchar(1024) ;
    my_var varchar2(5);
    cursor cur_region is select distinct REGION from MAIN_TBL order by region;
    begin
    select count(*) into report_exists
    from tab
    where tname = report_name;
    if ( report_exists = 1 ) then
    execute immediate 'drop table ' || report_name ;
    end if;
    open cur_region ;
    loop
    fetch cur_region into my_var ;
    exit when cur_region%NOTFOUND;
    query_part := 'select nvl(sum(quantity),0) from MAIN_TBL x where x.magazine = main.magazine and x.region='''||my_var||'''' ;
    query_main := query_main || chr(10) || ',(' || query_part || ')"' || my_var || '"';
    end loop;
    close cur_region ;
    query_main := query_main || ' from (select distinct MAGAZINE from MAIN_TBL ) main' ;
    DBMS_OUTPUT.PUT_LINE(query_main);
    --execute immediate query_main ;
    open o_test for query_main;
    end;
    {code}
    i need to transpose  a table which has dynamic number of rows.This was what i tried.Could you pls bhelp me out to correct this i get "P_TRAN_YEAR" invalid identifier
    [code]
    create or replace
    PROCEDURE         PRM_R_MAT_RPT (p_EmpID     IN  Integer,
    P_TRAN_YEAR IN NUMBER,
    P_TRAN_MONTH IN NUMBER,O_rc OUT sys_refcursor) IS
    v_cnt NUMBER;
    v_sql VARCHAR2(32767);
    v_basic Number(16, 4);
    BEGIN
    select PPH_ORG_AMOUNT into v_basic from prm_p_hop
    where pph_emp_id=p_empid
    and pph_tran_year=p_tran_year
    and pph_tran_month=P_TRAN_MONTH
    and pph_hop_code=5
    and PPH_SALARY_THRU='R';
    -- SELECT  distinct count(*)
    --  INTO v_cnt
    --  FROM PRM_T_VAR_HOP
    --  where PTVH_EMP_ID=p_EMPID
    --  and PTVH_TRAN_YEAR=p_TRAN_YEAR
    --  and PTVH_TRAN_MONTH=P_TRAN_MONTH;
    v_sql := 'select  distinct PCH_SHORT_DESCRIPTION,v_basic,PTVH_AMOUNT Amount ';
    --  FOR i IN 1..v_cnt
    --  LOOP
    v_sql := v_sql || ',max(decode(rn, PCH_SHORT_DESCRIPTION)) as description ';
    --v_sql := v_sql || ',max(decode(rn, '||to_char(i)||', PDSL_INTEREST)) as interest'||to_char(i);
    -- v_sql := v_sql || ',max(decode(rn, '||to_char(i)||', PDSL_PRINCIPAL_SALARY)) as principle'||to_char(i);
    -- v_sql := v_sql || ',max(decode(rn, '||to_char(i)||', PDSL_SOCIETY_CODE)) as SOC_CODE'||to_char(i);
    --  END LOOP;
    v_sql := v_sql || ' from (select  PRM_T_VAR_HOP.*, PRM_C_HOP.*, row_number() over (partition by PTVH_EMP_ID order by PTVH_EMP_ID) as rn
    from  
    PRM_T_VAR_HOP,
    PRM_C_HOP
    WHERE PTVH_EMP_ID         =P_empid
    And   PTVH_TRAN_YEAR      =P_TRAN_YEAR
    And   PTVH_TRAN_MONTH     =P_TRAN_MONTH
    And   PTVH_HOP_CODE       =PCH_HOP_CODE
    AND   PCH_CALCULATION_BASIS=''V''
    AND   PCH_TAG              =''C''
    AND   PTVH_SALARY_THRU     =''R'')';
    OPEN O_rc FOR v_sql;
    END;
    [/code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Your first piece of code does not work, because a create table statement cannot be issued using a ref cursor like that. When executed with the "execute immediate" command, it works. Then, the refcursor is only a "select * from report_tbl".
    What it does, is dynamically dropping and creating a table report_tbl and filling it with the results of a horribly inefficient pivot query. If the report_tbl has no other purpose after running this procedure, then I'd suggest to not drop and create tables dynamically like that. In the second variant of test_transpose, you can see how you can do that.
    SQL> create table main_tbl (magazine,region,quantity)
      2  as
      3  select 'MAGAZINE1','REGION1',1 from dual union all
      4  select 'MAGAZINE1','REGION2',2 from dual union all
      5  select 'MAGAZINE1','REGION3',3 from dual union all
      6  select 'MAGAZINE2','REGION1',4 from dual union all
      7  select 'MAGAZINE2','REGION2',5 from dual union all
      8  select 'MAGAZINE2','REGION3',6 from dual
      9  /
    Tabel is aangemaakt.
    SQL> create or replace PROCEDURE TEST_TRANSPOSE(o_test OUT SYS_REFCURSOR)
      2  AS
      3    report_exists number(3);
      4    report_name varchar(30) := 'REPORT_TBL' ;
      5    query_main varchar(16000) := 'create table ' || report_name || ' as select MAGAZINE ' ;
      6    query_part varchar(1024) ;
      7    my_var varchar2(7);
      8
      9    cursor cur_region is select distinct REGION from MAIN_TBL order by region;
    10  begin
    11    select count(*) into report_exists
    12    from tab
    13    where tname = report_name;
    14    if ( report_exists = 1 ) then
    15    execute immediate 'drop table ' || report_name ;
    16    end if;
    17
    18    open cur_region ;
    19    loop
    20      fetch cur_region into my_var ;
    21      exit when cur_region%NOTFOUND;
    22      query_part := 'select nvl(sum(quantity),0) from MAIN_TBL x where x.magazine = main.magazine and x.region='''||my_var||'''' ;
    23      query_main := query_main || chr(10) || ',(' || query_part || ')"' || my_var || '"';
    24    end loop;
    25    close cur_region ;
    26
    27    query_main := query_main || ' from (select distinct MAGAZINE from MAIN_TBL ) main' ;
    28    execute immediate query_main;
    29    open o_test for 'select * from ' || report_name;
    30  end;
    31  /
    Procedure is aangemaakt.
    SQL> var rc refcursor
    SQL> exec test_transpose(:rc)
    PL/SQL-procedure is geslaagd.
    SQL> print rc
    MAGAZINE     REGION1    REGION2    REGION3
    MAGAZINE1          1          2          3
    MAGAZINE2          4          5          6
    2 rijen zijn geselecteerd.
    SQL> create or replace procedure test_transpose (o_test out sys_refcursor)
      2  as
      3    l_query varchar2(1000) := 'select magazine';
      4  begin
      5    for r in (select distinct region from main_tbl)
      6    loop
      7      l_query := l_query || ', sum(decode(region,''' || r.region || ''',quantity)) ' || r.region;
      8    end loop;
      9    l_query := l_query || ' from main_tbl group by magazine';
    10    open o_test for l_query;
    11  end;
    12  /
    Procedure is aangemaakt.
    SQL> exec test_transpose(:rc)
    PL/SQL-procedure is geslaagd.
    SQL> print rc
    MAGAZINE     REGION1    REGION2    REGION3
    MAGAZINE1          1          2          3
    MAGAZINE2          4          5          6
    2 rijen zijn geselecteerd.Regards,
    Rob.

Maybe you are looking for