Create function

FUNCTION to CREATE or REPLACE add_numbers (strInteger in VARCHAR)
RETURN number
IS
CNT integer: = LENGTH (strInteger);
Number of beef (10): = strInteger;
Number of totsum (10);
BEGIN

FOR x IN 1.cnt

LOOP
buf: = SUBSTR (strInteger, x, 1);
totsum: = totsum + buf;

END LOOP;

END add_numbers;

Select double add_numbers('1952');

I will be very appreciated if someone could help me to what precedes. I expect 17 return from the function but instead I received an error ORA-06512: at "SYS." ADD_NUMBERS", line 17.
CREATE OR REPLACE FUNCTION add_numbers (strInteger IN VARCHAR)
RETURN number
IS
cnt integer := LENGTH(strInteger);
buf number (10) := strInteger;
totsum number (10);
BEGIN
totsum:=0;  -- you did not initialize totsum !!!
FOR x IN 1..cnt

LOOP
buf := SUBSTR(strInteger,x,1);
totsum := totsum + buf;

END LOOP;
return totsum;  -- you did not return the value
END add_numbers;

Tags: Database

Similar Questions

  • Create function for ODD or EVEN (NUMBER) in pls sql

    Create the function for ODD or EVEN (NUMBER) also
    If number is odd, multiply by 5
    If there is an even number, multiply it by 10;

    865253 wrote:
    Create the function for ODD or EVEN (NUMBER) also
    If number is odd, multiply by 5
    If there is an even number, multiply it by 10;

    create function fn_get_no (n_in in number) return number is
    o_num number;
    begin
    if mod(n_in,2) = 0 then
    o_num := n_in*10;
    else
    o_num := n_in*5;
    end if;
    return o_num;
    end;
    
    select fn_get_no(5) odd, fn_get_no(4) even from dual;
    ODD EVEN
    25 40 
    

    Vivek L

  • create functions (rectangular, triangle, etc.)

    I create some functions with a script.

    I found it online here:

    http://zone.NI.com/reference/en-XX/help/370858K-01/dlgdacpp/dac_packet_dlg_disp_io/hb_generator/

    can I use in my script somehow?

    I have honestly no idea what to do with this function generator, I can't find same in tiara. (I use Diadem 2014)

    Can someone help me? I just need to define rectangular and triangle works with the duration, frequency, etc.

    Thank you

    Hello

    'Funktionsgenerator '.

    Erfordert: CCIP Bundle.

    This means that you need to license al tiara with the DAC module on the left side as Script, report or ANALYSYS.

  • Error creating function.

    HII All,
    I am currently working on 10 gr 2. I'm trying to move from a column and analyze dynamically, but I met due to error. Please help me.

    Create or replace Function r_return_col
                        (
                         p_table_name          in          varchar2,
                         p_column_name          in          varchar2
                        )return varchar2
    is
    
              l_count                    number;
              l_clob                    clob;
              
              l_count_str               varchar2(32000);
              
              l_column_value          varchar2(32000);
              l_str                    clob;
              l_ret_str               clob;
    begin
              l_count_str := ' select count('||p_column_name||') ' ;
              l_count_str := l_count_str||' from      '||p_table_name ;
    
    
              execute immediate l_count_str into l_count;
              
              
              for i in 1..l_count
              loop
                   
                        
                        l_str := 'select '||p_column_name||' from ' ;
                        l_str := l_str||' ( ';
                        l_str := l_str||' select row_number() over(order by '||p_column_name||') rw,'||p_column_name||'  from '||p_table_name;
                        l_str := l_str||' ) where rw = '||i ;
              
              
                        execute immediate l_str into l_column_value;
                        
                        l_ret_str := l_column_value||','||l_column_value;
              
              
              
              end loop;
              
                   return 'select l_ret_str from dual';
              
    end;
    /
    show err;
    SQL> @D:\raghu\oracle_docs\rows_to_columns.sql
    
    Warning: Function created with compilation errors.
    
    Errors for FUNCTION R_RETURN_COL:
    
    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    34/5     PL/SQL: Statement ignored
    34/23    PLS-00382: expression is of wrong type
    Concerning
    Rambeau.

    I think the problem is the line:

    execute immediate l_str into l_column_value;
    

    run immediately makes does not work with the clob type. You must define the variable l_str as type varchar2.

    Another problem, it's your last line:

    return 'select l_ret_str from dual';
    

    You will always return the text "select l_ret_str from" dual I can't believe that's what you want. Probably you want:

    return l_ret_str;
    

    I suggest to also qualify the variable l_ret_str of type varchar2.

  • When creating function in unity of prg is a very

    Oracle forms6i
    Hai All

    I created a function using unit program I get an error

    BDP-PPU107the source of program unit must be declared as a subprogram or package

    Thanks for giving me solutions

    Thanks and greetings

    Srikkanth.M

    -IN function you can not use Declare u should have some
    Check the syntax of the basic function

    FUNCTION MyFunction RETURN number IS
     --Declare variables heree
          val number:= 0;
    BEGIN
      ---some calculations....
    
      return val; ---its a must in a function
    END;
    

    2nd
    you are missing the WHERE clause in the table dail_att

    select barcode,attend_date,intime,outtime into bar_code,bar_date,in_time,out_time from dail_att;
    

    I think that somewhere clause should come here to avoid the TOO_MANY_ROWS exception

    I assume that u is not a clear concept of PL/SQL cursors and loop check guide base PL/SQL will help you understand

    Bangoura
    [My Oracle Blog | http://baigsorcl.blogspot.com/]

  • CREATE FUNCTION, getting ORA-00942

    Trying to create the function as the user system

    create or replace
    FUNCTION get_num_roles (iUser to VARCHAR, iRole in VARCHAR) RETURN NUMBER
    IS num_roles NUMBER (11);
    BEGIN
    Select count (1) in num_roles
    of dba_role_privs;
    RETURN (num_roles);
    END;

    and obtains ORA-00942

    But:
    Select count (1) in the num_roles of dba_role_privs;
    as user system works

    info from dba_synonyms:
    OWNER SYNONYM_NAME TABLE_OWNER, TABLE_NAME
    PUBLIC DBA_ROLE_PRIVS SYS DBA_ROLE_PRIVS

    Why ORA-00942?

    Systems administrator privileges allow the selection of the DBA_ROLE_PRIVS, but creating a stored object requires a direct subsidy.

    As SYS:

    Grant select on DBA_ROLE_PRIVS to the SYSTEM;

  • The station to create function has been deleted recently? I can't create more songs on my phone stations.

    When you select the «...» ' to add songs to playlists etc. The option create a station is no longer available.  This feature has been removed?

    I have not used this feature before, but I see a command Station to start in the triple-dot for a song menu.  Is it the same or similar?

  • A class of working document for the variables... now I can't create functions on the timeline?

    Hi guys,.

    Listen I thought I was doing really good, I discovered how to store my varables in a document class, but now I find I can't use all the features on my calendar?  Is that supposed to be save me time?

    I want to have mouse event functions, can someone help out me?

    See you soon

    void

    It worked! PURE PURE JOY!

    import flash.events.MouseEvent;

    function A_wordsgo(event:MouseEvent):void

    {

    wordbook.gotoAndPlay (2);

    }

    A_button.addEventListener (MouseEvent.CLICK, A_wordsgo);

    )))))

  • Create Bluetooth earpiece function only works in some cases

    The function create a listener Bluetooth generates an ID of listener that lets wait for an incoming connection of Bluetooth. Because every time that you run a VI that contains this function, it must create a new listener ID, otherwise the block following that wait on the listener will crash.

    I found that for the listener to create function work properly the entry that the Service Description must be connected to a control element. If its connected to a constant run only once, then creating a new id of the listener, but she keep this id indefinitely. In this case, you will need to close all the screws and reopen to be able to run the function again.

    (See attached VI for an example.)

    Can someone tell me, why is this? Is there a difference in the compilation/execution screw using controls instead of constants?

    Thank you!

    I could reproduce the error. I presented a report to R & D. I'll let you know when I get a response from them.

    For now, you can try using a control instead of a constant and make it invisible in the façade.

    Kind regards

    Georg

  • can I use create valude function for MSSql scalar and table.

    Hello

    (1) can I use create scalar function for MSSql and function table?
    (2) is there how many type of function defined by the user in oracle 11 g express?
    (3) and I can reture 'type' any form user defined function?


    Attract sincerely

    944768 wrote:

    the answer lies in a few cases only,

    The response illustrates the basic concept of how customers need to use cursors created using PL/SQL as a layer of abstraction - SQL and this concepts adapts to ALL cases where the customer wants to Oracle via PL/SQL cursor.

    a case is,
    If my function returns only a single value, then I can use oracle 'create function' with the return type as types predefined as a whole, varchar2 etc?
    with regard to performance.

    With regard to this performance problem? And why now suddenly change the question to want to use a function to return data type number or string? How does this relate to PL/SQL to return a cursor now?

    A function can return scalar values, not scalar. A function may return atomic values (such as a unique number, or a non-scalar list of numbers). A function can return a complex data structure consisting of scalar values, not scalar.

    However, in PL/SQL function must NOT be used to read the lines of the database to cache lines in a memory of the server PL/SQL (PGA), then back to the client.

    He does not. It does not fit. It is too bloody dangerous to the overall health of the server as such code plays silly blighters with very expensive server memory.

    A PL/SQL function can also be used as guideline, returning data via expensive PGA, but via the SQL engine instead and using its slider interface (which allows output data to be "gradual" and not to return all data with a single copy of croustilleur mass of the call stack) directly. IT IS, HOWEVER, AN EXCEPTION. There is very rarely the need to make the functions PL/SQL pipeline table - and is often victims of abuse and bad demonstrated with examples of absurd code here.

  • create the default function for table

    Oracle Erro PLS-00593
    What is this problem?

    Is possible to create?

    exec default_values (51, p_seq_cessao_servidor_canc = > varray_1);
    or
    exec default_values (51, p_seq_cessao_servidor_upd = > varray_2);


    CREATE OR REPLACE TYPE 'SISARR '. "' VARRAYNUMTYP ' is varray (500) number;

    function test (p_seq_debito IN sisarr.debito.seq_debito%TYPE
    p_sig_usuario IN sisarr.deb_cessao_servidores.sig_usuario%type
    p_seq_cessao_servidor_canc IN varraynumtyp by default varraynumtyp()
    (, p_seq_cessao_servidor_upd IN varraynumtyp varraynumtyp() default) return is varchar2

    vMsg Varchar2 (4000);

    Start
    --
    end;

    Thank you!

    Published by: user10830594 on 06/03/2009 05:52

    Hello

    user10830594 wrote:
    Oracle Erro PLS-00593
    What is this problem?

    Oracle error: PLS-00593
    the default value of the parameter 'string' in the body must match spec

    Cause
    Initialization by default value of a parameter in a body of subroutine contained in a package body did not match that of the specification of subprogram corresponding to the corresponding package specification.

    Action
    Change the default initialization of the parameter in the body must match the spec.

    SQL> create or replace type test_v is VARRAY(500) of number;
      2  /
    
    Type created.
    
    SQL> create function test_f (x test_v default NULL)
      2  return number
      3  as
      4  begin
      5  return 1;
      6  end;
      7  /
    
    Function created.
    
  • I need to create a windows reinstallation disc

    I need to create a disk to reinstall windows.
    I picked up a virus and mcafee are not able to remove it if you need to reinstall windows...

    The recovery disk create function coverage this?

    Hello

    You mean, you want to create a recovery disk.
    What cell phone do you have?
    You have preinstalled software called Toshiba Recovery Disk Creator?
    If so, try this.
    Usually, this software creates a Toshiba Recovery disk that helps you to restore the operating system to factory settings.
    But note; This will of functions using only the operating system preinstalled by Toshiba.

    The other option might be (if available) HARD drive recovery
    Try pressing F8 (when starting laptop computer), and then select Repair my computer, then HARD drive recovery

  • How to record various objects used by an external C function

    I want to do my own LV component that calls a C function that uses an external API. For the first time, my function is called, it creates and defines variables and some API objects and store them. If the future my function calls do not need to define and create them again. The main problem is that this variables and objects must be different for any instance. I mean: if I have several components to call a library function, the call to my function, running at the same time, I need them to create variables and objects, instead of sharing their own API. So I need to be able to access or to allocate a memory space for each different instance of the NSI component that calls to my function.

    How can I do this with the function of library call? Is there another approach to this? How?

    Thank you very much.

    eduraser wrote:

    OK, I really appreciate this answer, thank you very much.

    Of course, I understand that I need to create a function which deletes, clean, free, etc., all objects and the variables created. But I don't know where exactly call to clean up at the right time. I want to have cleaned up the Labview runtime stops (do not break)... so do I call it as a reminder of the library call feature? Anywhere else? Another option?

    Thank you very much!

    Well in general, you flow "create(), read() read(2)/write(2) () / () use, close() in an application" for any resource and close() would be where you would have to call your function has.

    If you want this fact automatically, half only officially documented way is indeed the named of the dialog configuration node unaptly callback function call library. How is this registrant one or more additional function that takes a pointer as a parameter value. This pointer can be everything you want it to be, and you can configure your function to have an additional parameter which is not exposed on the diagram, but rather helps him pass this pointer.

    LabVIEW maintains such a pointer dataspace CLN instance and calls the callback function that appropriate specified events and pass this pointer to data. For example, you can check in the call to the create function if this parameter is NULL, and if yes to store a handle to your resource in there. When the reminder cancel or abort is called you could go and own up to your resource.

  • ActionBar.placement changes create duplicates

    I want to create functionality that my app is purchased the action point happen OT InOverflow OnBar however the following code creates doublonnait followed when it changes.  Any suggestions how to get around this problem?

    {ActionItem}
    Title: qsTr ("Options")
    ActionBar.placement: _tiledApp.purchased! 'Bought = '? ActionBarPlacement.OnBar: ActionBarPlacement.InOverflow
    onTriggered: {}
    If (_tiledApp.purchased == 'Bought') {}
    If {(sold)
    page var getOptionsPage() =;
    Console.Debug ("pushing retail" + page)
    navPaneid.push (page);
    } else {}
    optionsToast.show)
    Console.Debug (purched);
    }
    }
    attachedObjects:]
    {SystemToast}
    ID: optionsToast
    body: 'Premium Version required.
    }
    ]
    },

    I'll post this as a bug - leaving however the actionitem in place and simply change the title, image and function is a workaround that works - as long as you are swapping onBar and inOverflow.

  • By the way Self as a parameter or by passing an object Variable to a member function, both in the approach IN OUT NOCOPY Mode which is better?

    Hi all
    Asking for help which approach is better of the two in terms of performance and why (if there is no difference) or are they an and they same and only different in terms of syntax only.

    (A) to call a function with itself in passing as IN OUT nocopy
    (B) passing the calling object, same as IN OUT NOCOPY.

    @
    (In my approach, I need to pass an object with almost 30 attributes and I must assign values to few attributes of the object in a few member functions that will impact object)

    I have an object created in the
    CREATE or REPLACE TYPE my_obj AS OBJECT
    (
    NAME VARCHAR2 (100),
    FUNCTION CONSTRUCTOR My_obj RETURNS SELF AS RESULTS,
    FUNCTION MEMBER put_name (SELF IN OUT NOCOPY my_obj) RETURN PLS_INTEGER,
    RETURN of the MEMBER FUNCTION insert_name (v_my_obj IN OUT NOCOPY my_obj)
    PLS_INTEGER,
    MEMBER get_name PROCEDURE
    );
    /
    CREATE OR REPLACE TYPE BODY MY_OBJ

    FUNCTION CONSTRUCTOR RETURN self AS RESULT My_obj IS
    BEGIN
    NULL;
    RETURN;
    END;

    FUNCTION MEMBER (SELF IN OUT NOCOPY my_obj) put_name IS BACK PLS_INTEGER
    BEGIN
    Self.Name: = "my_name_in_self";
    RETURN 1;
    END put_name;

    MEMBER FUNCTION insert_name (v_my_obj IN OUT NOCOPY my_obj)
    IS BACK PLS_INTEGER
    BEGIN
    v_my_obj. Name: = "my_name_in_Alias";
    RETURN 1;
    END insert_name;

    MEMBER get_name PROCEDURE IS
    BEGIN
    dbms_output.put_line (self. (Name)
    END;
    END;
    /

    (a) put_name heel 1 call:

    declare
    v my_obj: = my_obj();
    number of ret_val;
    Start
    ret_val: = v.put_name;
    v.get_Name;
    end;

    o/p: my_name_in_self

    (a) insert_name citing heel 2:

    declare
    v my_obj: = my_obj();
    number of ret_val;
    Start
    ret_val: = v.insert_name (v);
    v.get_Name;
    end;

    o/p: my_name_in_Alias

    What is better to use the put_name or use the function insert_name.
    I manipulate the object when it is passed to a function.

    Thanks in advance,
    Kind regards
    Gaurav R

    As Billy said above, each member method has implicitly (which can be made explicit, as with "put_name", when required, for example, to specify the "nocopy" option) parameter named 'home '. For member functions, the passage of default mode is "inside". For the procedures of members, the passage of default mode is "outside". Therefore, the actual signature of the function of your 'insert_name":

    ...
    member function insert_name(self in my_obj, v_my_obj in out nocopy my_obj) return pls_integer
    ...
    

    Since you don't self directly access this function, it is logically equivalent to a static type function (which has no implicit setting of "self"):

    ...
    static function insert_name(v_my_obj in out nocopy my_obj) return pls_integer
    ...
    

    which is basically no different than using a non-object function that takes a parameter of type of object:

    create function insert_name(v_my_obj in out nocopy my_obj) return pls_integer
    

    Gerard

Maybe you are looking for

  • Play my music on apple machines

    I would like to power access/play my music, currently stored on my computer, on all my Apple machines. What is the best way to do it?

  • HP Envy laptop - 15-ae011na: HP Envy - keyboard and Trackpad not working after the mode 'sleep'.

    HP Envy laptop - 15-ae011na I have this laptop for only 1 week, he did various updates. I guess that's from Windows 8 to 8.1. He also completed an update of the BIOS with HP Support Assistant. Question: When the awakening of my laptop mode 'sleep', m

  • Fake Microsoft Security Alert Red

    I just got this for the second time.  I got rid of him the first time with a complete analysis of the actual analysis of Microsoft Security.  Not this time, help?

  • problem setting up vpn site-to-site between asa and 1811 router

    I get the following error. 3. January 8, 2008 | 15: 47:31 | 710003 | 192.168.0.45 | 192.168.0.50. TCP access denied by ACL to 192.168.0.45/3698 to LAN:192.168.0.50/80 3. January 8, 2008 | 15:47:28 | 710003 | 192.168.0.45 | 192.168.0.50. TCP access de

  • product key for the wrong region

    Recently I bought Windows 7 N by online download. I live in the United Kingdom. I can not activate because the I get the message that the product key can only be used in certain countries. I was billed in GBP to a UK postal address so I don't underst