Stored procedure in oracle plsql giving Error

Hi all,
I want to create stored procedure in oracle.
In that,I want to update if record is present in the table else want to insert that record in that table.
Here is my stored proc which I write.
I have very little knowledge about oracle(to be honest no knowledge).
Below is my code and the purpose of this code is to insert/update the data based on the entry what ever the user makes in cognos report studio report view.
Collapse | Copy Code
create or replace
PROCEDURE INSERTCOMMENTS
N_HATID NUMBER
, N_IN_NUMBER NUMBER
, N_POINTS VARCHAR2 DEFAULT 255
, N_QETYPE VARCHAR2 DEFAULT 255
) AS
BEGIN
IF((SELECT COUNT(*) FROM CCM_REPORT_USER.POINTS_QETYPE_COMMENTS
WHERE CCM_REPORT_USER.POINTS_QETYPE_COMMENTS.HATID = N_HATID)=0)
THEN (INSERT INTO "CCM_REPORT_USER"."POINTS_QETYPE_COMMENTS" (HATID, IN_NUMBER, POINTS, QETYPE)
VALUES (N_HATID , N_IN_NUMBER , N_POINTS , N_QETYPE,));
ELSE
(UPDATE "CCM_REPORT_USER"."POINTS_QETYPE_COMMENTS" SET CCM_REPORT_USER.POINTS_QETYPE_COMMENTS.POINTS = N_POINTS
AND CCM_REPORT_USER.POINTS_QETYPE_COMMENTS.QETYPE = N_QETYPE
WHERE CCM_REPORT_USER.POINTS_QETYPE_COMMENTS.HATID = N_HATID)
AND WHERE CCM_REPORT_USER.POINTS_QETYPE_COMMENTS.IN_NUMBER = N_IN_NUMBER)
END IF;
END INSERTCOMMENTS;

948677 wrote:
I want to create stored procedure in oracle.
I have very little knowledge about oracle(to be honest no knowledge).If you are new to Oracle you should first be familiar with the manuals before writing code
http://tahiti.oracle.com/
For the latest version
http://www.oracle.com/pls/db112/homepage
And then start with *2 Day Developer's Guide*
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10766/toc.htm
SQL Language Reference
http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/toc.htm
Concepts
http://download.oracle.com/docs/cd/E11882_01/server.112/e16508/toc.htm
PL/SQL Language Reference
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/toc.htm
And the Error Messages references for looking up the errors you will encounter when starting out
http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/toc.htm
>
In that,I want to update if record is present in the table else want to insert that record in that table.
Here is my stored proc which I write.Once you know where the manuals are you would see that you would not write a stored procedure, you would use the MERGE command to do this
http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_9016.htm#i2081218
Which you can of course put in a stored procedure if you like.

