Call a procedure and a function over a db link

I feel a few errors with the following and would be very happy in the view of some experts here.

My use case is to insert records into a table via a database link. Inserted records will be interviewed for a same table in the local data dictionary. Everything works, but sometimes, I get a unique constraint violation if I'm trying to insert a duplicate record, so I wrote a simple function to check for the scenario. My problem is that I can run my procedure using the link to the db and I can run my function using the db link, but I can't use the two together without errors.

My test scenario uses only the standard emp table:

create or replace procedure test_insert(p_instance varchar2)
IS
l_sql varchar2(4000);
begin
    l_sql := 'insert into EMP@'||p_instance||' (EMPNO, ENAME, JOB, MGR, SAL, DEPTNO) (Select EMPNO, ENAME, JOB, MGR, SAL, DEPTNO from EMP)';
execute immediate l_sql;
END;

BEGIN
test_insert('myLink');
END;

It works very well and the insert occurs without any problem.

If I run the same process a second time, I get:

00001 00000 - "forced single (s.%s) violated" which is what I've been waiting for EMPNO has a unique constraint. So far so good.

Now, I create a function to check if the record exists:

create or replace function record_exists(p_empno IN NUMBER, p_instance IN varchar2) return number
IS
l_sql varchar2(4000);
l_count number;
BEGIN
l_sql := 'select count(*) from EMP@'||p_instance||' where empno = '||p_empno;
execute immediate l_sql into l_count;
IF
l_count > 0
THEN return 1;
ELSE
return 0;
END IF;
END;

I test this situation as follows:

select record_exists(8020, 'myLink') from dual;

RECORD_EXISTS(8020,'myLink')

-------------------------------------------

1

That works well, so now I'll add this feature to my procedure:

