Help needed to create a Procedure

Can anyone help me with a small procedure I have to write?
Requirement to create Stored Procedure :
1.  Create tables
     A1
     A2
     B1
     B2
----------- this is done------
Fill the data in those tables
------------this is also done----
Create "Source_table.tx"t file with table names and place them in any location.
------------this is also done----
write a procedure to read the above file "Source_table.txt"  and it should read the tables name 1 by 1 which performs a simple operation inside SP -->  
Select * from @Table_Name
Also, it should check if the .txt file is exisiting or not.
If exists then Read the file and execute the SP.
      SP does this :
         Select * from A1
         Select * from A2
         Select * from B1
         Select * from B2
After that, write an output file with the counts of records to the same location  where our Source_table.txt exists .
If doesnt exist then write to a .txt file that "File name and Location doesnt exist"

What format is the data inside your .txt file?
If it's just some lines containing the names of the tables then you may as well just use the UTL_FILE package to:
a) check the existence of the file using the UTL_FILE.FGETATTR procedure
b) open and read the contents of the file using the UTL_FILE.FOPEN, UTL_FILE.GET_LINE and UTL_FILE.FCLOSE functions/procedures.
UTL_FILE
Alternatively you could set up an external table to read the .txt file as though it's a table.
Managing External Tables
Once you extract the table names from the .txt file, you'll then have to construct dynamic SQL queries to query the data from them.  Are all of the tables of the same structure or do they change?  If they change you'll have to use the DBMS_SQL package.  If they don't you could do it more statically in PL/SQL code (at least in terms of the structures you're reading the data into), but you may still be better using DBMS_SQL for it.  It depends what you're trying to do exactly and why these table names are being exported to a file and need to be read dynamically in this way.  Often Dynamic coding indicates poor design, but without knowing exactly what you're doing, it's hard to tell if it's really necessary or not.

