Sample plsql code needed.

I am a beginner in plsql programming . I need to dump all data from EMP table to EMP1 by using cursor.
Can anybody help?

I am a beginner in plsql programming.I would first learn all there is to learn about SQL, nowadays...
Cursor based row-by-row processed = slow-by-slow.
http://tkyte.blogspot.com/2006/10/slow-by-slow.html
Doing it set-based, should be the way to go, it takes only one line of code, one single SQL statement:
SQL> create table emp1 as select * from emp;Cursor examples can be found in the Oracle documentation @ http://tahiti.oracle.com
For example, have a look in the PL/SQL User's Guide and Reference @ http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm
Or here: http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96624/a_samps.htm
Edited by: hoek on May 8, 2010 6:08 PM

Similar Messages

  • Sample JSP code needed with jdbc select lists

    Hello java experts!
    I need to create a series a jsp pages that connects to an ms access "books" database. This first page should connect to the books.mdb and populate select lists with the values from the database. The solution would be similar to the the books shopping cart in the CoreServlets book, EXCEPT I must do everything in JSP only.
    All I have done to this point is Java servlets. (I've done shopping cart stud in ASP.net, but not JSP).
    I know everyone hates to post code samples, but seeing the code will help me understand. I've read the API, the tutorials, 3 textbooks, and any other doc I could find. I understand Java beans and jsp, but I need to see the JSP for this to finally crystalize.
    Thanks in advance.
    -JavaGirl

    what school is teaching db access from jsp?

  • Functional Module:Need  some sample source code.

    Hi All,
    I have created  a customized table   u2018ZStock_Order_Dealeru2019 with the following fields:
    Stock_Order_Dealer
    Dealer Number
    S2D order Number     
    Line item Number     
    Material Number     
    Ordered Quantity     
    Batch Number     
    Received Quantity     
    S2D from D2G     
    Receiving Date
    I need to  create a remote enabled function module in CRM system to fetch the u2018Batch Numberu2019 and u2018Received Quantityu2019 fields when the Material Number is fed to it.Please note that the input and output should be tables.
    Could some one please give some sample source code for this.

    I used table types and select queries to resolve this problem.

  • Needs sample ABAP code for field routine

    Dear Expert,
    There is a field "Pay Scale Group" in my DSO which stores the data in the format
    AA1/B1/CCC2/DD2/EEE1, A1/BB2/CC2/DDD3/EE2 etc. These data has to be transferred to
    InfoCube where "pay Scale Group" in the InfoCube will store the data like EEE1,EE2 etc.
    I need to write a field routine on the transformation between DSO and Cube.
    Can any one please help me with the sample ABAP code for this scenario.
    Some more examples for better understanding of the requirement:-
    Data in DSO(Source)            Data in Cube(Target)
    ===================            ===================
    AA1/B1/CCC2/DD2/EEE1            EEE1
    AAA1/BB2/CC1/DDD3/EE2           EE2
    A2/BBB2/CC2/DDD3/EEE5           EEE5
    AA2/BB1/C1/DDD3/EE3             EE3
    A3/B1/CC2/DDD1/EE4              EE4
    Many thanks in advance.
    Regards,
    Prakash
    Please do not dump your code requirements in SDN
    Edited by: Pravender on May 18, 2011 11:37 AM

    Hi,
    You can use the following code :
    Suppose the technical name of the field coming from DSO is ZPAY_SGRP.
    And also for example let me take one record, that is ZPAY_SGRP = AA1/B1/CCC2/DD2/EEE1 .
    My assumption is that there will always be 4 '/'.
    In the field routine write the below code
    data: V1(5) type c,
              V2(5) type c,
             V3(5) type c,
              V4(5) type c,
             V5(5) type c.
    data : VAR1 TYPE /BIC/OIZPAY_SGRP.
    split VAR 1  at '/' into V1 V2 V3 V4 V5.
    result = V5.
    V5 will be having the characters after the last '/' .That is V5 = EEE1.
    Hope the above reply was helpful.
    Kind Regards,
    Ashutosh Singh
    Edited by: Ashutosh Singh on May 17, 2011 3:53 PM
    Edited by: Ashutosh Singh on May 17, 2011 4:17 PM

  • Need Sample java code

    Hi,
    iam working in SAP .
    I need sample java code on how to convert Decimal to number
    For Ex: I/p-----123.11
    O/p----------------12311 ( with out decimal) want to remove the dicimal point what ever the input value and deliver it to the output
    Please give me code
    Regards
    Suman

    i don't know what do you want to do really. If you are doing it simply then you can take the input in a String and then remove the decimal.
    String str = "123.11";
    str = str.substring(0, str.indexOf("."));
    System.out.println(str);

  • Need sample source code for calling stored procedure in Oracle

    Hi.
    I try to call stored procedure in oracle using JCA JDBC.
    Anybody have sample source code for that ?
    Regards, Arnold.

    Thank you very much for a very quick reply. It worked, but I have an extended problem for which I would like to have a solution. Thank you very much in advance for your help. The problem is described below.
    I have the Procedure defined as below in the SFCS1 package body
    Procedure Company_Selection(O_Cursor IN OUT T_Cursor)
    BEGIN
    Open O_Cursor FOR
    SELECT CompanyId, CompanyName
    FROM Company
    WHERE CompanyProvince IN ('AL','AK');
    END Company_Selection;
    In the Oracle Forms, I have a datablock based on the above stored procedure. When I execute the form and from the menu if I click on Execute Query the data block gets filled up with data (The datablock is configured to display 10 items as a tabular form).
    At this point in time, I want to automate the process of displaying the data, hence I created a button and from there I want to call this stored procedure. So, in the button trigger I have the following statements
    DECLARE
    A SFCS1.T_Cursor;
    BEGIN
    SFCS1.Company_Selection(A);
    go_Block ('Block36');
    The cursor goes to the corresponding block, but does not display any data. Can you tell me how to get the data displayed. In the future versions, I'm planning to put variables in the WHERE clause.

  • Need Sample source code for Forum in jsp

    Hi..
    Please tell me the website which is having the sample source code for simple forum... I have to implement it into my project... kindly help me out...
    thanx in advance
    kumar

    Hi..
    Please tell me the website which is having the sample source code for simple forum... I have to implement it into my project... kindly help me out...
    thanx in advance
    kumar

  • ORA-01403: no data found Error in PLSQL code raised during plug-in processing.

    Hello OTN community,
    We are having the access to APEX problem. a New user was setup to access the APEX application. When I test to login as a new user, I get the message "ORA-01403: no data found Error in PLSQL code raised during plug-in processing.". When click OK to the disply message, the application will take me out of the sstem. I need help to even understand what is happening. I didn't develop the application, there is no documentation for this application, I am just supporting the application whenever there is a problem and I am new to APEX. As you can see I need help to figure this thing out. Your help is dearly appreciated.
    Thank you OTN

    Try to check the query that is executed and check if there is data or not

  • How to write a file in unix server through oracle plsql code

    Hi All,
    My requirement is to create and write a file (any file for eg txt file) in unix box with in a specified directory through oracle plsql code.
    Oracle sits in windows server.
    using utl_file package we can create directory where oracle resides and write it there in oracle server in our case windows..
    But here we need to create,write a file but in unix server which is different server than where the oracle server resides..
    we are using Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    Can any one one please help me out in this issue...
    Thanks in Advance.
    Prakash

    Mr Prakash,
    Why are you asking this question multiple times in every forum you can spell?
    Valid responses have been presented to you already two times.
    Can you explain why you can't follow them up, but continue to abuse this forum by repeating doc questions?
    Sybrand Bakker
    Senior Oracle DBA

  • How to register a custom plsql code

    Hi
    i have wrritten a custom plsql code for my Overtime entries validation for payroll processing.
    Can any body tell me how to register it in application.
    Secondly i want to get the output file generated by report submission on my desktop.i want to know where the report output files for HR and payroll are stored so that i can get them through FTP.
    Regards

    if you want to integrate your plsql into a fast formula, please download the fast formula guide from metalink. Or ask your functional payroll consultant.
    All reports and processes in Oracle Apps are handled via concurrent programs and requests. When a concurrent request is finished, click on the output button, and depending from the filetype, your browser will take action.
    All concurrent output is also stored on the concurrent server. Ask your apps dba where she mapped the concurrent output directory. But i do not see why you should need this.

  • URGENT HELP: When some users submit, application carries empty fields from html components to plsql code

    Hi APEX users and developer, especially forum's active users, please get me rid of this problem because it is really very bad situation.
    I have a real trouble with application. It behaves unusual. Application is used by 60 users but only 3 of them have these problem and they can not use the application anymore.
    Application is
    http://apex.oracle.com/pls/apex/f?p=70547
    After fields are filled and some rows checked from tabular form in page, user submits the page. Process called newReyestr calls plsql procedure from package with inputs from page. But only same 3 users get empty fields in plsql code. I see it just after when the first line stepped in procedure.
    So, "what is the problem?"

    Hi NoGot,
    you know, I have not written big quote. The code was big. But it has no any meaning. Because problem is in first line. No need to understand it.
    There is no any difference between those users. They also tried it from different browser and even computers.
    BTW: I am not russian.

  • NLS issue in Java/PLSQL code [ using ROWID]

    I have NLS related question regarding the following scenario in Java/PLSQL code ::-
    OracleResultSet ors = (OracleResultSet) stmt.executeQuery("select rowId from t where t.col = 'XX'");
    // The above query could return multiple rowIds.
    String strVal1 = null;
    String strVal2 = null;
    if(ors.next())
    strVal1 = ors.getROWID(1).stringValue();
    if(ors.next())
    strVal2 = ors.getROWID(1).stringValue();
    ArrayList strList = new ArrayList();
    strList.add(strVal1);
    strList.add(strVal2);
    Now I need to pass a list of rowId's from Java to PLSQL function f().
    oracle.sql.ARRAY rowListArr = convertArrayListToRowPointerList(strList, conn) ;
    OracleCallableStatement cstmt = (OracleCallableStatement)
    cstmt.prepareCall("begin f(?); end;");
    cstmt.setObject(1, rowListArr);
    cstmt.execute();
    where:-
    static oracle.sql.ARRAY convertArrayListToRowPointerList(ArrayList arr, Connection conn)
    throws SQLException {
    oracle.sql.ArrayDescriptor stDesc = ArrayDescriptor.createDescriptor
    ("DBUSER.ROWPOINTERLIST", conn);
    oracle.sql.Datum[] keyVals= new oracle.sql.Datum[arr.size()];
    for(int i = 0; i < arr.size(); i++) {
    keyVals[i] = new oracle.sql.CHAR((String) arr.get(i),
    oracle.sql.CHAR.DEFAULT_CHARSET);
    oracle.sql.ARRAY keyArr = new oracle.sql.ARRAY(stDesc, conn, keyVals);
    return keyArr;
    and
    create or replace type DBUSER.ROWPOINTERLIST as table of varchar2(4000);
    Will there be NLS issues in the above code, where I pass the rowId content
    that I obtain from one query, as array of string bind variables to a subsequent PLSQL procedure? --- first approach
    Or
    do I need to pass the rowId list , as a array of oracle.sql.ROWID via bind variables? -- second approach
    The problem I have in second approach is that in the DB we cannot define a type as a table of ROWID's. So currently I have RowPointerList as a table of varchar2's (note the length of list of rowId is not predetermined in my case, so I user table instead of varray).
    However I was wondering if the first approach will have any NLS issues.
    Will appreciate your comments.
    Thanks

    ROWIDs are represented as either hex-encoded values or base64 encoded values. Both encodings use pure ASCII, so there should be no NLS issues.
    I am not very familiar with the oracle.sql.ARRAY type, but unless absolutely necessary, I would avoid the oracle.sql.CHAR datatype (assuming 10g drivers). Using java.lang.String is preferred.
    -- Sergiusz

  • Can i submit  a page and later execute a plsql code in some seperate page..

    I have a page.. this page has a button and the action for it is submit ..database action is insert activity..What i need is the moment
    i press the button .. after the submit activity has been done .. a plsql procedure which fires when i redirect to page.. 100 also be executed.
    Normally if my button action type is redirect to page .. Then this procedure gets executed...Since it is in redirected page.
    But If I change the action type... to submit this is not possible . ..Since the activity that occurs is the database insert activity..
    I also need the plsql code which is other page to be executed..
    Any information provided will be appreciated.

    i got it solved.. issue was..just
    needed to write a plsql code.. which will do a insert activity and then ..it does a redirect of page..I changed the button action from submit to link to page
    Issue is sorted
    Thanks

  • Hide or encrypt password in SQL/PLSQL code

    Hi,
    I need some help or suggestions to hide or encrypt database user password in SQL/PLSQL code. In our environment, we use a connect string with username/password for the JDBC connection. Our goal is to take out the password string and read it or pass it to the code on the fly.
    Thanks,
    Subroto

    So in the database somewhere you are storing username and password credentials? How do those credentials get sent to the Java application? Presumably, the Java application has to connect to the database, requiring a JDBC connection string, in order to query the table in order to get the username and password you've stored in the database.
    Assuming there are two different JDBC connection strings-- one in the Java application that connects to the database and a second that is stored in the database and used later by the Java application, who do you want to protect the data from? Do you want to protect it from other database users? Or do you want to protect it from the Java developers? Or something else?
    Justin

  • PLSQL code optimizing

    Hi
    My oracle db version is 11g R1/AIX5.3
    how following plsql code can be re-written for better performance
    CREATE OR REPLACE PROCEDURE CSCOMMON.POST_SEQ_PROCESS
    AS
       -- Declare variables to hold sequenced infomration.
       pragma autonomous_transaction;
       V_RECORD_ID           POST_SEQUENCING_PROCESS.RECORD_ID%TYPE;
       V_RECEIVED            POST_SEQUENCING_PROCESS.RECEIVED%TYPE;
       V_PROCESS_NAME        POST_SEQUENCING_PROCESS.PROCESS_NAME%TYPE;
       V_PROCESS_ID          POST_SEQUENCING_PROCESS.PROCESS_ID%TYPE;
       V_PROCESS_SEQ         POST_SEQUENCING_PROCESS.PROCESS_SEQ%TYPE;
       V_RECEIVER            POST_SEQUENCING_PROCESS.RECEIVER%TYPE;
       V_RECEIVER_ID         POST_SEQUENCING_PROCESS.RECEIVER_ID%TYPE;
       V_RECEIVER_SEQ        POST_SEQUENCING_PROCESS.RECEIVER_SEQ%TYPE;
       V_SENDER              POST_SEQUENCING_PROCESS.SENDER%TYPE;
       V_SENDER_ID           POST_SEQUENCING_PROCESS.SENDER_ID%TYPE;
       V_MESSAGE_ID          POST_SEQUENCING_PROCESS.MESSAGE_ID%TYPE;
       V_INSTANCE_ID         POST_SEQUENCING_PROCESS.INSTANCE_ID%TYPE;
       V_STATUS              POST_SEQUENCING_PROCESS.STATUS%TYPE;
       V_STEP_ID             POST_SEQUENCING_PROCESS.STEP_ID%TYPE;
       V_INTERNAL_ID         POST_SEQUENCING_PROCESS.INTERNAL_ID%TYPE;
       V_LOCK_ID             POST_SEQUENCING_PROCESS.LOCK_ID%TYPE;
       V_ERROR_HANDLING      POST_SEQUENCING_PROCESS.ERROR_HANDLING%TYPE;
       V_STARTED             POST_SEQUENCING_PROCESS.STARTED%TYPE;
       V_WARNINGS            POST_SEQUENCING_PROCESS.WARNINGS%TYPE;
       V_DOCUMENTTYPE_NAME   POST_SEQUENCING_PROCESS.DOCUMENTTYPE_NAME%TYPE;
       V_DOCUMENTTYPE_ID     POST_SEQUENCING_PROCESS.DOCUMENTTYPE_ID%TYPE;
       V_DOCUMENTTYPE_SEQ    POST_SEQUENCING_PROCESS.DOCUMENTTYPE_SEQ%TYPE;
       v_current             VARCHAR2 (600);
       v_sql_error           VARCHAR2 (600);
       lv_count              NUMBER;
       CURSOR c_first500
       IS
          SELECT RECORD_ID,
                 RECEIVED,
                 PROCESS_NAME,
                 PROCESS_ID,
                 PROCESS_SEQ,
                 RECEIVER,
                 RECEIVER_ID,
                 RECEIVER_SEQ,
                 SENDER,
                 SENDER_ID,
                 MESSAGE_ID,
                 INSTANCE_ID,
                 STATUS,
                 STEP_ID,
                 INTERNAL_ID,
                 LOCK_ID,
                 ERROR_HANDLING,
                 STARTED,
                 WARNINGS,
                 DOCUMENTTYPE_NAME,
                 DOCUMENTTYPE_ID,
                 DOCUMENTTYPE_SEQ
            FROM (  SELECT RECORD_ID,
                           RECEIVED,
                           PROCESS_NAME,
                           PROCESS_ID,
                           PROCESS_SEQ,
                           RECEIVER,
                           RECEIVER_ID,
                           RECEIVER_SEQ,
                           SENDER,
                           SENDER_ID,
                           MESSAGE_ID,
                           INSTANCE_ID,
                           STATUS,
                           STEP_ID,
                           INTERNAL_ID,
                           LOCK_ID,
                           ERROR_HANDLING,
                           STARTED,
                           WARNINGS,
                           DOCUMENTTYPE_NAME,
                           DOCUMENTTYPE_ID,
                           DOCUMENTTYPE_SEQ
                      FROM CSCOMMON.SEQUENCING_PROCESS
                  ORDER BY RECEIVED)
           WHERE ROWNUM < 101;
       P_RAND                NUMBER;
       V_LID                 NUMBER;
    BEGIN
       v_current := 'BEFORE CURSOR OPENING';
       SELECT COUNT (*) INTO lv_count FROM POST_SEQUENCING_PROCESS;
       OPEN c_first500;          
       LOOP
          SELECT CSCOMMON.SEQ_LID_SEQUENCING_PROCESS_NU.NEXTVAL
            INTO V_LID
            FROM DUAL;
         UPDATE CSCOMMON.SEQUENCING_PROCESS A
             SET A.LOCK_ID = V_LID ,
                 A.STATUS = 1,
                 A.STARTED = SYSDATE,
                 A.WARNINGS = 0
           WHERE NOT EXISTS
                        (SELECT 1
                           FROM CSCOMMON.SEQUENCING_PROCESS B
                          WHERE ( (A.RECEIVER_ID = B.RECEIVER_ID
                                   AND A.RECEIVER_SEQ = 1)
                                 OR (A.PROCESS_ID = B.PROCESS_ID
                                     AND A.PROCESS_SEQ = 1)
                                 OR (A.DOCUMENTTYPE_ID = B.DOCUMENTTYPE_ID
                                     AND A.DOCUMENTTYPE_SEQ = 1))
                                AND (A.ERROR_HANDLING = 0 OR B.STATUS != 4)
                                AND B.RECORD_ID < A.RECORD_ID)
                 AND A.STATUS = 2
                 AND 1024 =
                                        (SELECT WM1.STATUS
                           FROM WMLOG610.WMPROCESS WM1,
                                (  SELECT MAX (AUDITTIMESTAMP) AUDITTIMESTAMP,
                                          INSTANCEID
                                     FROM WMLOG610.WMPROCESS WM2
                                    WHERE INSTANCEID IN
                                             (SELECT INSTANCE_ID
                                                FROM CSCOMMON.SEQUENCING_PROCESS where rownum<101)
                                 GROUP BY INSTANCEID
                                 ORDER BY instanceid) WM2
                          WHERE     A.INSTANCE_ID = WM1.INSTANCEID
                                AND WM1.INSTANCEID = WM2.INSTANCEID
                                AND WM1.AUDITTIMESTAMP = WM2.AUDITTIMESTAMP
                                AND ROWNUM = 1)
                 AND A.LOCK_ID IS NULL
                 AND A.DOCUMENTTYPE_NAME != 'FxHaulage';
    commit;
          FETCH c_first500
          INTO V_RECORD_ID,
               V_RECEIVED,
               V_PROCESS_NAME,
               V_PROCESS_ID,
               V_PROCESS_SEQ,
               V_RECEIVER,
               V_RECEIVER_ID,
               V_RECEIVER_SEQ,
               V_SENDER,
               V_SENDER_ID,
               V_MESSAGE_ID,
               V_INSTANCE_ID,
               V_STATUS,
               V_STEP_ID,
               V_INTERNAL_ID,
               V_LOCK_ID,
               V_ERROR_HANDLING,
               V_STARTED,
               V_WARNINGS,
               V_DOCUMENTTYPE_NAME,
               V_DOCUMENTTYPE_ID,
               V_DOCUMENTTYPE_SEQ;
          EXIT WHEN c_first500%NOTFOUND;
          BEGIN
             v_current := 'INSERT INTO POST_SEQUENCING_PROCESS';
             IF (lv_count = 0)
             THEN
                INSERT INTO POST_SEQUENCING_PROCESS (RECORD_ID,
                                                     RECEIVED,
                                                     PROCESS_NAME,
                                                     PROCESS_ID,
                                                     PROCESS_SEQ,
                                                     RECEIVER,
                                                     RECEIVER_ID,
                                                     RECEIVER_SEQ,
                                                     SENDER,
                                                     SENDER_ID,
                                                     MESSAGE_ID,
                                                     INSTANCE_ID,
                                                     STATUS,
                                                     STEP_ID,
                                                     INTERNAL_ID,
                                                     LOCK_ID,
                                                     ERROR_HANDLING,
                                                     STARTED,
                                                     WARNINGS,
                                                     DOCUMENTTYPE_NAME,
                                                     DOCUMENTTYPE_ID,
                                                     DOCUMENTTYPE_SEQ)
                     SELECT *
                       FROM cscommon.sequencing_process A
                      WHERE lock_id IS NOT NULL
                            AND A.DOCUMENTTYPE_NAME != 'FxHaulage' order by lock_id;
                            commit;
                INSERT INTO CSCOMMON.PRE_SEQUENCING_PROCESS
                   (SELECT * FROM CSCOMMON.POST_SEQUENCING_PROCESS);
    commit;
                DELETE FROM CSCOMMON.POST_SEQUENCING_PROCESS;
                COMMIT;
                v_current := 'DELETE FROM SEQUENCING_PROCESS';
                DELETE FROM CSCOMMON.SEQUENCING_PROCESS
                      WHERE LOCK_ID IS NOT NULL
                            AND DOCUMENTTYPE_NAME != 'FxHaulage';
                COMMIT;
             ELSE
                RETURN;
             END IF;
          END;
       END LOOP;
       CLOSE c_first500;                    
       COMMIT;
    EXCEPTION
       WHEN OTHERS
       THEN
          v_sql_error := SQLERRM || ' - ' || v_current;
          ROLLBACK;
    END;
    /May be by using forall /bulk collections
    Thanks
    Raj

    You need to understand transactional consistency. Not only are your commits
    slowing things down, they are not good for maintaining transactional consistency.
    Ask yourself what would happen if there was a problem in your procedure after
    the first commit? How would you recover from that with some records
    updated but the rest of your procedure not having been run?
    In general you should only have one commit at the topmost level. By that I mean if
    there is a program that kicks of other ones and is the 'master' controller, that
    should be the one that decides to commit or rollback the whole transaction.
    Also you need to understand exception handling. Your exception processing is dangeroulsly wrong.
    Remove it.
    Finally, try and do this processing without using cursor loops: pure (set-based) SQL is much faster than
    slow cursor based PL/SQL and SQL together.

Maybe you are looking for