create or replace procedure test_insert(p_instance varchar2)
IS
l_sql varchar2(4000);
begin
    l_sql := 'insert into EMP@'||p_instance||' (EMPNO, ENAME, JOB, MGR, SAL, DEPTNO) (Select EMPNO, ENAME, JOB, MGR, SAL, DEPTNO from EMP WHERE record_exists( EMPNO, '''||p_instance||''') = 0)';
execute immediate l_sql;
END;

I test this situation as follows:

BEGIN
test_insert('myLink');
END;

As a result:

Error report:
ORA-02069: global_names parameter must be set to TRUE for this operation
ORA-06512: at "FUSION.TEST_INSERT", line 6
ORA-06512: at line 2
02069. 00000 -  "global_names parameter must be set to TRUE for this operation"
*Cause:    A remote mapping of the statement is required but cannot be achieved
           because global_names should be set to TRUE for it to be achieved
*Action:   Issue alter session set global_names = true if possible

I don't know why I'm getting this. The function works, the works of the procedure, but when I combine I get an error. If I set the global setting to true names and then run again I get:


02085. 00000 -  "database link %s connects to %s"
*Cause:    a database link connected to a database with a different name.
           The connection is rejected.
*Action:   create a database link with the same name as the database it
           connects to, or set global_names=false.

All opinions are appreciated. I do not understand why I can run the procedure and function of each separately on the db connection, but they don't work together.

Thank you

John

The procedure depends on what how would you define failure and it should mean - error to the caller, sign and continue, just continue. Constraints are created to ensure if it receives no invalid data in a table. Generally, they provide the most effective mechanism for the verification of the invalid data and return useful exceptions that can deal with the appellant. You also double the workload of the checking uniqueness by adding your own control.

In general I would say use Exceptions, they are your friend

Tags: Database

Similar Questions

  • Can we call the procedure inside the function?

    Hello

    Can we call the procedure inside the function?

    Thank you
    Brij

    845712 wrote:

    Can we call the procedure inside the function?

    Strange question to ask.

    Yes. This is the standard behavior in most (if not all) procedural and object oriented languages.

    A procedure, function or a method is a unit of code.

    You can call one of the other units. Units can call themselves (recursion). Technically, this means simply by pushing the battery current (to save the stack of the current device memory), the call to the new unit and then popping up battery when control is returned to the unity of the appellant.

    There are very few exceptions to this. The only one that comes to mind programming languages I've used through the years, is natural 1 - could not call a new unit of code to replace the existing one in memory. If no call-and-return was possible.

    Exactly what did you ask this question? Some newcomers to confused Oracle SQL and PL/SQL - two different languages aside server. And then also mistaken for PL/SQL client command vocabulary of SQL * more.

    You will need to make sure that understand the basics of programming (applies to most current programming languages) and Oracle concepts.

  • Call stored procedures and using its output parameters in a report

    Hello

    I have a procedure defined in a package on the database. This procedure returns a number of output parameters. How to call this procedure and use the output parameters in my report?

    Thank you, Mark

    Depends on the level at which the procedure should be called. If its at the State level, call the form in the trigger-REPORT-BEFORE (or AFTER-PARAMFORM) and store the off-values space reserved columns. These you can use anywhere in your report.

  • Stored procedure and stored function

    Greetings from a newbie,
    Question about procedure and function:
    When we use procedure and function? What is the difference between the two?

    Kind regards
    Valerie

    Published by: Valerie debonair on August 24, 2009 21:27

    When we use procedure and function?

    If you need to compute and value, good idea to use the function to return.
    If you need data DML, good idea to use the procedure...

    What is the difference between the two?

    A FUNCTION is always returns a value using the return statement.
    A PROCEDURE can return one or more values through parameters or may not return at all.

  • Call the stored procedure, and bind parameters by name

    Hello

    I use the Oracle ODBC 12 c driver to pass values from one Interface to our database Oracle 11.2. The Interface software collects data from modbus protocoll and calls a stored procedure. Right now my syntax to call the stored procedure looks like this:

    CALL procedure-name ('STRING', 'Timestamp as String', numValue1);

    It works very well. Now, I have to add a default setting to my procedure. To stay flexible to make other changes, I want to call the procedure and bind the parameters by name. Release 10.2.0.1.0 ISC ODBC Notes:

    Added support for the named parameter, binding the parameters by name. ODBC Oracle driver now allows the application to specify the parameters of a stored procedure by name, in the procedure call. Named parameters are to be used in calls to stored procedures and should not be used in other SQL statements.

    So, it shouldn't be a problem to use named notation, but how do I do this in ODBC? I tried like this, but oracle returns an ora-00936 error of missing expression:

    call procedure-name (paramName1 = > 'STRING',= paramName2 > 'Timestamp as String',paramName3 = > numValue1).


    Thank you for your help.

    Finally, I was able to find the error. The syntax of the statement was very good. The problem was caused by another declaration that I edited before and the error has not attracted Attention immediately.

    Thanks for reading and looking for an answer.

  • Calling a procedure with IN and OUT parameters

    Hello

    I usually call my procedures using the following

    declare the variable msg_erreur varchar2 (50)
    exec simple_msg('ABC,'ABC','ABC',:error_msg);

    CREATE OR REPLACE PROCEDURE SIMPLE_MSG)
    ID IN VARCHAR2,
    URL IN VARCHAR2,
    THE LIST IN VARCHAR2,
    MSG_ERREUR OUT VARCHAR2

    *************************************************************
    Now my question is, I try to call a proc that has IN OUT parameters. Can someone guide me on how to call the d.a. thanks

    CREATE OR REPLACE PROCEDURE SIMPLE_MSG)
    ID IN VARCHAR2,
    URL IN VARCHAR2,
    THE LIST IN VARCHAR2,
    NAME IN VARCHAR OUT,
    MSG_ERREUR OUT VARCHAR2

    Hello

    OUTSIDE of the parameters are passed as OUT was: you must pass a variable.

    If you set the IN OUT parameter before calling the procedure, and then either
    (a) use the separate EXEC command:

    EXEC  :name := 'Original name';
    EXEC  simple_msg ('ABC', 'ABC', 'ABC', :name, :error_msg);
    

    or

    (b) use a PL/SQL anonymous block, like this:

    BEGIN
        :name := 'Original name';
        simple_msg ('ABC', 'ABC', 'ABC', :name, :error_msg);
    END;
    /
    

    The parameter can be either a variable binding (as illustrated above), or a local variable (which may only be used in the block).

  • How to call the procedure on the page of the ofa

    Hi all

    I have a button.when I click this button need to call the procedure and should return the values.i tried with below code.am is error.i am passing two parameters to the procedure.please suggest me where I made a mistake in the code.

    error while calling procedure.PNG

    code in am

    -------------

    public String calprorate (String laseid, String billingid)

    {

    OADBTransaction oadbtransaction = (OADBTransaction) getTransaction ();

    OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl) getTransaction ();

    String retValues;

    System.out.println ("number:" + laseid);

    StringBuffer str = new StringBuffer();

    Str.Append ("BEGIN");

    Str.Append (LEASE_PRORATE_PKG ".") LEASE_PRORATE_PROC1 (»);

    Str.Append ("p_lease_id = >: 1");

    Str.Append ("p_billing_id = >: 2");

    Str.Append ("P_PRORATE = >: 3");

    System.out.println ("params");

    Str.Append (»); «) ;

    Str.Append ("END");

    System.out.println ("End");

    OracleCallableStatement oraclecallablestatement =

    (OracleCallableStatement) oadbtransaction.createCallableStatement (str.toString (), 1);

    System.out.println ("Oracle");

    try {}

    oraclecallablestatement.setString(1,laseid);

    oraclecallablestatement.setString(2,billingid);

    oraclecallablestatement.setInt (1, Integer.parseInt (laseid));

    oraclecallablestatement.setInt (2, Integer.parseInt (billingid));

    System.out.println ("param");

    oraclecallablestatement.registerOutParameter (3, Types.VARCHAR);

    System.out.println("3");

    oraclecallablestatement. Execute();

    System.out.println ("exe");

    retValues = oraclecallablestatement.getString (3);

    }

    catch (System.Exception e)

    {

    System.out.println ("delivery");

    throw OAException.wrapperException (e);

    }

    Return retValues;

    System.out.println ("End");

    }

    code co:

    -------------

    If (pageContext.getParameter ("Calc")! = null) {}

    Vo1 OAViewObject = (OAViewObject) am.findViewObject ("AddonBillingVO");

    System.out.println ("VO");

    {if(VO1!=null)}

    CNT int = vo1.getRowCount ();

    System.out.println ("count:" + cnt);

    If (cnt > 0)

    {

    RowSetIterator rs = vo1.createRowSetIterator("empIterator");

    System.out.println ("EMP");

    If (rs! = null)

    {

    While (rs.hasNext ())

    {

    AddonBillingVORowImpl line = rs.next ((AddonBillingVORowImpl));

    System.out.println ("impl");

    If (line! = null)

    {

    String laseid = row.getAttribute("LeaseId").toString ();

    System.out.println (laseid);

    String billingid = row.getAttribute("AddonBillingId").toString ();

    [Serializable] param = {}

    laseid, billingid

    };

    String newupc = (String) am.invokeMethod ("calprorate", param);

    }

    }

    Khalil.

    You can paste your spec procedure here?

    Also see: Oracle tips of Johny: OAF: sample code to call the PL/SQL of OA Framework procedure

  • Calling a procedure that returns a cursor in a procedure

    Hello
    I have two stored procedures. They both return a cursor as output variables. However, I have another stored procedure that calls these procedures and return their results once again an output variable. I know that sounds strange to want to do something like this, but how can I do this?

    Mikhail says:

    My first procedure returns a cursor. But the cursor is opened on one condition. Like, if PARAM1 = 1 THEN OPEN cursor_1 to SELECT... OTHERWISE, OPEN CURSOR_1 TO SELECT... And the second slider has the same structure. The thing is in the two procedures if I declare that a single CURSOR_1 IN OUT parameter that the procedure will not work. So in both entities, I have two variables IN OUT SYS_REFCURSOR: c1 and c2. Then, in the third procedure I first call the first procedure, then the second. How can I write my third procedure in order to obtain the result two procedures United?

    Why the appellant (3rd procedure) need to have 2 ref Cursor? How will the appellant to "unite" the sliders?

    The actual data, a power of work must be done inside sliders. Not in PL/SQL or other languages. The SQL language is a very powerful and flexible language.

    So if the SQL 2 data sets (or more) must be "United", then you should not use the 3rd procedure and PL/SQL code to do. Should use you 2 sliders.

    You should watch this by using SQL only. The 2 sets of data can be merged, joined, union'ed. You can determine the intersection. You can determine the difference (with a negative sign). It can be rotated. It can be aggregated. It can be cube' ed. Etc.

    This SQL will then be used as a single slider and a unique reference cursor handle will be used to consume the output of the cursor.

    The basic rule to develop Oracle applications is simple. Optimize SQL. Minimize the PL/SQL.

    Use the SQL language to the data of the crisis. No PL/SQL.

  • call another proc and passing the values in the exception block

    Hello
    I'm trying to call the procedure another passing values in the exception block... but I couldn't m figure out how would the values in the exception block
    create or replace procedure test_proc 
    is 
       cursor test_cur is 
         select update_dt from test_tbl;   
         
         test_rec test_cur%rowtype;
    
        begin
            for test_rec in test_cur
            loop
                begin 
                    insert into test_tbl values (test_rec.update_dt);
                    commit;
                    exception 
                       when others then
                         rollback;
                    --      test_proc2(update_dt)       --     want to call another procedure and want to pass that update_dt here ; this process will insert the update_dt into the message table    
                       commit; 
                     
            end loop;  
            
        end;
         
     
    
    My question is how do i pass value(update_dt) into the exception block or do i need to create any varaible ?? any idea 
    Thank you very much!!

    BTW, you can still use SQL % BULK_EXCEPTIONS even if you don't use EXCEPTION to LOG. You just can't use ORA-24381, since it will not be raised. Using SO many OTHER instead. And of course, there will be only one element in SQL % BULK_EXCEPTIONS:

    SQL> CREATE TABLE emp_temp AS SELECT * FROM emp;
    
    Table created.
    
    SQL> DECLARE
      2     TYPE empno_tab IS TABLE OF emp.empno%TYPE;
      3     emp_sr empno_tab;
      4     errors NUMBER;
      5     dml_errors EXCEPTION;
      6     PRAGMA EXCEPTION_INIT(dml_errors, -24381);
      7  BEGIN
      8     SELECT empno BULK COLLECT INTO emp_sr FROM emp_temp;
      9       FORALL i IN emp_sr.FIRST..emp_sr.LAST --SAVE EXCEPTIONS
     10         UPDATE emp_temp SET job = job || '_SR'
     11            WHERE emp_sr(i) = emp_temp.empno;
     12  EXCEPTION
     13    WHEN OTHERS THEN -- Now we figure out what failed and why.
     14     errors := SQL%BULK_EXCEPTIONS.COUNT;
     15     DBMS_OUTPUT.PUT_LINE('Number of statements that failed: ' || errors);
     16     FOR i IN 1..errors LOOP
     17        DBMS_OUTPUT.PUT_LINE('Error #' || i || ' occurred during '||
     18           'iteration #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX);
     19            DBMS_OUTPUT.PUT_LINE('Error message is ' ||
     20            SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
     21     END LOOP;
     22  END;
     23  /
    Number of statements that failed: 1
    Error #1 occurred during iteration #2
    Error message is ORA-12899: value too large for column "SCOTT"."EMP_TEMP"."JOB"
    (actual: 11, maximum: 9)
    
    PL/SQL procedure successfully completed.
    
    SQL> DROP TABLE emp_temp;
    
    Table dropped.
    
    SQL> 
    

    SY.

  • Can we put procedure in a function?

    Can we put procedure in a function?

    Hello

    If you mant to say have a procedural code in a function, you can do it, you can have a block of code in a function or if you want to call a procedure in a function you can call it.
    Have you tried to create a Package?

    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/packages.htm

    Thank you

  • Procedure and settings

    Could someone post an example or a link on how to call a procedure and to pass a procedure, and how the procedure receives this settings?

    Thanks in advance

    Demos IN, OUT and ON the use of the parameter found in the demos in the Morgan Library in www.psoug.org. Search for STORED PROCEDURES.

  • Case function can be used as a parameter when calling a procedure, please advise...

    Case function can be used as a parameter when calling a procedure, please notify

    The daily procedure is called with the parameter 3 following one of the parameters using a function box between them as shown below.

    Daily_Ins (c1.p_mtrid, c1.p_UOM CASE WHEN "KWH" THEN 1 ELSIF 'KW' THEN 2 END, v_dateHold);

    In my opinion, using decode is illegal, so I think that I cannot say something like :

    Daily_Ins (c1.p_mtrid, ( decode c1.p_UOM, "KWH", 1 'KW', 2), v_dateHold);

    I think I just found something on the net

    SQL > DECLARE

    2 wages NUMBER: = 20000;

    3 employee_id NUMBER: 36325 =;

    4

    5 PROCEDURE give_bonus (emp_id in NUMBER, bonus_amt number) IS

    6 BEGIN

    7 DBMS_OUTPUT. Put_line (emp_id);

    8 DBMS_OUTPUT. Put_line (bonus_amt);

    9 END;

    10

    BEGIN 11

    12 give_bonus (employe_id,

    13 CASES

    14 salary when > = 10000 AND salary<=20000 then="">

    15. WHAT salary > 20000 AND salary<= 40000="" then="">

    16. WHAT > 40000 salary THEN 500

    17 0 OTHERWISE

    18 END);

    END 19;

    20.

    PL/SQL procedure successfully completed.

  • two related issues: to call the stored procedure and passing in an array of elements using htmldb_Get

    I need to save items of ApEx generated dynamically via AJAX.  I use the APEX_ITEM API to generate the elements.  At runtime, I have no idea how much of elements are generated on the page, but I know that they're all separate and discreet 'name' attributes, i.e. f01, f02, f03, etc..  As a basic example, if I have to generate a selection list, I know that the parameter "p_idx" of the APEX_ITEM call is to say '3', so select all lists that get generated have a "name" attribute in "f03" DOM, all text elements will be "f01", etc.

    I want to record these data in the database using AJAX.  It is common to call the javascript htmldb_Get function that is standard for the use of an application process, but I am interested in the use of the rarely called upon 'internal' and queryString"options of this javascript function so that I can build the query string to the fly according to what is on the DOM when it tries to save the data they have entered into these items generated by APEX_ITEM.  Someone at - there are good examples of the use of the 'procedure' and 'queryString' the javascript htmldb_Get function parameters?

    I have found a handful of some blogs, messages, etc. online linked to this, but just for most people regurgitate the documentation.  I found this post (https://forums.oracle.com/thread/2549237), which has had a glimpse of hope to move from a table (which is something I need) as a parameter, but as someone in their right mind would check this before you go this route.

    Shane.

    ApEx 4.2.1

    Shane

    Since you mention that you are on 4.2 APEX I advise to use apex.server.process which is replacing the htmldb_Get officially undocumented documented.

    In the literature, it is that the first parameter is the ajaxidentifier but it's actually the name of the process.

    The data object would be something like

    var lData ={f01 : get_value_array('f01')}
    

    Where is get_value_array

    function get_value_array(pColumnName) {
      var l_values =[];
      apex.jQuery('[name="'+pColumnName+'"]').each(
       function(){
        var l_value;
        l_value = apex.item(this.id).getValue();
        l_values.push(l_value);
       }
      );
      return l_values
    }
    

    For an example see this demo.

    Nicolette

  • Function procedures and triggers

    Sorry to ask this question,


    In oracle. We use the function of triggers and procedures.

    for example:

    If we wrote a trigger for a table. It fires both to manipulate the table. (database table contains data and database also contains triggers the same function, procedure).

    but my questions?: is

    In my database, I have not kept only tables. No trigger, no function, no procedures. and


    I kept this triggers, function, procedures of data instead of I want kept this function, triggers, procedures in layers of logic (intermediate level)

    is it possible? .


    If yes means, how to write or where to write? Please help me, otherwise send guidance documents or the blog releated to it.

    Hi Marie Laura,.
    If you want to call the procedures used the following link
    http://www.techartifact.com/blogs/2009/04/procedure-calling-in-Oracle-ADF.html

    for my statement

    all logic, triggers can be done using java classes that is attached with the business objects.

    This means... in the procedure, you have selection, insertion, updating, and deleting of records in a table...
    So map complete things as an object adf...

    Tables-> object EO
    Select the statement - > VO objects
    Insert, update, deletion - crud-> dodML() operation, the remove() method in EntityImpl
    commit - dbTransaction.commit)
    other features... are also can be mapped to specific files, and can be represented as objects adf...

    That's what I wanted to say, convert the whole procedure into objects of the adf and work on...
    I hope you understand now...

  • differences between the procedures and functions.

    a little confusing... differences between procedures and functions...

    1. a function returns only the unique value? can't return us multiple values?

    2. can we use clause of 'back' and 'out' parameter at the same time in the same function

    Thank you

    Hello

    Simply create a TYPE for strong cursors, returning the specified columns. For genereic, or the low sliders, there is a TYPE integrated, namely SYS_REFCURSOR.

    Try this:

    CREATE OR REPLACE function test_f(p_DEPTNO  in emp.DEPTNO%type)
      return SYS_REFCURSOR
      as
         REF_C     SYS_REFCURSOR;
    BEGIN
         OPEN  REF_C  FOR   SELECT  *
                             FROM    EMP
                      WHERE   DEPTNO = P_DEPTNO;
         RETURN REF_C;
    END;
    

    You don't want to close the cursor service.

    Always format your code.

Maybe you are looking for

  • Change browser.newtab.url does not work

    Hello Installed some crapware today and have trovi.com as the page by default when I open a new tab. It makes me incredibly angry. What is even worse, he has changed the browser.newtab.url and when I removed the config it STILL load the same page. I

  • The iPhone 6 can be stored on HD radio tag information?

    Recently bought an Alpine car stereo for my car, which offers a feature of marking on the HD radio broadcasts (to store artist information, album, and song for research/purchase at a later date). The info is supposed to be transferred to a connected

  • cannot get mail out with comcast using windows 7, outlook 2010.

    I use an e-mail address that is not comcast.  That is, it is from another server.  However, I was able to use it before when I had an old computer.  Do I need to use different passwords for incoming and outgoing like my incoming mail very much. My em

  • Hp psc 1210v all-in-one has the possibility to print back to the front?

    My hp psc 1210v all-in-one still works and it makes me crazy that this printer is able to print back to the front. I'm also disturbed that there is no software print double don't face as with the new hp printers. Is it just me or this printer would b

  • cannot access windows install... or such

    Why are there pages and pages of "try this", try this"and none of them work unless maybe the provided guru corrects do... not for beginners... Help us Dummies. Oh Yes... I am running Windows7 64-bit SP1. And for Windows technitions be envolved in the