Similar Messages

  • Need to create a procedure whic h search and drop tables from the db.

    Dear Gurus,
    I need to create a procedure, which first checks the tables and then drop those tables if find in the database. For example, I have 5 tables, then my procedure should first checks the existence , then drop all those 5 tables from the database. Actually, I have to attach this procedure to report buildeer, so please keep in mind the above mentioned scenario. Your input will be highly appriciated.
    hare krishna
    Alok

    Dropping 5 tables each time user hits the report!!! (According to my understanding)
    I would like to share my experience. My group developed many complex reports, we used oracle jobs to run the complex queries time to time, according to our business requirements and stored the result in a final table. Just for viewing at front end level, we used a simple select statement.
    -aijaz

  • Help Needed in Creating Java Class and Java Stored Procedures

    Hi,
    Can anyone tell how can i create Java Class, Java Source and Java Resource in Oracle Database.
    I have seen the Documents. But i couldn't able to understand it correctly.
    I will be helpful when i get some Examples for creating a Java Class, Java Source and Stored Procedures with Java with details.
    Is that possible to Create a Java class in the oracle Database itself ?.
    Where are the files located for the existing Java Class ?..
    Help Needed Please.
    Thanks,
    Murali.v

    Hi Murali,
    Heres a thread which discussed uploading java source file instead of runnable code on to the database, which might be helpful :
    Configure deployment to a database to upload the java file instead of class
    The files for the java class you created in JDev project is located in the myworks folder in jdev, eg, <jdev_home>\jdev\mywork\Application1\Project1\src\project1
    Hope this helps,
    Sunil..

  • Help needed In testing a procedure

    Hi,
    This Is My procedure. I need to test this procedure. How can i pass multiple values to this first two parameters and check ?
    CREATE OR REPLACE PROCEDURE testts (
    i_custid IN str_varray,
    i_pymtref IN str_varray,
    i_screen IN VARCHAR2,
    i_rejreason IN VARCHAR2,
    i_userid IN tl_pymt_details.user_id%TYPE,
    i_country_code IN tl_pymt_details.country_code%TYPE,
    i_city_code IN tl_pymt_details.city_code%TYPE,
    o_intrc OUT NUMBER
    IS
    w_intrc NUMBER;
    w_excep EXCEPTION;
    w_time_zone_date TIMESTAMP ( 6 );
    w_custid tl_pymt_details.cust_id%TYPE;
    w_pymtref tl_pymt_details.pymt_ref%TYPE;
    BEGIN
    IF i_screen = 'confirm'
    THEN
    FOR i IN 1 .. i_custid.COUNT
    LOOP
    w_custid := i_custid (i);
    w_pymtref := i_pymtref (i);
    sp_031_process_time_zone_diff (w_time_zone_date);
    UPDATE tl_pymt_details
    SET status_code = 151
    WHERE cust_id = i_custid (i) AND pymt_ref = i_pymtref (i);
    INSERT INTO tl_pymt_details_trk
    (cust_id, pymt_ref, modi_date, status_code,
    payee_charge_status, modi_by, country_code, city_code)
    (SELECT cust_id, pymt_ref, w_time_zone_date, status_code,
    payee_charge_status, i_userid, pd.country_code,
    pd.city_code
    FROM tl_pymt_details pd, tl_sys_parm sp
    WHERE cust_id = i_custid (i)
    AND pymt_ref = i_pymtref (i)
    AND pd.country_code = i_country_code
    AND pd.city_code = i_city_code);
    END LOOP;
    ELSE
    FOR i IN 1 .. i_custid.COUNT
    LOOP
    w_custid := i_custid (i);
    w_pymtref := i_pymtref (i);
    sp_031_process_time_zone_diff (w_time_zone_date);
    UPDATE tl_pymt_details
    SET status_code = 5,
    rejected_reason = i_rejreason
    WHERE cust_id = i_custid (i) AND pymt_ref = i_pymtref (i);
    INSERT INTO tl_pymt_details_trk
    (cust_id, pymt_ref, modi_date, status_code,
    payee_charge_status, modi_by, country_code, city_code)
    (SELECT cust_id, pymt_ref, w_time_zone_date, status_code,
    payee_charge_status, i_userid, pd.country_code,
    pd.city_code
    FROM tl_pymt_details pd, tl_sys_parm sp
    WHERE cust_id = i_custid (i)
    AND pymt_ref = i_pymtref (i)
    AND pd.country_code = i_country_code
    AND pd.city_code = i_city_code);
    END LOOP;
    END IF;
    o_intrc := 1;
    END testts;
    Your Help is highly appreciated.
    Regards,
    SImma....

    Hi,
    I supposed your varray is created by TYPE str_varray IS VARRAY(100) OF VARCHAR2(30); Then you can do the following:
    declare
      l_custid str_varray;
      l_pymtref str_varray;
      l_out number;
    begin
      /* filling of varray */
      l_custid := str_varray('test1','test2');
      l_pymtref := str_varray('test4','test5');
      /* call procedure */
       testts (
           i_custid => l_custid,
           i_pymtref => l_pymtref,
           i_screen =>   ..... , -- set value
           i_rejreason =>   ..... , -- set value
           i_userid =>   ..... , -- set value
           i_country_code =>   ..... , -- set value
           i_city_code =>   ..... , -- set value
           o_intrc => l_out
    end;Herald ten Dam
    http://htendam.wordpress.com

  • Help need to create a query

    I need to fetch records from a table. Please help me to create a query
    The Tablename is Employee. It has the following records
    Department Empname Gender
    Finance Tom Male
    Finance Rick Male
    Finance Stacy Female
    Corporate Tom Male
    Corporate Rob Male
    I want to select the value of the Gender field from the Employee table corresponding to a Department
    If all the values in the Gender field are 'MALE' corresponding to 'finance' in the Department field, the value should be 'MALE'
    If there is a value 'FEMALE', the gender corresponding to the Empname 'TOM' should be considered as the gender

    Tables have rows - not records.
    Your question is a basic SQL language question - which means you do not know the SQL language. This forum is not a classroom for teaching you the SQL language.
    Use the following as the basic outline of how your SQL language statement need to look like for selecting the required from the table:
    SELECT
      <<sql projection goes here>>
    FROM <<table name goes here>>
    WHERE <<filter conditions go here>>
    {code}
    The SQL projection specifies the list of columns the SQL need to return to the caller.
    The filter condition is basic predicates and AND and OR  can be used for multiple predicates.
    Go to http://tahiti.oracle.com and look for the +SQL Reference Guide+ for the Oracle version you are using. The +SELECT+ statement syntax is covered in detail and sample statements are provided.
    And please do not expect this forum to be used as a classroom, or expect this forum to do your homework for a class.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help needed to create Quik Time VR movies, step by step

    Hello,
    thank you for your attenction.
    I need to create Quick time vr movies, and I need to know the exact sequance of steeps to do it, and if the starting point I use is correct.
    1) I shooted a sequence of photos with my digital camera (for example: www.stebianchi.com/quicktimevrhelp/still-photo.jpg).
    2) Then, with photoshop (CS4) I choose: Automate/photomerge and I select all them to joint them in a bigger 360° panoramic one (www.stebianchi.com/quicktimevrhelp/pan.jpg). If, untill here, all is correct, the first question: in photoshop Photomerge layout option, do I have to choose one voice "auto, perspective, cylindrical, spherical, etc..." rather than anoter one of these?
    3) from here, I really need your help.
    First of all: the great doubt:
    My photos can not cover a spherical panorama, they're only a "ring" around a center (and not a spherical texture). To cover all the surface (or almost all, ok...) of my ambient, do I have to use a wider lens on my camera or there is a different solution (for ex a vertical photomerge?).
    4) Done this, I think I shuold buy a software like Cubic converter, to set and export the QTVR movie. Right?
    Thanks a lot guys,
    all the best!
    Stefano

    You can call your local apple store(find one on the home page of apple.com) and they will give you instructions how to convert DVD to iPod. That is what they told me, but from what I heard, you may need more than Quicktime Pro. Just call and ask them, because if you make a manual of how to do it, it could help me a lot.
    (I'm looking for a good DVD converter, already know some, beside the internet download ones)

  • Help Needed in Xml Stored Procedure

    Hi , i am trying to write one sp which takes xml document as a parameter. I want to update/Insert the data in the xml based on some conditions. So i put the data from xml to a global TEMPORARY table. The i process this data and will update /Insert the data based on the output.
    Right now i am unable to create global TEMPORARY table my stored procedure .When i compile the stored procedure , its showing the following error
    Compilation errors for PROCEDURE SYSTEM.TESTXML
    Error: PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe
    Line: 8
    Text: CREATE GLOBAL TEMPORARY TABLE temp
    I am attaching my sp below
    create or replace procedure testxml
    ( xmlDoc IN clob )
    is
    updCtx DBMS_XMLStore.ctxType;
    rows NUMBER;
    begin
    CREATE GLOBAL TEMPORARY TABLE temp
    ( cdcalendar NUMBER,
    cdperiod NUMBER,
    cdsubperiod NUMBER,
    cdglperiod NUMBER,
    dtstartsubperiod date,
    dtendsubperiod date
    ) ON COMMIT PRESERVE ROWS;
    updCtx := DBMS_XMLStore.newContext(temp)
    rows := DBMS_XMLStore.insertXML(updCtx,xmlDoc);
    DBMS_XMLStore.closeContext(updCtx);
    if Not exists
    (Select Distinct cd_calendar from Calendar_Period
    Where cd_calendar = select Distinct cdcalendar from temp )
    Then
    Insert into calendar_period
    cd_calendar,
    cd_period,
    cd_subperiod,
    cd_gl_period,
    dt_start_subperiod,
    dt_end_subperiod
    select cdcalendar,
    cdperiod,
    cdsubperiod,
    cdglperiod,
    dtstartsubperiod,
    dtendsubperiod
    from temp ;
    Else
    Update calendar_period
    Set cdp.cd_calendar = temp.cdcalendar ,
    cdp.cd_period = temp.cdperiod,
    cdp.cd_subperiod = temp.cdsubperiod ,
    cdp.cd_gl_period = temp.cdglperiod,
    cdp.dt_start_subperiod = temp.dtstartsubperiod ,
    cdp.dt_end_subperiod = temp.dtendsubperiod
    From
    calendar_period cdp Inner Join temp
    On
    cdp.cd_calendar = temp.cdcalendar
    cdp.cd_subperiod = temp.cdsubperiod
    cdp.cd_period = temp.cdperiod ;
    End if
    end testxml;
    Kindly guide me !!!!

    Hi,
    "CREATE GLOBAL TEMPORARY TABLE" is not a PL/SQL sommand; it is a SQL command. That explain the error message you're getting.
    Normally, tables (including Global Temporary Tables) are created once for all, without using PL/SQL. After they are created, you can write PL/SQL code to populate and use them. This job doies not seem to be an exception.
    In the rare event that you do need to create a table in PL/SQL, use EXECUTE IMMEDIATE, which can do any SQL command from withiin PL/SQL.
    EXECUTE IMMEDIATE is documented in the PL/SQL manual:
    http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/dynamic.htm#sthref857

  • Help needed for creating 1 invoice for 2 different material types.

    Dear, Gurus
    I really need help here I have spent 3 days cracking my head trying to solve the problem. Problem is client was creating invoice with reference to order and while invoice was being made it would cause an invoice split. The materials involved are Trading Good and Service Material. They would like only 1 invoice. Note nothing was different except material group and item cat. of the material. payment terms billing dates partners everything is same.
    Current item config for Trading Good material is ZMPI-project item cat.
    Copying requirements   023  Item ord.ref. w/o AZ        Billing quantity     A
    Data VBRK/VBRP         000                                           Pos./neg. quantity   +
                                                                                    Pricing type         K
                                                                                    PricingExchRate type
                                                                                    Price source
    Current item config for service Material is TAD-Service
    Copying requirements   002  Item/order-related          Billing quantity     A
    Data VBRK/VBRP         001  Inv.split (sample)            Pos./neg. quantity   +
                                                                                    Pricing type         G
                                                                                    PricingExchRate type
                                                                                    Price source
    I was told to change Data VBRK/VBRP to 003 One Invoice which I did in both of these item cat. and yes they worked perfectly but at time of creating the invoice for service material the qty that showed was 11. Note: In sales order it is 1 qty. So I went back into the config of item cat TAD and changed copying requirement to 023 instead of 002 but nothing changed. Seems a qty of 10 is referencing something else which I have no idea what or where it is picking this up from. Just to see or test things I went into the sales order and tried changing the service material qty then a weird popup appears and says service order 12344456 has been blocked. (Seriously I have no idea why this would happen or should be existing at all.) Even if for some reason it is being referenced the service order that is existing is qty 1.
    I really really do need help and if someone can help me that would be god sent.
    Regards, Ali

    You did not mention what value is maintained in the field billing quantity in the copy control->Item settings. Check for the service item, what value is assigned. Put value A and re-test.
    Note that whenever you change any settings in configuration side, you need to create a new documents to test the results of the settings. You should not use the existing documents.
    When you say the document is blocked, then check the status of the sales order to find the reason for blocking (like credit block, approval etc)..
    Regards,

  • Help needed to create a CSS 'style-switcher' button.

    Hi,
    I need some help please in creating alternate style sheets for each page on a site I'm creating to enable users to change text size (i.e. small, normal and large options - sometimes, symbolized as a letter 'A' in varying sizes). The site has been built in basic format so far but I would like to add these features for the sake of usability. There are no actual problems with the site as it currently works fine, it's just this one thing I need help with.
    Is this possible using post-processing methods, (which I have no problem doing) and if so could someone kindly point me in the right direction? I've searched the iWeb forum using keywords most relevant to this question and have found nothing.
    Any help greatly appreciated,
    Matt
    MacMini G4 1.42GHZ   Mac OS X (10.4.8)  

    Thanks varkgirl,
    This works (partially): this is the page:
    http://www.charitydesigns.com/odyssey/index.html
    The first paragraph is not responding and at larger sizes line spacing is not in proportion to the size of the text (and is squashed), what am I doing wrong?
    Hope you can assist.

  • Help needed to create Notification in IW21 tr code using BAPI

    <b>Hi Experts,
                      I am searching for some BAPI's of IW21 tr code, where I need to create Notification using the details of some legasy system/flat file. I dont wanna use BDC, I need to use BAPI so could anyone help me out.
    Thanks in advance,
    Sunil</b>

    <b>Hi Surya,
                   Thanx for your reply, if u have the program to create the notification could you please send me,,,, I need it urgently....I have a Z-table which has the datas like;
    CusomerName
    Customeraddress
    Work_order_type
    Work_order_priority.........and so on...
    Now I need to create notification using the same datas....
    Thanks in advance..
    Sunil</b>

  • Help needed to create desktop application background using javaFx.

    Hi,
    i need to create background for my desktop application in JavaFx. It have top side bottom menu bars to place icon buttons for my app. The whole scene need to resize. I had tried this using
    JavaFx composer. But my issue is like in java swing i can not able to create different panels and set different styles. Please help me on this issue.
    Thankyou.

    Hi mate take a rectangle and fill it to scene width !
    use fill gradient and bind it to your main scene.width
    for example :
    Rectangle {
    fill: color.Blue
    stroke: LinearGradient {
    startX: 125.0, startY: 0.0, endX: 225.0, endY: 0.0
    proportional: false
    stops: [
    Stop { offset: 0.0 color: Color.web("#1F6592") }
    Stop { offset: 1.0 color: Color.web("#80CAFA") }
    use appropriate start and offset then bind it to scene width and height.
    width : bind scene.width;
    height : bind scene.height ;

  • HELP NEEDED BADLY, creating Block Avoider game.

    Could anyone please help me with creating a game called block avoider, i have a link here to show what the game should look like. I need alot of help with it so if anyone is good a coding and see`s this as an easy project helping me would be greatly appreciated.
    LINK TO SIMILAR GAME:
    http://scratch.mit.edu/projects/timo4932/82326

    We can help, but we won't do it for you. Start the game, and post a question if you are stuck and need help.

  • Help needed . Creating DSN in Unix

    Hi The Oracle server is running on Unix platform. I need to connect the server from my client application which recoganises the DB using its DSN. Please help me in creating the DSN in the Unix environment.
    Any help will be Apreciated.
    Regards,
    Badhri([email protected])

    I'm a bit confused. You need to have an ODBC DSN on your client machine, not on your server machine. ODBC is generally a Windows-only technology-- at least the Oracle ODBC driver is available only on Windows. There are some third-parties that have created various Unix ODBC drivers, however.
    If you need to create a DSN on a Unix box, you must not be using the Oracle driver or the standard DSN configuration dialogs. You'd have to contact whatever third-party driver provider you're using to find out how they handle things.
    Justin

  • Help needed with creating Flash game

    Hello,
    I need to create Flash educational/quiz game for one of my clients. It would be based on concept like these ones for example:
    Example 1
    http://go.ucsusa.org/game/
    Example 2
    http://www.zdravlje.hr/igre/stop-aids/
    Note: when you open this link you will see two text boxs which you first must fill. On the left side text box "Upišite ime" means "Type your name" and right one "Upišite godinu svog rođenja" means "Year of birth"
    What is interesting about this type of games is that they are classic games (for example game Labirint where you have to find way out), but during play pop-up questions starts to appear to test end user knowledge abot certain topic (in example 2 topic is about AIDS/HIV). In case of my client, topic is about Eco environment.
    Here is where my trouble starts;) : I found many useful free tutorials how to create simple flash game (most interesting example I found is this one http://www.strille.net/tutorials/snake/index.php)  BUT I dont know how make that system of popup questions appear during game similar to Example 1 and Example 2?
    Any help is appreciated and thanks in advance for promt reply.
    Greetings,
    Adnan

    Update: I have just read all instructions in Snake tutorial which helped be better realize how Snake game works.
    a) This is what I plan to realize for my client:
    1. Snake game which end users will play and during play pop-up/quiz quesions will appear on topic Eco environment;
    2. For example when end user earns 50 points he must answer some of the random questions like "Q:How many ton of waste are produced by US livestock each year" with three answers A1: "1 milion" A2: "1 bilion" A3: "2 bilion" and after user scores 100 points then another question pops up and so on. This is all true if all answers are correct but in case he answer some question wrong than game can start from begining or another solution could be he looses -50 or -100 points.
    3. At the end, user which gains most points wins.
    b) This is what I have done till now:
    I have this file http://www.strille.net/tutorials/snake/snakeGameWithHighscore.zip which I partly understand how it works with my Flash knowladge.
    All functions and main game engine is in layer code:
    "// Snake Game by Strille, 2004, www.strille.net
    blockSize = 8;   // the block width/height in number of pixels
    gameHeight = 30; // the game height in number of blocks
    gameWidth  = 45; // the game width in number of blocks
    replaySpeed = 1;
    SNAKE_BLOCK = 1; // holds the number used to mark snake blocks in the map
    xVelocity = [-1, 0, 1, 0]; // x velocity when moving left, up, right, down
    yVelocity = [0, -1, 0, 1]; // y velocity when moving left, up, right, down
    keyListener = new Object(); // key listener
    keyListener.onKeyDown = function() {
        var keyCode = Key.getCode(); // get key code
        if (keyCode > 36 && keyCode < 41) { // arrow keys pressed (37 = left, 38 = up, 39 = right, 40 = down)...
            if (playRec) {
                if (keyCode == 37 && replaySpeed > 1) {
                    replaySpeed--;
                } else if (keyCode == 39 && replaySpeed < 10) {
                    replaySpeed++;
            } else if (game.onEnterFrame != undefined) { // only allow moves if the game is running, and is not paused
                if (keyCode-37 != turnQueue[0]) { // ...and it's different from the last key pressed
                    turnQueue.unshift(keyCode-37); // save the key (or rather direction) in the turnQueue
        } else if (keyCode == 32) { // start the game if it's not started (32 = SPACE)
            if (!gameRunning || playRec) {
                startGame(false);
        } else if (keyCode == 80) { // pause/unpause (80 = 'P')
            if (gameRunning && !playRec) {
                if (game.onEnterFrame) { // pause
                    delete game.onEnterFrame; // remove main loop
                    textMC.gotoAndStop("paused");
                } else { // exit pause mode
                    game.onEnterFrame = main; // start main loop
                    textMC.gotoAndStop("hide");
    Key.addListener(keyListener);
    function startGame(pRec) {
        x = int(gameWidth/2); // x start position in the middle
        y = gameHeight-2;     // y start position near the bottom
        map = new Array(); // create an array to store food and snake
        for (var n=0;n<gameWidth;n++) { // make map a 2 dimensional array
            map[n] = new Array();
        turnQueue = new Array(); // a queue to store key presses (so that x number of key presses during one frame are spread over x number of frames)
        game.createEmptyMovieClip("food", 1); // create MC to store the food
        game.createEmptyMovieClip("s", 2); // create MC to store the snake
        scoreTextField.text = "Score: 0"; // type out score info
        foodCounter = 0; // keeps track of the number of food movie clips
        snakeBlockCounter = 0; // keeps track of the snake blocks, increased on every frame
        currentDirection = 1; // holds the direction of movement (0 = left, 1 = up, 2 = right, 3 = down)
        snakeEraseCounter = -1; // increased on every frame, erases the snake tail (setting this to -3 will result in a 3 block long snake at the beginning)
        score = 0; // keeps track of the score
        ticks = lastRec = 0;
        recPos = recFoodPos = 0;
        playRec = pRec;
        if (!playRec) {
            textMC.gotoAndStop("hide"); // make sure no text is visible (like "game over ")
            highscores.enterHighscoreMC._visible = false;
            statusTextField.text = "";
            recTurn = "";
            recFrame = "";
            recFood = "";
            game.onEnterFrame = main; // start the main loop
        } else {
            if (loadedRecordingNumber != -1) {
                var n = getLoadedRecordingNumberHighscorePos(loadedRecordingNumber);
                statusTextField.text = "Viewing " + highscores[n].name.text + "'s game (score " + highscores[n].score.text + ")";
            } else {
                statusTextField.text = "Viewing your game";
            game.onEnterFrame = replayMain; // start the main loop
        placeFood("new"); // place a new food block
        gameRunning = true; // flag telling if the game is running. If true it does not necessarily mean that main is called (the game could be paused)
    function main() { // called on every frame if the game is running and it's not paused
        if (playRec) {
            if (ticks == lastRec+parseInt(recFrame.charAt(recPos*2)+recFrame.charAt(recPos*2+1), 36)) {
                currentDirection = parseInt(recTurn.charAt(recPos));
                lastRec = ticks;
                recPos++;
        } else if (turnQueue.length) { // if we have a turn to perform...
            var dir = turnQueue.pop(); // ...pick the next turn in the queue...
            if (dir % 2 != currentDirection % 2) { // not a 180 degree turn (annoying to be able to turn into the snake with one key press)
                currentDirection = dir; // change current direction to the new value
                recTurn += dir;
                var fn = ticks-lastRec;
                if (fn < 36) {
                    recFrame += " "+new Number(fn).toString(36);
                } else {
                    recFrame += new Number(fn).toString(36);
                lastRec = ticks;
        x += xVelocity[currentDirection]; // move the snake position in x
        y += yVelocity[currentDirection]; // move the snake position in y
        if (map[x][y] != SNAKE_BLOCK && x > -1 && x < gameWidth && y > -1 && y < gameHeight) { // make sure we are not hitting the snake or leaving the game area
            game.s.attachMovie("snakeMC", snakeBlockCounter, snakeBlockCounter, {_x: x*blockSize, _y: y*blockSize}); // attach a snake block movie clip
            snakeBlockCounter++; // increase the snake counter
            if (map[x][y]) { // if it's a not a vacant block then there is a food block on the position
                score += 10; // add points to score
                scoreTextField.text = "Score: " + score; // type out score info
                snakeEraseCounter -= 5; // make the snake not remove the tail for five loops
                placeFood(map[x][y]); // place the food movie clip which is referenced in the map map[x][y]
            map[x][y] = SNAKE_BLOCK; // set current position to occupied
            var tailMC = game.s[snakeEraseCounter]; // get "last" MC according to snakeEraseCounter (may not exist)
            if (tailMC) { // if the snake block exists
                delete map[tailMC._x/blockSize][tailMC._y/blockSize]; // delete the value in the array m
                tailMC.removeMovieClip(); // delete the MC
            snakeEraseCounter++; // increase erase snake counter   
        } else { // GAME OVER if it is on a snake block or outside of the map
            if (playRec) {
                startGame(true);
            } else {
                gameOver();
            return;
        ticks++;
    function replayMain() {
        for (var n=0;n<replaySpeed;n++) {
            main();
    function gameOver() {
        textMC.gotoAndStop("gameOver"); // show "game over" text
        delete game.onEnterFrame; // quit looping main function
        gameRunning = false; // the game is no longer running
        enterHighscore();
    function placeFood(foodMC) {
        if (playRec) {
            var xFood = parseInt(recFood.charAt(recFoodPos*3)+recFood.charAt(recFoodPos*3+1), 36);
            var yFood = parseInt(recFood.charAt(recFoodPos*3+2), 36);
            recFoodPos++;
        } else {
            do {
                var xFood = random(gameWidth);
                var yFood = random(gameHeight);
            } while (map[xFood][yFood]); // keep picking a spot until it's a vacant spot (we don't want to place the food on a position occupied by the snake)
            if (xFood < 36) {
                recFood += " "+new Number(xFood).toString(36);
            } else {
                recFood += new Number(xFood).toString(36);
            recFood += new Number(yFood).toString(36);
        if (foodMC == "new") { // create a new food movie clip
            foodMC = game.food.attachMovie("foodMC", foodCounter, foodCounter);
            foodCounter++;
        foodMC._x = xFood*blockSize; // place the food
        foodMC._y = yFood*blockSize; // place the food
        map[xFood][yFood] = foodMC; // save a reference to this food movie clip in the map
    //- Highscore functions
    loadHighscores();
    enterHighscoreKeyListener = new Object();
    enterHighscoreKeyListener.onKeyDown = function() {
        if (Key.getCode() == Key.ENTER) {
            playerName = highscores.enterHighscoreMC.nameTextField.text;
            if (playerName == undefined || playerName == "") {
                playerName = "no name";
            saveHighscore();
            Key.removeListener(enterHighscoreKeyListener);
            Key.addListener(keyListener);
            highscores.enterHighscoreMC._visible = false;
            loadedRecordingNumber = -1;
            startGame(true);
    function enterHighscore() {
        if (score >= lowestHighscore) {
            highscores.enterHighscoreMC._visible = true;
            highscores.enterHighscoreMC.focus();
            Key.removeListener(keyListener);
            Key.addListener(enterHighscoreKeyListener);
        } else {
            loadedRecordingNumber = -1;
            startGame(true);
    function getLoadedRecordingNumberHighscorePos(num) {
        for (var n=0;n<10;n++) {
            if (num == highscores[n].recFile) {
                return n;
    function loadHighscores() {
        vars = new LoadVars();
        vars.onLoad = function(success) {
            for (var n=0;n<10;n++) {
                var mc = highscores.attachMovie("highscoreLine", n, n);
                mc._x = 5;
                mc._y = 5+n*12;
                mc.place.text = (n+1) + ".";
                mc.name.text = this["name"+n];
                mc.score.text = this["score"+n];
                mc.recFile = parseInt(this["recFile"+n]);
            lowestHighscore = parseInt(this.score9);
            if (!gameRunning) {
                loadRecording(random(10));
            delete this;
        if (this._url.indexOf("http") != -1) {
            vars.load("highscores.txt?" + new Date().getTime());
        } else {
            vars.load("highscores.txt");
    function loadRecording(num) {
        vars = new LoadVars();
        vars.onLoad = function(success) {
            if (success && this.recTurn.length) {
                recTurn = this.recTurn;
                recFrame = this.recFrame;
                recFood = this.recFood;
                startGame(true);
            } else {
                loadRecording((num+1)%10);
                return;
            delete this;
        loadedRecordingNumber = num;
        if (this._url.indexOf("http") != -1) {
            vars.load("rec"+loadedRecordingNumber+".txt?" + new Date().getTime());
        } else {
            vars.load("rec"+loadedRecordingNumber+".txt");
    function saveHighscore() {
        sendVars = new LoadVars();
        for (var n in _root) {
            if (_root[n] != sendVars) {
                sendVars[n] = _root[n];
        returnVars = new LoadVars();
        returnVars.onLoad = function() {
            if (this.status == "ok") {
                loadHighscoresInterval = setInterval(function() {
                    loadHighscores();
                    clearInterval(loadHighscoresInterval);
                }, 1000);
            delete sendVars;
            delete this;
        sendVars.sendAndLoad("enterHighscore.php", returnVars, "POST");
    function startClicked() {
        if (!gameRunning || playRec) {
            if (highscores.enterHighscoreMC._visible) {
                Key.removeListener(enterHighscoreKeyListener);
                Key.addListener(keyListener);
                highscores.enterHighscoreMC._visible = false;
            startGame(false);
    function viewGame(lineMC) {
        loadRecording(lineMC.recFile);
        statusTextField.text = "Loading " + lineMC.name.text + "'s game...";
    Now what is left to do is somehow to iclude educational quiz in this game/code. First idea that came to me is same thing Ned suggested: to create some unique movie clip which would contain all data/questions lined up but main problem for me is how to "trigger" that movie clip to play only AFTER end user clicks on "Start game" or SPACE to restart? Not sure how to solve this issue?

  • Help need in creating DB objects programatically .

    Hi All,
    I have a case where i need to create a table in DB from ADF and need to insert/modify/delete their records in java code.
    Is that possible to create an update-able view object from java code rather going with conventional declarative steps in ADF?
    Regards,
    Suresh kumar.k

    ADF BC runtime doesn't give you any feature out for the box for creating DB objects, you may need to use standard JDBC API+ DDL. (btw, there may be design time API used by JDev for DB synch . however I'm not sure about the feasibility of using the same in your context) Next step may be building programmatic EO/VO. You can refer this blog post for the same - http://jobinesh.blogspot.com/2010/06/model-driven-approach-for-building.html

Maybe you are looking for

  • Cannot Input Goods Receipt for a Stock Transport Order

    Dear all, I created a stock transport order from one plant to another. But in the following "MIGO" transaction, the system indicates "Document xxxxxxxxx does not contain any selectable items". In the stock transport order, I simply input the supplyin

  • One user can't get Outlook to work

    Hi, We have one user who is having problems with Outlook. It started a few weeks ago, and no one else is having the same problem. It says "The connection to Microsoft Exchange is unavailable. Outlook must be online to complete this action" Environmen

  • PC won't recognize WPSM54G HELP!

    Greetings. I am trying to reinstall my WPSM54G on my wireless network (via Belkin F6D4230-4 router). I can make it through the steps to set up the print server without any errors, but when I go to set up the PC, it does not pick up the WPS. (PC works

  • Sporadic blue screen on startup in windows 7

    i get a blue screen on start up once or twice a month with no pattern found. Will start up fine if restarted.

  • Nokia C3: missing application

    Just the other day, I noticed that my MENU changed. Something is missing. i've figured out that the pre-installed MAIL is missing -- from the menu, homescreen, shortcut and all. I am not doing anything weird before this thing happened. I was just tex