PL/SQL function with update

Hi can someone help me!

I have this code is a function, but do not work

CREATE or replace FUNCTION f2 (sucursala varchar,socioa number,folioa number) RETURN number IS PRAGMA AUTONOMOUS_TRANSACTION; id_mov number; ca number; sa number; int_m number; tipo varchar(400); sucu varchar(400); fech date; cursor movimientos IS select id,sucursal,cantidad,interes,movimiento,fecha from det_pzo_fijo_saldos where sucursal=sucursala and socio=socioa and folio=folioa and movimiento in ('DEPOSITO NORMAL','VENCIMIENTO CON RENOVACION DE CAPITAL E INTERES','VENCIMIENTO CON RENOVACION DE CAPITAL E INTERES MAS INCREMENTO','CANCELACION DE DEPOSITO','VENCIMIENTO SIN RENOVACION','VENCIMIENTO CON RENOVACION DE CAPITAL MAS INCREMENTO','VENCIMIENTO CON RENOVACION POR MENOS DEL CAPITAL','RETIRO DE INTERESES','VENCIMIENTO CON RENOVACION DE CAPITAL','CAPITALIZACION DE INTERESES') order by fecha,id; BEGIN open movimientos; sa:=0; fetch movimientos into id_mov,sucu,ca,int_m,tipo,fech; WHILE movimientos%found loop begin if tipo in ('DEPOSITO NORMAL', 'VENCIMIENTO CON RENOVACION DE CAPITAL E INTERES', 'VENCIMIENTO CON RENOVACION DE CAPITAL E INTERES MAS INCREMENTO') then sa:=sa+ca+int_m; else if tipo in ('CANCELACION DE DEPOSITO', 'VENCIMIENTO SIN RENOVACION', 'VENCIMIENTO CON RENOVACION DE CAPITAL MAS INCREMENTO', 'VENCIMIENTO CON RENOVACION POR MENOS DEL CAPITAL') then sa:=sa+ca; else if tipo in ('RETIRO DE INTERESES', 'VENCIMIENTO CON RENOVACION DE CAPITAL') then sa:=sa; else if tipo in ('CAPITALIZACION DE INTERESES') then if sucu in ('MATRIZ') then if (fech <= '03/10/2007') then sa:=sa+ca+int_m; end if; if (fech >= '04/10/2007') then sa:=sa; end if; end if; if sucu in ('OBRERA') then if (fech <= '18/10/2007') then sa:=sa+ca+int_m; end if; if (fech >= '19/10/2007') then sa:=sa; end if; end if; end if;  end if;  end if;  end if; update det_pzo_fijo_saldos set saldo = sa where id=id_mov; COMMIT; EXCEPTION WHEN OTHERS THEN ROLLBACK; end; end loop; close movimientos; return sa; END; 

In the anointing errors show don't show me anything so I don't know what the problem

Thank you!!!

Rewrite your function in a procedure with three inputs and one output parameter.

Do not commit in your program, leave it to the caller (client side).

You miss a fetch statement in your loop (put it before "END LOOP");

Tags: Database