Similar Messages

  • SQLException while calling a Stored Procedure in Oracle

    Hi all,
    I am getting this error while calling a Stored Procedure in Oracle...
    java.sql.SQLException: ORA-00600: internal error code, arguments: [12259], [], [
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:207)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:540)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1273)
    at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:780)
    at oracle.jdbc.driver.OracleResultSet.next(OracleResultSet.java:135)
    at StoredProcedureDemo.main(StoredProcedureDemo.java:36)
    The Program is ...
    import java.sql.*;
    public class StoredProcedureDemo {
         public static void main(String[] args) throws Exception {
              Connection con = null;
              ResultSet rs = null;
              Statement st = null;
              CallableStatement cs = null;
              int i;
              try {
                   Class.forName("oracle.jdbc.driver.OracleDriver");
                   con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:SHYAM","scott","tiger");
                   System.out.println("Got Connection ");
                   st = con.createStatement();
                   String createProcedure = "create or replace PROCEDURE Get_emp_names (Dept_num IN NUMBER) IS"
                             +" Emp_name VARCHAR2(10);"
                             +" CURSOR c1 (Depno NUMBER) IS"
                             +" SELECT Ename FROM emp WHERE deptno = Depno;"
                             +" BEGIN"
                             +" OPEN c1(Dept_num);"
                             +" LOOP"
                             +" FETCH c1 INTO Emp_name;"
                             +" EXIT WHEN C1%NOTFOUND;"
                             +" END LOOP;"
                             +" CLOSE c1;"
                             +" END;";
                   System.out.println("Stored Procedure is \n"+createProcedure);
                   i = st.executeUpdate(createProcedure);
                   System.out.println("After creating the Stored Procedure "+i);
                   cs = con.prepareCall("{call Get_emp_names(?)}");
                   System.out.println("After calling the Stored Procedure ");
                   cs.setInt(1,20);
                   System.out.println("Before executing the Stored Procedure ");
                   rs = cs.executeQuery();
                   System.out.println("The Enames of the given Dept are ....");
                   while(rs.next()) {
                        System.out.println("In The while loop ");
                        System.out.println(rs.getString(1));
              catch (Exception e) {
                   e.printStackTrace();
    Stored Procedure is ...
    create or replace PROCEDURE Get_emp_names (Dept_num IN NUMBER) IS
    Emp_name VARCHAR2(10);
    CURSOR c1 (Depno NUMBER) IS
    SELECT Ename FROM emp WHERE deptno = Depno;
    BEGIN
    OPEN c1(Dept_num);
    LOOP
    FETCH c1 INTO Emp_name;
    EXIT WHEN C1%NOTFOUND;
    END LOOP;
    CLOSE c1;
    END;
    Stored procedure is working properly on sql*plus(Oracle 8.1.5)) editor. But it is not working from a standalone java application. Can anyone please give me a solution.
    thanks and regards
    Shyam Krishna

    The first solution is to not do that in java in the first place.
    DDL should be in script files which are applied to oracle outside of java.
    Other than I believe there are some existing stored procedures in Oracle that take DDL strings and process them. Your user has to have permission of course. You can track them down via the documentation.

  • Calling stored procedure in Oracle forms

    I have a stored procedure in Oracle which is declared as follows in the package
    SFCS1.Company_Selection(O_Cursor IN OUT T_Cursor, cls IN Varchar2);
    Where T_Cursor is defined as a Ref Cursor
    From the Oracle forms I'm using the following code
    SFCS1.Company_Selection(A,my_cls);
    go_block('Block50');
    Execute_Query;
    I get the error message "FRM40505:Oracle Error: Unable to Perform Query". If I hardcode the value of my_cls in the query it runs properly. Any solutions will be really helpful
    Further to this, I want to put the single quotes around a value (for eg. 'A') from a variable. For instance I'm getting a value from my_cls and for the output I want to surround it with the single quotes, can somebody tell me how to do it.
    Thanks in advance

    This is a bit of a roundabout way to do it? Try setting up the block data source as procedure and set the values in the property palette of the data block.
    e.g.
    Query Data Source Type = Procedure
    Query Data Source Name = SFCS1.Company_Selection
    Query Data Source Columns = (Whatever columns/items you have in your datablock)
    Query Data Source Arguments = Argument names are your ref cursor and your variable.
    Check out basing data blocks on Ref Cursors.
    HTHs
    L :-)

  • How to Create a Stored Procedure in Oracle

    I try to create a very simple Stored Procedure from Oracle SQL Developer, got the following error. Can someone give me some help on this? I am new on this. Thanks.
    Error(4,1): PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: := ( ; not null range default character The symbol ";" was substituted for "BEGIN" to continue.
    create or replace PROCEDURE Test
    AS ACCESSTYP_ID ACCESSTYP.ACCESSTYPCD%TYPE
    BEGIN
         SELECT ACCESSTYPCD
         INTO ACCESSTYP_ID
         FROM ACCESSTYP
         WHERE ACCESSTYPCD = 'WWW';
    END;

    I found out I forgot to put ";" after the declare.
    How do I test it call this stored procedure from
    Oracle SQL Developer.
    create or replace PROCEDURE Test_VL
    AS ACCESSTYP_ID
    ACCESSTYP.ACCESSTYPCD%TYPE;
         SELECT ACCESSTYPCD
         INTO ACCESSTYP_ID
         FROM ACCESSTYP
         WHERE ACCESSTYPCD = 'WWW';
    END;in your SQL Developer window just enclosed your procedure with a Begin ... End.
      Begin
        Test_VL;
      End;

  • Stored procedure in Oracle 8.1.7.0

    HI,
    my oracle version is 8.1.7.0
    I've created this stored procedure:
    CREATE OR REPLACE procedure CREATE_TAB1
    IS
    SVUOTA VARCHAR2(64);
    PRAGMA AUTONOMOUS_TRANSACTION;
    err_num number;
    err_msg varchar2(100);
    BEGIN
    SVUOTA := 'TRUNCATE TABLE TAB1 REUSE STORAGE';
    EXECUTE IMMEDIATE SVUOTA;
    INSERT INTO TAB1
    SELECT "COD_IMM","PIANO","COD_RITMI","TOTAL_AREA","MAX_AREA"
    FROM (SELECT a.*,
    MAX(total_area) OVER (PARTITION BY cod_imm, piano) max_area
    FROM REP_02_TEST1 a
    where a.COD_RITMI not in ('04'))
    WHERE max_area = total_area;
    COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
    err_msg:= SUBSTR(SQLERRM, 1, 100);
    err_num:= SQLCODE;
    INSERT INTO tab_error (proc_name, err_code, err_msg, err_date)
    VALUES ('CREATE_TAB1', err_num, err_msg, sysdate);
    COMMIT;
    END CREATE_TAB1;
    but when I compile I get this error
    PROCEDURE AFM.CREATE_TAB1
    On line: 14
    PLS-00103: Encountered the symbol "(" when expecting one of the following:
    , from
    the procedure stop on line:
    MAX(total_area) OVER (PARTITION BY cod_imm, piano) max_area
    I think that oracle version 8.1.7.0 not allow the code "OVER (PARTITION BY"
    I tried also with:
    EXECUTE IMMEDIATE 'INSERT INTO TAB1
    SELECT "COD_IMM","PIANO","COD_RITMI","TOTAL_AREA","MAX_AREA"
    FROM (SELECT a.*,
    MAX(total_area) OVER (PARTITION BY cod_imm, piano) max_area
    FROM REP_02_TEST1 a
    where a.COD_RITMI not in ('04'))
    WHERE max_area = total_area';
    but I get:
    PROCEDURE AFM.CREATE_TAB1
    On line: 16
    PLS-00103: Encountered the symbol "04" when expecting one of the following:
    How can I create my stored procedure with Oracle version 8.1.7.0
    Thank in advance!

    What is this code suppose to accomplish?
    Is this type of processing not possible using Global Temporary Tables?
    Oracle8i PL/SQL did not parse analytic functions correctly so you would have to make that SELECT a view and then SELECT from that view in PL/SQL.
    I tried also with:When you wrap the SELECT in EXECUTE IMMEDIATE you have to properly use the single quotes. The single quote that appears at this line:
    where a.COD_RITMI not in ('04'))is assumed by the compiler as the end of the string started by EXECUTE IMMEDIATE. That is not what you want.
    Please post some more details about the type of procesing that this code is suppose to accomplish so we can suggest alternatives to get it done better.

  • How to call a sql server stored procedure from oracle

    Hi all,
    Please anybody tell me how to call a sql server stored procedure from oracle.
    I've made an hsodbc connection and i can do insert, update, fetch data in sql server from oracle. But calling SP gives error. when I tried an SP at oracle that has line like
    "dbo"."CreateReceipt"@hsa
    where CreateReceipt is the SP of sql server and hsa is the DSN, it gives the error that "dbo"."CreateReceipt" should be declared.
    my database version is 10g
    Please help me how can i call it... I need to pass some parameters too to the SP
    thanking you

    hi,
    thank you for the response.
    when i call the sp using DBMS_HS_PASSTHROUGH, without parameters it works successfully, but with parameters it gives the following error
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Generic Connectivity Using ODBC][Microsoft][ODBC SQL Server Driver]Invalid parameter number[Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index (SQL State: S1093; SQL Code: 0)
    my code is,
    declare
    c INTEGER;
    nr INTEGER;
    begin
    c := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@hsa;
    DBMS_HS_PASSTHROUGH.PARSE@hsa(c, 'Create_Receipt(?,?)');
    DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,1,'abc');
    DBMS_HS_PASSTHROUGH.BIND_VARIABLE@hsa(c,2,'xyz');
    nr:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@hsa(c);
    DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@hsa(c);
    end;
    Create_Receipt is the sp which requires two parameters.
    please give me a solution
    thanking you
    sreejith

  • 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.

  • How to use a stored procedure in oracle reports

    How to use a stored procedure in oracle reports

    Dear,
    In report triggers you can write your procedure/functions or call it like
    function AfterPForm return boolean is
    begin
    myprocedure(:mydate);
    return (TRUE);
    end;
    Thanks
    Jamil

  • Calling Stored Procedure from Oracle DataBase using Sender JDBC (JDBC-JMS)

    Hi All,
    We have requirement to move the data from Database to Queue (Interface Flow: JDBC -> JMS).
    Database is Oracle.
    *Based on Event, data will be triggered into two tables: XX & YY. This event occurs twice daily.
    Take one field: 'aa' in XX and compare it with the field: 'pp' in YY.
    If both are equal, then
         if the field: 'qq' in YY table equals to "Add" then take the data from the view table: 'Add_View'.
         else  if the field: 'qq' in YY table equals to "Modify"  then take the data from the view table: 'Modify_View'.
    Finally, We need to archive the selected data from the respective view table.*
    From each table, data will come differently, means with different field names.
    I thought of call Stored Procedure from Sender JDBC Adapter for the above requirement.
    But I heard that, we cannot call stored procedure in Oracle through Sender JDBC as it returns Cursor instead of ResultSet.
    Is there any way other than Stored Procedure?
    How to handle Data Types as data is coming from two different tables?
    Can we create one data type for two tables?
    Is BPM required for this to collect data from two different tables?
    Can somebody guide me on how to handle this?
    Waiting eagerly for help which will be rewarded.
    Thanks and Regards,
    Jyothirmayi.

    Hi Gopal,
    Thank you for your reply.
    >Is there any way other than Stored Procedure?
    Can you try configuring sender adapter to poll the data in intervals. You can configure Automatic TIme planning (ATP) in the sender jdbc channel.
    I need to select the data from different tables based on some conditions. Let me simplify that.
    Suppose Table1 contains 'n' no of rows. For each row, I need to test two conditions where only one condition will be satisfied. If 1st condition is satisfied, then data needs to be taken from Table2 else data needs to be taken from Table3.
    How can we meet this by configuring sender adapter with ATP?
    ================================================================================================
    >How to handle Data Types as data is coming from two different tables?
    If you use join query in the select statement field of the channel then whatever you need select fields will be returned. This might be fields of two tables. your datatype fields are combination of two diff table.
    we need to take data only from one table at a time. It is not join of two tables.
    ================================================================================================
    Thanks,
    Jyothirmayi.

  • How to verify stored procedures in Oracle 10g.

    I would like to locate default stored procedure in Oracle 10g database.
    And Suggest which stored procedure can be converted in to JAVA code ??

    If the Java part of the question refers to looking for potential to speed up your stored procedures:
    You should consider native compilation which transfers your code to shared libraries which are bound to the DB kernel.
    In this case however consider, that this does not make any sense/improvement for pure data access statements but only for procedures consisting of complex algorithmic processing.
    For details refer to
    [How native compilation works|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2280]
    and
    [Setting Up and Testing PL/SQL Native Compilation|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2309]

  • How to write a PL/SQL stored procedure in Oracle to call Webservice

    Can any one pelase send me a code on how to write a PL/SQL stored procedure in Oracle database to call the Webservice ?
    Thanks,
    Rajesh

    Were you able to solve this problem

  • C-stored procedure in Oracle

    Dear Friends,
    I have a lot of c-stored procedures for DB2,
    now,I want to use these c-stored procedures in Oracle directly without any changes.
    I'm not sure whether this method is right.
    Please help me.
    Guang

    I think, that the best way inclusion of business logic into ORACLE database as a TABLE-constraints, triggers and stored procedures for guaranteeing data integrity.
    But if you have really a LOT of c-stored procedures and you need provide quick startup with ORACLE, than you can use your c-procedures as "external calls" with ORACLE.
    Unfortunately I don't know DB2 c-stored procedures specifics and can't give finally recommendations for you.
    Sincerely, Urry

  • Stored Procedure in Oracle 8

    Hi, I create a stored procedure in Oracle 10g and I want to run this same procedure in Oracle 8. Anybody knows the syntax for this procedure in Oracle 8?
    Here are the stored procedure:
    create or replace PROCEDURE Sp06_Rel_Acoes_Usuario (dt_inicio IN VARCHAR2, dt_fim IN VARCHAR2, filtro IN VARCHAR2, v_cursor OUT sys_refcursor)
    IS
    BEGIN
         OPEN v_cursor FOR
              SELECT A.AD013_DTOCORRENCIA, A.AS013_APLICATIVO, A.AS002_CDUSUARIO, A.AS013_DADOADICIONAL, AC.AS012_DSACAO
              FROM T013_ACAOUSUARIO A, T012_ACAO AC
         WHERE A.AD013_DTOCORRENCIA BETWEEN TO_DATE(dt_inicio,'dd/mm/yyyy HH24:MI:SS') AND TO_DATE(dt_fim,'dd/mm/yyyy HH24:MI:SS')
              AND A.AS002_CDUSUARIO = filtro AND A.AN012_CDACAO = AC.AN012_CDACAO                     
              ORDER BY A.AD013_DTOCORRENCIA;
    END;

    I'm pasting your code in proper format - so that everyone can understand what you have posted here.
    create or replace PROCEDURE Sp06_Rel_Acoes_Usuario (dt_inicio IN VARCHAR2,
                                                        dt_fim IN VARCHAR2,
                                                        filtro IN VARCHAR2,
                                                        v_cursor OUT sys_refcursor)
    IS
    BEGIN
      OPEN v_cursor FOR
      SELECT A.AD013_DTOCORRENCIA,
             A.AS013_APLICATIVO,
             A.AS002_CDUSUARIO,
             A.AS013_DADOADICIONAL,
             AC.AS012_DSACAO
      FROM T013_ACAOUSUARIO A, T012_ACAO AC
      WHERE A.AD013_DTOCORRENCIA BETWEEN TO_DATE(dt_inicio,'dd/mm/yyyy HH24:MI:SS')
      AND TO_DATE(dt_fim,'dd/mm/yyyy HH24:MI:SS')
      AND A.AS002_CDUSUARIO = filtro
      AND A.AN012_CDACAO = AC.AN012_CDACAO
      ORDER BY A.AD013_DTOCORRENCIA;
    END;Try to post script in proper format. It will be easier for everyone to go through your problem and debug it.
    Regards.
    Satyaki De.

  • Importing function with multiple ref cursors in Stored Procedure of Oracle 12c database Using EF6

    Hi Good day!
    I can able to import function for stored procedure of oracle db and able to add the complex type and get the output but i tried to import the procedure which having two ref cursors and unable to retrieve the column information. Only able to retrieve the
    columns of first ref cursor.  Please help me to get the result of two ref cursors which acting as out parameters.

    Having to ref cursors return mutiple recordsets in an Oracle package is like haveng two resultsets return from a MS SQL Server sparc.
    The link may point you in the right direction.
    http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram

  • How to create java stored procedure from oracle(Dastageer)

    how to create java stored procedure from oracle-please help me to create the procedure.

    Hi,
    This forum is exclusively for discussions related to Sun Java Studio Creator. Please post your question in the appropriate forum.
    Thanks,
    RK.

Maybe you are looking for

  • Connecting form MAC OS 10.7.5 to HP officejet pro 8620

    I am running MAC OS 10.7.5. Have just bought HP officejet pro 8620 After initial setup wireless printing worked but then stopped and now when I try to print the computer cannot find the printer. I have reinstalled the soft ware - both printer and com

  • Advice on migrate from MacBook 4,1 to MacBookPro 8,1 & mobileMe to iCloud

    Hi all, I just bought a MBP 8,1 to upgrade from my MacBook 4,1 (white). I'd like to know what the best way is to migrate my files & stuff. How well does the Migration Assistant work? My main concern is with Mail, Calendar, Address Book, iPhoto, iMovi

  • 2 Filled Sonnet Fusion 500P enclosures; RAID 0/1, or RAID 5?

    I currently have a Sonnet Fusion 500P loaded with 5 WD 500GB RE2 drives; all running individually and not RAIDed; this box is connected to a Sonnet Tempo E2P in my MacPro. I'm interested in getting a 2nd identical enclosure and drives, and creating a

  • ESS link EP7

    Dear All, My landscape consists of EP7 and ECC6 using ESS and MSS from portal. In ESS role I have Benfits and payments workset , I dont want to use Benfits like participation overview page and FlexBeans. Deleted these pages from workset even though i

  • Formatted Search IN OINV

    Experts, Good Day! I have a UDF in OINV where I want to compute sum of amount in INV1. Example: INV1.PPD_Amount (UDF)  Line 1   1000 INV1.PPD_Amount (UDF)  Line 2   1000 INV1.PPD_Amount (UDF)  Line 3   1000 Total Amount