Similar Questions

  • PL/SQL-function with variable number of parameters

    Hello

    I want to write an INLIKE function that combines the functions of the po and AS operator.
    I want to call it that:

    SELECT 1 in the table where INLIKE (column, Motif1, pattern2,...) with a variable count of bosses.

    Is there a possibility the java selection button (String... stringArray) to declare or to make, I have to define a function with multiple parameters and default values?

    With greetings

    Florian

    You don't need to write a function no., you can use regular expressions REGEXP_LIKE...

    for example to find all the rows that have % ED % or % LY in them...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'FRED IS SCARED' as txt from dual union all
      2             select 'EDWARD IS HAPPY' from dual union all
      3             select 'BOB AND TIM ARE ASLEEP' from dual union all
      4             select 'JIM AND SALLY DO NOT CARE' from dual)
      5  --
      6  -- END OF TEST DATA
      7  --
      8  select *
      9  from t
     10* where regexp_like(txt, '(ED|LY)')
    SQL> /
    
    TXT
    -------------------------
    FRED IS SCARED
    EDWARD IS HAPPY
    JIM AND SALLY DO NOT CARE
    
  • Problems of execution of a SQL function with a variable in the WHERE clause

    Hello world!

    I have programmed a function that returns a boolean value based on the result of the SQL. It's the function:

    FUNCTION existe_secuencial (seq_name VARCHAR2) RETURN AS BOOLEAN

    cursor c2 is SELECT FROM all_sequences WHERE upper (sequence_name) = sequence_name' | seq_name | ' ;

    BEGIN

    OPEN c2;

    DBMS_OUTPUT. Put_line (nombre_seq);

    Get c2 INTO kk;

    If c2% NOTFOUND = True THEN

    RETURNS false;

    on the other

    RETURNS true;

    end if;

    END existe_secuencial;

    And I give the floor to the function of a procedure in this way:

    IF existe_secuencial ("SEQ_ARQUETA") = True THEN

    DBMS_OUTPUT. Put_line ('exists');

    ON THE OTHER

    DBMS_OUTPUT. Put_line ("' NOT exists");

    END IF;

    The probrem that this SQL is forced to return results because this sequence exists in the comic book, but is not, return me the FALSE value. What makes me mad is that if I change the second line of the function in this way:

    > > cursor c2 is SELECT FROM all_sequences WHERE upper (sequence_name) sequence_name ="SEQ_ARQUETA";

    It works find and return of sequence existing (real)

    Can someone help me please, I'm quite desperate to find what is the problem with that because I do not understand why if I built the slider with a variable returns no results so that if I do write it works...

    Thanks in advance!

    Itziar

    Frame you your variable in quotes, which makes the string literal ' |. ' seq_name | "rather than the content of the variable.

    I think that something like this would be an improvement.

    function existe_secuencial (seq_name VARCHAR2) return a Boolean value as

    number of exist_check: = 0;

    Start

    Start

    Select 1

    in exist_check

    of all_sequences

    where upper (sequence_name) = upper (seq_name);

    exception

    When no_data_found then

    null;

    end;

    return (exist_check = 1);

    end existe_secuencial;

  • I had problem with update

    Hi experts,

    I play with the parameterizsed slider, I did the next thing.

    It works. If give empid it retrieves the emmployee is belongs to which Department.
     CREATE OR REPLACE FUNCTION FUNC_SOMETHING_EMPLOYEE(EMPID VARCHAR2)
    RETURN VARCHAR2 IS
    RES VARCHAR2(200);
    CURSOR C1 IS SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID=EMPID;
    CURSOR C2(DID NUMBER) IS SELECT * FROM DEPARTMENTS WHERE DEPARTMENT_ID = DID;
    BEGIN
    FOR CR1 IN C1
    LOOP
    FOR CR2 IN C2(CR1.DEPARTMENT_ID)
    LOOP
    RES := 'EMPLOYEE ID : ' ||CR1.EMPLOYEE_ID|| 'DEPARTMENT NAME : '||cr2.DEPARTMENT_NAME;
    END LOOP;
    END LOOP;
    RETURN RES;
    END;
    /
    but I want to update the given employee sal:

    but throw an error.
    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE OR REPLACE FUNCTION FUNC_SOMETHING_EMPLOYEE(EMPID VARCHAR2 , amt number)
      2  RETURN VARCHAR2 IS
      3  RES VARCHAR2(200);
      4  CURSOR C1 IS SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID=EMPID;
      5  CURSOR C2(DID NUMBER) IS SELECT * FROM DEPARTMENTS WHERE DEPARTMENT_ID = DID;
      6  BEGIN
      7  FOR CR1 IN C1
      8  LOOP
      9  FOR CR2 IN C2(CR1.DEPARTMENT_ID)
     10  LOOP
     11  update EMPLOYEES set salary = cr1.salary*amt where EMPLOYEE_ID = cr1.EMPLOYEE_ID ;
     12  RES := cr1.salary;
     13  END LOOP;
     14  END LOOP;
     15  RETURN RES;
     16* END;
    SQL> /
    
    Function created.
    
    SQL> select FUNC_SOMETHING_EMPLOYEE('1981',22) from dual;
    select FUNC_SOMETHING_EMPLOYEE('1981',22) from dual
           *
    ERROR at line 1:
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "HR.FUNC_SOMETHING_EMPLOYEE", line 11
    can someone explain what is happening. ?

    Oracle db10g

    Sorry peoples everything by pasting the corresponding condition is left empty.

    I think I see your confusion.

    There are two different languages in question here, SQL and PL/SQL.

    The SQL language is a non-procedural language whose role is to define data structures (DDL) and manipulate data (DML). The language also contains transaction control statements (commit, rollback, backup point) and a few other buildings are not able to qualify so perfectly, but that can be ignored for now.

    The PL/SQL language is a complete language of proceedings (which is the bit of the name PL) which is based on the ADA language and takes in charge the SQL language it contains.

    You can write PL/SQL packages, procedures functions that do not contain any SQL at all if you wish.

    The power of PL/SQL, however, is the way it integrates SQL it contains.

    In your example, you have written a PL/SQL function that updates some data using a SQL statement. You can call this function to other procedures - PL/SQL and functions you have shown an example calling in an anonymous PL/SQL block, and it worked very well.

    You can also use a PL/SQL function (but not a procedure) in a SQL statement, but there are restrictions on what the function is allowed to do in this context. In particular, as you have discovered, no update! These are just the 'rules' and they are documented in detail.

    Do not be offended when people write 'it's a matter of doc' and give a reference, because this document contains the facts better and more completely that could be written here. It is best to read the documentation here written explanations that are only partially correct (I wrote some of these myself).

    There are any other questions where the answers are not so cut, and this is where you can see different responses. They reflect the original writers and experience... right or wrong, just different approaches to situations.

    Then read a lot, try things and then ask a lot of questions about things you don't know.

    Dave

  • Problem inserting new line in a VO with SQL functions and subqueries

    Hello

    I use JDeveloper 10.1.3.4 and and stuck with insertion of a new line when the values to insert into some fields of the new line are returns of SQL functions and subqueries.

    At the sqlplus prompt, the following sql statement is tested and developed successfully:
    insert into VALIDATIONS values (
       '111223333', 'JANE', 'DOE',
       SYSDATE,
       (select to_char(sysdate, 'yymmdd') from dual)||
       (select to_char(count(TRANSACTION_DATE)+1,'fm0999') from VALIDATIONS
          where trunc(TRANSACTION_DATE) = to_char(sysdate))
    );
    Note that the values for the fields of 4th and 5th are returns of subqueries and SQL functions.

    Ideally, it would be simple to assemble a SQL and executed him as he did to the old way of servlet:
    String sql = "insert into VALIDATIONS values ('" + id + "', '" + firstName + "', '" + lastName + "', SYSDATE, (select to_char( ......)))";
    statement.executeUpdate(sql);
    I'm not sure it can be done in JDeveloper, and it was not found in the developer's guide. What I found was rather:
    // 1. Find the ServiceRequests view object instance.
    ViewObject svcReqs = am.findViewObject("ServiceRequests");
    // 2. Create a new row and insert it into the row set
    Row newSvcReq = svcReqs.createRow();
    svcReqs.insertRow(newSvcReq);
    // 3. Show effect of entity object defaulting for Status attribute
    System.out.println("Status defaults to: "+newSvcReq.getAttribute("Status"));
    // 4. Set values for some of the required attributes
    newSvcReq.setAttribute("CreatedBy",308); // Nancy Greenberg (user)
    Date now = new Date(new Timestamp(System.currentTimeMillis()));
    newSvcReq.setAttribute("RequestDate",now);
    newSvcReq.setAttribute("ProdId",119); // Ice Maker
    newSvcReq.setAttribute("ProblemDescription","Cubes melt immediately");
    // 5. Commit the transaction
    am.getTransaction().commit();
    In my case, it would be OK for the first three fields as shown below (in the code of transactionsRecords is a display object). But what about the 4th and 5th fields?
    Row newTransaction = transactionsRecords.createRow();
    transactionsRecords.insertRow(newTransaction);
    newTransaction.setAttribute("StudentId", id);
    newTransaction.setAttribute("FirstName", firstName);
    newTransaction.setAttribute("LastName", lastName);
    
    newTransaction.setAttribute("TransactionDate", <how to put "SYSDATE" here?>);
    newTransaction.setAttribute("ConfirmNumber", <how to put subqueries here?>);
    A big thank you to those who know or have experience before!


    Newman

    Newman,
    You can do this via a procedure call. This technique is described here
    I guess you can't do this directly in the EO or VO.
    You can do it the old way to create a prepared directly query and call it as you described. To get the declaration use getDBTransaction () .createPreparedStatement (...) method available in the module of your application.
    Be aware of the implications using the given solution. The framework doesn't know anything of what you are doing. So to see the changes that you used to update the tables that you change.

    Timo

  • How can I call a function with parameter out of sql

    Hello world
    I'm calling a Sql statement function and I get this error ORA-06572: XX function has arguments.

    can you offer any solution on this workaround.

    Thank you

    Hello

    Sorry, you cannot call functions with OUT arguments (or arguments, but I'll just say in the future) SQL statements.
    This is one of the reasons why many people avoid having arguments in functions.
    THE arguments are never optional. If the function expected of them, you must pass to them.

    Depending on your needs, you can write a Wrapper function that has no arguments.
    For example, if you want to call this function:

    fun1 ( in_out_str      IN OUT  VARCHAR2
         , in_num          IN      NUMBER
         )
    RETURN  NUMBER ...
    

    you don't need really the value changed to in_out_str, then you can write a function like this:

    fun1_wrapper ( in_str          IN      VARCHAR2
                   , in_num          IN      NUMBER
                   )
    RETURN  NUMBER
    IS
        in_str2     VARCHAR2 (32767)  := in_str;
    BEGIN
        RETURN  fun1 ( in_str2
                       , in_num
               );
    END  fun1_wrapper;
    

    You can use fun1_wrapper in a SQL statement, even if you cannot use fun1 in the same statement.

    Published by: Frank Kulash on February 27, 2013 09:42

  • Report of update SQL query with line selector. Update process.

    I have a report of update SQL query with the selectors in line.
    How to identify line selector in a process update on the page.

    I want to update some columns with a value of an area of selection on the page.

    With the help of the base:

    UPDATE table_name
    SET Column1 = value
    WHERE some_column = some_value

    I would need to do:

    UPDATE table_name
    SET column1 =: P1_select
    WHERE [line selector] =?

    Now sure how to identify [line selector] and/or validate it is checked.
    Thank you
    Bob

    Identify the name of the checkbox of the source of the page element, it should be of the fxx format (f01, f02... f50).
    Suppose that we f01.

    for i in 1 .. apex_application.g_f01.count
    loop
      UPDATE CONTRACTS
      SET SIP_LOAD_FLAG = :P16_STATUS
      where  =  apex_application.g_f01(i); --i'th checked record' primary key
    end loop;
    
  • Replace the trivial calculation with PL/SQL function?

    I have several queries that are full day based on a date field differences Oracle - for example, something along the line of computing:

    Select
    Customer
    , trunc (current_date) - trunc (payment_date)
    Of
    (select 'Fred', to_date ('2009-06-01 07:05 ',' yyyy-mm-dd hh24:mi:ss') as payment_date of all the double union)
    Select 'Barney', to_date ('01-07-2009 15:15:15 ',' yyyy-mm-dd hh24:mi:ss') of double
    )
    -- ------------------------------------
    --
    -Customer Account_Age
    -- --------- -----------
    -Fred 49
    -Barney 19

    I'm a developer who is now Advisor we use a user defined PL/SQL function rather than the difference of these functions TRUNC. Who goes against the grain for me. In MS SQL Server Transact SQL forums, I would recommend almost never replace something trivial with a user defined function because the UDF is called for each row returned by the query and adds overhead to the application.

    The same kind of logic applies to the UDF Oracle? Is it a good idea to replace trivial calculations like this with the UDF?


    Kent Waldrop

    If you can do it in sql, avoid any need for a function.

    SS

  • Filling point with the body of the pl/sql function

    Hello

    I want to fill an item "Show as text (saves the State)" in contrast to the other 2 points.

    The source of my question is:
    -Only when the current...
    -Body of PL/SQL function
    -Term source:
    DECLARE
    v_diff NUMBER;
    BEGIN
    v_diff: =: P1_AUFWAND_TOTAL -: P1_AUFWAND_BERECHNET;
    Return v_diff;
    END;

    Now I get this error:

    ORA-06502: PL/SQL: taking oder Wertefehler: Fehler beim zu if indication Zahl von
    Error ERR-1904 unable to calculate the default item: type = body of the function...

    I tried to find the problem with the conversion to_number:
    v_diff: = to_number(':P1_AUFWAND_BERECHNET'); or
    v_diff: = to_number (': P1_AUFWAND_BERECHNET', '999G999D00');

    What's not here? It's as if I'm making a simple mistake...

    Thanks for any help,
    Roger

    If the following code does not work for you, then one of the two elements are not the numbers:

    DECLARE
       v_diff   NUMBER;
    BEGIN
       v_diff := TO_NUMBER (:p1_aufwand_total)
                 - TO_NUMBER (:p1_aufwand_berechnet);
       RETURN v_diff;
    EXCEPTION
       WHEN OTHERS
       THEN
          RETURN SQLERRM;
    END;
    

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    -------------------------------------------------------------------

  • PL/SQL function to calculate the non-working days

    Hello

    I have the following pl/sql function which generates a number of days between two selected dates (i.e. excluding weekends). However, I also need to exclude specific holidays - day of Christmas etc. These holiday dates are stored in a table in our database (11 GR 2) called "HOLIDAY".

    How can I integrate the holidays which is held in the table of holidays in the following query to exclude these dates as well? I know how to write a separate funtion pl/sql for a number of days between two dates using SELECT... BUT I can't work out how to bring together them in a single query.

    Could someone show me how with the pl/sql / dates below please?

    Example of HOLIDAY table below.

    Thank you!

    TP

    create or replace
    function WORKING_DAYS (pi_start_date in date, pi_end_date in date) return integer
    
    is
    
    v_start_date date :=pi_start_date;
    v_end_date date:=pi_end_date;
    v_count integer:=0;
    
    begin
    
    while v_start_date <= v_end_date
          loop
                            if to_char(v_start_date,'D') not in ('6','7')                    
                            then
                            v_count := v_count+1;                       
                            end if;
                           
                    v_start_date:=v_start_date+1;
                   
          end loop;
         
    return v_count;
    
    end;
    
    

    (select '10-Apr-2013' as NWD from dual union all
    select '06-May-2013' from dual union all
    select '27-May-2013' from dual union all
    select '26-Aug-2013' from dual union all
    select '26-Dec-2013' from dual union all
    select '25-Dec-2013' from dual union all
    select '01-Jan-2014' from dual union all
    select '18-Apr-2014' from dual union all
    select '21-Apr-2014' from dual union all
    select '05-May-2014' from dual union all
    select '26-May-2014' from dual union all
    select '25-Aug-2014' from dual union all
    select '25-Dec-2014' from dual union all
    select '26-Dec-2014' from dual) HOLIDAYS
    

    Hello

    the link is on MOSC, not OTN... Here's a copy:

    This function calculates the number of days between two dates, ignoring weekends and holidays (if requested and if the holidays are stored in a table)

    I give an example of table 'public_holiday' with sample data, but users must ensure that their table contains the relevant data (all holidays within the maximum range of use of the service)

    CREATE TABLE public_holiday (calendar_day, DATE, text VARCHAR2 (30));

    FUNCTION to CREATE or REPLACE nb_days (p_date_from IN DATE

    p_date_to DATE by DEFAULT TRUNC (sysdate)

    , p_public_holidays in CHAR DEFAULT 'Y '.

    ) RETURN NUMBER

    DEFINE AUTHID

    AS

    /*********************************************************************/

    / * Author: Bruno Vroman * /.

    / * Created: 23-AUG-2012 * /.

    / * Last updated: 23-AUG-2012 * /.

    / * Object: to calculate the number of days between 2 dates, to the exclusion of * /.

    / * Saturday and Sunday, but also "holidays" If the * /.

    / * argument 'p_public_holidays' = 'Y ' * /.

    / * Support: p_date_from<= p_date_to                             ="">

    / * component ' hour min dry "ignored (just counting days) * /.

    /* First step:                                                       */

    / * the calendar days between 2 days * /.

    / Remove 2 days for each "week" and 0 or 1 extra day * /.

    / * function to a condition "complex" mix day of first week * /.

    / * and the number of days when full remaining weeks are removed * /.

    / * (set up once for all, for example if there is 3 days and the * /)

    (/ * first day is a Thursday, there is 1 "Sat/Sun" to subtract) * /.

    / * Second step: If 'p_public_holidays' = 'Y': other * /.

    / * days, do not count holidays.                         */

    / Holiday everyday are defined in a table "public_holiday" * /.

    / * Note: there may be holidays defined on Saturday/Sunday.       */

    /*********************************************************************/

    l_result NUMBER;

    l_from DATE;

    l_to DATE;

    l_case tank (4);

    BEGIN

    l_from: = TRUNC (p_date_from);

    l_to: = TRUNC (p_date_to);

    l_case: = TO_CHAR (l_from, 'Dy', 'NLS_DATE_LANGUAGE = English').

    To_char (MOD (l_to - l_from + 1, 7));

    l_result: = l_to - l_from + 1

    -TRUNC ((l_to-l_from + 1) / 7) * 2

    -CASE

    WHEN l_case IN ('Mon6', 'Tue5', 'Wed4', 'Thu3', 'Fri2'

    , "Sat1", "Sun1", "Sun2', 'Sun3", "Sun4".

    , "Sun5', 'Sun6.

    )

    THEN 1

    WHEN l_case IN ('Tue6', 'Wed5', 'Wed6', 'Thu4', "Thu5"

    , 'Thu6', 'Fri3', 'Fri4', 'Fri5', 'Fri6 '.

    , "Sat2", "Sat3', 'Sat4', 'Sat5", "Sat6.

    )

    THEN 2

    0 OTHERWISE

    END

    ;

    IF SUPERIOR (p_public_holidays) = "Y".

    THEN

    SELECT l_result - COUNT (*)

    IN l_result

    OF public_holiday p

    WHERE p.calendar_day > = l_from

    AND p.calendar_day<=>

    AND SUBSTR (TO_CHAR (p.calendar_day

    , "Dy".

    'NLS_DATE_LANGUAGE = English'

    )

    , 1, 1 ) != 'S'

    ;

    END IF;

    RETURN l_result;

    EXCEPTION

    WHILE OTHERS

    THEN

    DBMS_OUTPUT. Put_line (' CTF nb_days (' |))

    To_char (p_date_from, "MON-DD-YYYY"). ', ' ||

    To_char (p_date_to, "MON-DD-YYYY"). ', ' ||

    p_public_holidays | ' ) : ' || SQLERRM

    );

    LIFT;

    END nb_days;

    /

    REM

    REM example:

    REM A) fill out the 'public_holidays '.

    REM

    TRUNCATE TABLE public_holiday;

    INSERT INTO public_holiday VALUES (DATE ' 2012-01-01', ' new year (a Sunday)');

    INSERT INTO public_holiday VALUES (DATE '' 2012-01-03, "for example");

    REM (insert other days...)

    COMMIT;

    Call the function for some pairs of dates of REM B)

    REM nb1: remove only Sat/Sun

    REM nb2: also remove holidays

    REM

    ALTER SESSION SET nls_date_format ='Dy DD-MON-YY';

    WITH some_dates AS

    (SELECT DATE ' 2011-12-29'd dual FROM

    UNION ALL SELECT DATE ' 2012-01-08' FROM dual

    UNION ALL SELECT DATE ' 2012-01-10' FROM dual

    )

    SELECT d1.d 'FROM '.

    , d2.d ' to THE '.

    , nb_days (d1.d, d2.d, ' don't) nb1

    , nb_days (d1.d, d2.d, 'Y') nb2

    OF some_dates d1

    some_dates d2

    WHERE d1.d<=>

    ORDER BY nb1, nb2, d1.d

    ;

    GO TO NB1 NB2

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

    Monday, January 8, 12 Monday, January 8, 12 0 0

    Friday, December 29, 11 Friday, December 29, 11 1 1

    Wednesday, January 10, 12 Wednesday, January 10, 12 1 1

    Monday, January 8, 12 Wednesday, January 10, 12 2 2

    Friday, December 29, 11 Monday, January 8, 12 7 6

    Friday, December 29, 11 Wednesday, January 10, 12 9 8

    Hope that this could be useful, but note that this code has not been completely tested, so check and test before you trust it (in the case of any questions, please post a comment)

    Bruno Vroman.

    Best regards

    Bruno

  • perform an immediate function with parameter out

    How to perform a function with parameter in the statement immediately execute?
    declare
       vRunFunctie   varchar2(100) := 'startfunction';
       vParmIn1      varchar2(100) := 'AAA';
       vParmIn2      varchar2(100) := 'HHH';
       vParmOut1     number;
       vParmOut2     varchar2(100);
    begin
       --
       execute immediate 'select '||vRunFunctie||'('''||vParmIn1||''','''||vParmIn2||''',:vParmOut2) from dual' into vParmOut1 using vParmOut2;
       --
       dbms_output.put_line('vParmOut1['||vParmOut1||']');
       dbms_output.put_line('vParmOut2['||vParmOut2||']');
    end;
    /
    error: ORA-06572 startfunction function has arguments

    the statement looks like this in pl/sql:
    vParmOut1 := startfunction(vParmIn1, vParmIn2, vParmOut2);
    --vParmOut1 := startfunction('AAA', 'HHH', vParmOut2);
    Thank you.
    L.

    Update:
    You are not using bind variables with your dynamic code. That is a major mistake and the #1 reason for poor database performance.
    It is a fundamental flaw in programming to design a function that includes output parameters. This is simply and plainly wrong.
    Output parameters are also not supported by the SQL language - it does not support "procedure" like code units and call methods. 
    I know that the function should not have out parameters. But its programmed that way already...

    You try something like

    declare
       vRunFunctie   varchar2(100) := 'startfunction';
       vParmIn1      varchar2(100) := 'AAA';
       vParmIn2      varchar2(100) := 'HHH';
       vParmOut1     number;
       vParmOut2     varchar2(100);
    begin
       --
       execute immediate 'begin :x := ' || vRunFunctie || '( :p1,  :p2, :vParmOut2 ); end;' using out vParmOut1, vParmIn1, vParmIn2, out vParmOut2;
       --
       dbms_output.put_line('vParmOut1['||vParmOut1||']');
       dbms_output.put_line('vParmOut2['||vParmOut2||']');
    end;
    / 
    
  • No function with name 'F_ITEMCHECK' does exist in this scope

    Hi I have an error:


    SQL > declare
    2 cursor stk_val is
    3 select prod_code, prod_desc, prod_tran bal_Stock;
    4 mProd_code prod_tran.prod_Code%type;
    prod_tran.prod_desc%type mProd_desc 5;
    mProd_qty 6 prod_tran.prod_qty%type;
    7 whole valexits;
    8 whole bal_stock;
    9 whole vquantity;
    10 whole f_itemcheck;
    Begin 11
    12 stk_val open;
    loop 13
    14 stk_val of fetch in mprod_code, mprod_desc, mprod_qty;
    15 exit when stk_val % notfound;
    16 valexits: = f_itemcheck (mprod_code);
    17 if valexits = 0 then
    18. insert into prod_mast (prod_code, prod_Desc, bal_Stock)
    19 values(mprod_code,mprod_Desc,mprod_qty);
    20 elsif valexits = 1 then
    Update 21 prod_mast
    22 set bal_stock = bal_stock + vquantity
    23 where prod_code = mprod_code;
    24 end if;
    25 end of loop;
    26 close stk_Val;
    27 end;
    28.
    Declare
    *
    ERROR on line 1:
    ORA-06550: line 3, column 34:
    PLS-00320: the declaration of the type of the expression is incomplete or incorrect
    ORA-06550: line 3, column 6:
    PL/SQL: SQL statement ignored
    ORA-06550: line 16, column 22:
    PLS-00222: no function with name 'F_ITEMCHECK' does exist in this scope
    ORA-06550: line 16, column 10:
    PL/SQL: Statement ignored

    You use f_itemcheck at the same time as a variable

    whole f_itemcheck;

    and in function:

    valexits: = f_itemcheck (mprod_code);

    But there is no function with that name...

    Max
    http://oracleitalia.WordPress.com

  • PL/SQL functions as LOV to use in another display object

    Hello

    We had a custom search to extract data from a display object and the data displayed as a Table of ADF. Now, there are few requests for searches on this report. Go see criteria and Panel request if we allow saved search. But the fields used in the research are going through a lot of logic and thus the PL/SQL functions are implemented. We used to call these functions and lists separated by commas and then divided the list into individual elements and put in the component "select options".

    The value (String) returned by the pl/sql function is something like - APAC, EMEA, NORTH AMERICA, FDA

    I am creating a LOV based on SQL-query "Select getRegions() from dual;

    Now, I want the list separated by commas to divide so that I could use this LOV in an another view and try the display criteria and saved searches.

    I tried to assign as LOV just to check and the criteria drop-down view for region displays same value as single element - "APAC, EMEA, NORTH AMERICA, LAD."

    I want it to be 4 separate - elements

    APAC

    EMEA

    NORTH AMERICA

    DVL

    Is there anyway to achieve this?

    Or better is at - it another way to do this (maybe I'm wrong)

    Thank you.

    JDev: 11.1.2.4

    Instead of a programmatic VO of PL/SQL, I found sometimes easier to write PL/SQL functions that return a table - need to CREATE a TYPE for the data items to be returned and a TYPE of TABLE IMBRIQUE tabular form of the first kind.  The function returns the type of table, and can even be a PIPElined table function.  Then I create a VO with the following text:

    SELECT * from TABLE (my_function_returning_table)

    The function can even take parameters, which you fill with variable BIND your VO.

  • Help SQL function

    Hi all

    I have a table which includes

    ID, first_name, last name and date of birth

    I want to retrieve all the records that have the same name and DOB

    for example.

    ID, first_name, last name, DOB

    1 xyz abc 01/01/2012

    hij 2 efg 15/05/2012

    3 xyz abc 01/01/2012

    4 xyz abc 01/01/2012

    so in the output of 1, 3 and 4 rows will appear only.

    can someone advise please on the appropriate SQL function

    Thanks in advance

    Hello

    One way is to use the analytical COUNT function:

    WITH got_num_rows AS

    (

    SELECT id, first_name, last_name, dob

    , COUNT (*) OVER (PARTITION BY first name

    last_name

    ,             dob

    ) AS num_rows

    FROM table_x

    )

    SELECT id, first_name, last_name, dob

    OF got_num_rows

    WHERE num_rows > 1

    ;

    The subquery is needed here, because the analytical functions are calculated after the WHERE clause has been applied.  To use the results of an anlytic function in a WHERE clause, you must calculate the function in a subquery, then you can use the results where you want (including the WHERE clause) of a Super query.

  • Calling a SQL function which has Out parameters

    Hello people,
    I don't know if it's feasible, but here's my scenrio at hand. I have a database function that accepts a few parameters AND OUTPUT parameters. I want one Out to display in my select statement parameters. Is this possible?

    Thank you

    No you can not use a function with out parameters in sql statements.

    If possible do the function of this return value, use it in select. (imean instead of the parameter, OUT out which parameter through the BACK)

    G.

Maybe you are looking for

  • is this possible?

    Here's the situation... My GF installed spyware on my phone, I would like to see if I can allow the tracking by GPS, but do not allow the follow-up... Is this possible?

  • Take pictures

    Can't find help to take pictures using my Apple Watch 2.2.1 running.

  • Satellite Pro A10 to the United Kingdom: impossible to find some drivers for XP

    Hello Just my old laptop slung and bought a 2nd hand, Satellite Pro A10 and have reformatted and installed my existing copy of XP home that uses the SP1, I managed to find all drivers I need except for the "USB Controller" and 2 instances of "Base sy

  • Upgrade of Acer Aspire 5738 G CPU and RAM?

    Hello! I want to spend the CPU and the RAM of the Aspire 5738 G. The Chipset is PM45. Common current C2D [email protected] and RAM CPU is 2x2gb Kingston DDR2 PC2-6400 to 400 MHz. I'm confused because some sources claim that he cannot be upgraded but offic

  • record the location of the screenshots

    Hi all a straight line. Lollipop on the compact z3 appears to save screenshots in the internal memory, while they went to the external card of kitkat. Can a control where the screenshots get saved to with our lolloipop versions? Thank you Gary