Function Vs Proc

procedure has OUT parameters
though function has returning a single value using return we also can have
out parameters in function also..
so what is the criteria whether to go for function or procedure??

Also, when used in a SQL, the function cannot have any DML inside its implementation. or else it will give an error like this.
SQL> create table r (x varchar2(10));
Table created.
SQL> create function p return number as
2 begin
3 insert into r values ('oregon');
4 commit;
5 return 123;
6 end p;
7 /
Function created.
SQL> select p from dual;
select p from dual
ERROR at line 1:
ORA-14551: cannot perform a DML operation inside a query
ORA-06512: at "RAHUL.P", line 3
SQL> create or replace function p return number as
2 begin
3 return 123;
4 end p;
5 /
Function created.
SQL> select p from dual;
P
123
Message was edited by:
rputtagunta

Similar Messages

  • Calling a cpp(.cpp) function in proc file(.pc)

    Hi,
    I am trying to call a new cpp function in a proc file,while compiling time it did gave any error.While runtime it is giving unresolved symbols at my cpp function. It is not able to recognize that cpp function.This is my problem.
    How I am doing is I will explain now.
    First I am compiling a cpp function on C++ comiler and creating an object file. Then I am giving this object file path in the make file of pc file.This makefile of .pc file will generate a shared library.
    Can u please provide me any solution for this situation?
    thanks,
    seshadri
    303-306-1533(R)
    303-763-1462(W)

    The best way to do this is probably using delegates, but to do it directly you have to solve the circular dependency problem (as you have discovered). See
    http://en.wikipedia.org/wiki/Circular_dependency
    In case it is not clear to you how the Wikipedia article relates to your case, your files should look something like this:
    // Form1.h
    #include "Watch.h"
    ref class Form1: public Form
    public:
    void SomeMethod()
    // implementation
    private:
    void SomeHandler()
    Watch watchForm(this);
    watchForm.ShowDialog();
    // Watch.h
    ref class Form1; // declaration only
    ref class Watch: public Form
    public:
    Watch(Form1^ f1);
    private:
    Form1^ form1;
    void SomeMethod();
    // Watch.cpp
    #include "Watch.h"
    #include "Form1.h"
    Watch::Watch(Form1^ f1)
    form1 = f1;
    void Watch::SomeMethod()
    form1->SomeMethod();
    David Wilkinson | Visual C++ MVP

  • Trying to find unused tables by views,function, and proc?

    I come up with lists of unused table through given script
    SELECT
    SCHEMA_NAME(t.schema_id)
    as SchemaName,
    t.name as
    TableName
    FROM   sys.tables
    t
    WHERE  is_ms_shipped
    = 0
    AND NOT
    EXISTS (SELECT
    FROM   sys.sql_expression_dependencies
    d
    WHERE  d.referenced_entity_name
    = t.name
    AND ((
    is_ambiguous = 1
    or is_caller_dependent=1)
    OR
    d.referenced_id
    = t.object_id) 
    result:
    dbo temp_bandfix
    dbo ClientParty_AXClient_back
    dbo EmployeeParty_AXEmployee_back
    dbo CUSTTABLE
    dbo sysdiagrams
    dbo ConcurClientList
    I have list of procs, Vws, and FN in DB
    I am thinking to add sub query on the above script and see dependency on procs, views and FN to make sure those tables are not used at all  in database before dropping them.
    Looking for help on this issue???

    Use SQL Server Profiler to run a trace on your database. You can let it run for a week or longer if you'd like to. Then once it is done you can upload the results to an SQL table. Then you can use a join to the query you have above to see if there are any
    tables not being accessed. This is probably the best method for determining if a table is unused, as the Profiler will log events anytime someone runs a transaction against a table.
    Jordan Johnson

  • Simple function or proc will also do

    I need to pass 2 parameter to SP/function to return date
    I will be passing the tableName and DateValue in return I should be getting the max(dt_date) from tableName can anyone help me in building this simple logic
    create function fun( @tableName varchar(250), dtdate datetime)
    return datetime
    begin
    end
    create function sproc( @tableName varchar(250), dtdate datetime)
    As
    begin
    end
    Neil

    SaravanaC, you cannot pass a table or a column name as a parameter to sp_executesql, but yet
    I recommend getting used to using sp_executesql instead of exec.
    My idea is that you should getting used to using sp_executesql instead of exec. This is why I wrote this and
    in the same time I proposed your response as an answer. It is an answer but I dont like it so much :-) and prefer my answer or Visakh16 answer which is using sp_executesql with Parameters according the needs.
    I prefer to use: EXEC sp_executesql @SQLQuery
    without parameters then to use: EXEC (@SQLQuery)
    This is my opinion :-)
    [Personal Site] [Blog] [Facebook]
    Thanks Ronen for Clarification :-), i will try to use sp_executesql
    Thanks
    Saravana Kumar C

  • Proc or function returning n rows

    Returning multi-rows with informix or sysbase procedures is very simple
    for example it's possible to declare in esql/c sybase a cursor for execute procedure and retrieve all tutles in a cursor in the esql/c code.
    This procedure is also usable in sql with execute blablabla and the result is like a simple select.
    Oracle proc or function simes to be more complicated!
    Is someone got a part of pro*C code and stored proc or function code about multirows retrieval? Is this function or proc usable in VB for example?

    If you are certain to get a small number of rows (10, 20, ..., 100), than PL table is the best choice.
    But for a large number of rows, cursor is the best choice, having in view that a PL table will have to be entirely stored in the server memory (and this requires some SGA space), while cursors allow fetching a number of rows, processing the fetched rows, again fetch a number of rows and so on ...
    Forms with data-blocks based on functions that return ref cursor allow fetching rows in bulks of 10-20...100 at a time.
    null

  • Running SQL Server Function and Procedures from Oracle

    I am trying to run SQL Server 2005 functions and/or procedures from a SQL statement in Oracle. I have gone throught the hetergeneous services and have connected to the SQL Server database successfully. I can also do a query to a table in SQL Server successfully; but I have not been able to execute a procedure or a function.

    Have you tried Oracle syntax? It seems to me that you have only tried T-SQL syntax, e.g. execute proc.
    Wrap it in a begin..end tag like you would a normal PL/SQL function or proc call. Assumption is that as Oracle makes the remote database (via the dblink) look like an Oracle database, you should also play along and pretend it is one and treat it as such.
    E.g.declare
      r integer;
    begin
      -- execute remote proc
      procFoo@dblink( 'ABC' );
      -- call a remote function
      r := funcFoo@dblink( 123 );
    end;

  • Combine floor() and ceiling() functions

    I need to combine the functionality provided by both floor() and ceiling() functions using
    normal pl/sql function or proc. and without using any built-in functions in it.

    And wtf is the purpose of not using 'any built-in functions in it'?

  • XMLGEN & Stored Procs

    Could someone give an example of calling a function/stored proc contained in a package by the XML tools? Something like:
    xmlStr := xmlgen.getXML (MyPackage.StoredProc(vars));
    TIA!

    Steve,
    Yes, I figured that the return string needs to be a CLOB, although here I've actually depicted a function - which is fine - but I still need a quick example. What about stored procs with REF CURSORs?
    P.S. Good book!
    Thanks
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Steven Muench ([email protected]):
    What does MyPackage.StoredProc(vars) return in your environment? Is it returning the string representation of a query for which you want the XML ?
    Is "xmlStr" declared as a CLOB ?
    if so, you've already got the right syntax.<HR></BLOCKQUOTE>
    null

  • How to find the list of un used table names in a schema?

    Hi,
    I have a doubt in Oracle. The doubt is that If we are using any tables in Function Or Proc.... Then...We can list all those used table names from USER_DEPENDENCIES system table. Right...
    But, If the table is used with Execute Immediate Statement, then, those table names are not coming out with USER_DEPENDENCIES system table. Because they are identified at run time and not compile time.
    It is fine. And I agree.. But, If I want to list out those tables also...then...How to do? Any idea?
    I think ‘USER_SOURCE’ system table may not be the right one. If there is any other system table avails for this purpose...then..it would be very grateful to extract right...
    So I am wanting that exact system table.
    Please let me know about this, if you have any idea or check with your friends if they have any idea.
    Regards,
    Subramanian G

    Hi Guys,
    Thanks for all your answers.
    Yes....You are all right. We can list out the used tables upto certain extent. Anyhow, I have done some R&D to derive the SQL's which is given below:
    SELECT TABLE_NAME FROM USER_TABLES
    MINUS
    SELECT DISTINCT UPPER(REFERENCED_NAME)
    FROM user_dependencies
    where
    referenced_type='TABLE' and UPPER(NAME) in
    select distinct UPPER(object_name) from user_objects where UPPER(object_type) in
    'MATERIALIZED VIEW',
    'PACKAGE',
    'PACKAGE BODY',
    'PROCEDURE',
    'TRIGGER',
    'VIEW',
    'FUNCTION'
    UNION
    SELECT UT.TABLE_NAME FROM
    SELECT TABLE_NAME FROM USER_TABLES
    MINUS
    SELECT DISTINCT UPPER(REFERENCED_NAME)
    FROM user_dependencies
    where
    referenced_type='TABLE' and UPPER(NAME) in
    select distinct UPPER(object_name) from user_objects where UPPER(object_type) in
    'MATERIALIZED VIEW',
    'PACKAGE',
    'PACKAGE BODY',
    'PROCEDURE',
    'TRIGGER',
    'VIEW',
    'FUNCTION'
    AND REFERENCED_OWNER=(SELECT sys_context('USERENV', 'CURRENT_SCHEMA') FROM dual)
    ) UT,
    ( SELECT * FROM USER_SOURCE
    WHERE NAME IN
    ( SELECT DISTINCT NAME FROM USER_SOURCE
    WHERE TYPE NOT IN ('TYPE')
    AND
    UPPER(TEXT) LIKE '%EXECUTE IMMEDIATE%'
    ) US
    WHERE
    UPPER(US.TEXT) LIKE '%'||UPPER(UT.TABLE_NAME)||'%'
    AND
    (UPPER(US.TEXT) NOT LIKE '%--%')
    The above SQL Query can list out unused tables by checking the Dynamic SQL Statement also upto some level only.
    Once we extracted the list of unused tables, having a manual check would be also greater to verify as it is should not impact the business applications.
    Regards,
    Subramanian G

  • Stored procedure for a calculated value

    Hello all..
    I have this problem:
    I have a data form on which there's a textfield control which is linked to a calculated field. This field is calculated by a stored procedure. The stored procedure is based on some values that might be changed on that same data form. My problem is that when I call the stored procedure it doesn't see the changes that I've made in the DB (Which were not commited yet) although they share the same session.
    Here's how I activate the stored procedure in my code:
    ViewObjectImpl viewObjectImpl = (ViewObjectImpl)getViewObject();
    DBTransaction dbTransaction = viewObjectImpl.getDBTransaction();
    Statement stmt = dbTransaction.createStatement(1);
    stmt.execute("select ....")
    etc.. this is done in my getCalculatedField inside the Viewimpl class.
    Any ideas?
    Thanks
    Liron

    Create an alternate stored procedure or function that takes the "modified" but not yet committed value(s) as a parameter(s)?
    That's what I do, today. You can either use a dynamic view object or straight JDBC to get to the stored function or proc.
    Sorry if I misinterpreted what you were after.

  • Debugger breakpoint not stopping.

    Hi,
    I had two package. When debugging the package COLLECTIONS_VERSION1_V1 the package will stop at the breakpoint specified (line 113) . However debugging the other packageTERMS_COLLECTIONS would just exit the process and doesn't stop/halt at the breakpoint at the line(145). This is what the breakpoint window displayed:
    Description Type Status Action
    Oracle exception, Persistent     Exception Breakpoint     Enabled               Halt, Log
    $Oracle.PackageBody.User COLLECTIONS_VERSION1_V1 113     Source Breakpoint     Enabled (now Verified)               Halt, Beep, Log
    $Oracle.PackageBody.User1 TERMS_COLLECTIONS 145     Source Breakpoint     Enabled (now Unverified)     Halt, Beep, Log
    Can anyone please explain why the package behave differently especially the Enabled(now Verified) and enabled (now Unverified). I have permission to debug and also the port/firewall also not block.
    Thanks,
    Ad

    The breakpoint that I put is in separate functions and procs called by the main procedure.
    I am beggining to suspect the package is also too long but I'm not sure how much and how to know if I have exceed. If it does, does it mean compiler debug total ignores my breakpoint and just exit the process? My package uses quite lot of passing record/collection in procs/function as I was trying to shortened/optimise the code. The code also has 67 output parameter going out from the package. ( The other developer doesn't want to change their code and expect me to pass it all :( )
    Are any of them the main culprit/reason for the memory becoming to large? Is there any other better way?
    I have also added few NOCOPY to the output parameter.

  • AppActivate doesn't work

    Hi
    I am using the AppActivate for long time in my application and all went well until few weeks ago.
    Lately the AppActivate work partially (i.e. sometimes it gets to the right focus to the application and sometimes it doesn’t).
    There were 2 changes that I did lately and it might be related to it  but not sure :
    I have upgraded from VB2008 to VB2012
    I have upgraded from Office2010 to Office2013
    When I was trying to read on AppActivate in MSDN Library I notice that this function is not support at Visual Studio 2012 (the latest one that it is supported is Visual Studio 2008) – Was this function deprecated in VS2012 and need to use other function
    BTW, I am using the function processID as parameter :  AppActivate(processID) 

    Hi,
     You can try using something like the ActivateApp sub that is in the example below. It uses the
    Process Class to get the process that has the specified ID and then uses the
    SetForegroundWindow API to set the processes window to the Foreground. Depending on your situation you may be able to use one of the other Process Methods to make it work by passing the Process`s ProcessName or the Process`s MainWindowHandle
    instead of the ID.
    Imports System.Runtime.InteropServices
    Public Class Form1
    <DllImport("user32.dll", EntryPoint:="SetForegroundWindow")> _
    Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
    Private proc As Process
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    proc = Process.Start("notepad")
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    ActivateApp(proc.Id) 'use the process`s name
    End Sub
    Private Sub ActivateApp(ByVal pID As Integer)
    Dim p As Process = Process.GetProcessById(pID)
    If p IsNot Nothing Then
    SetForegroundWindow(p.MainWindowHandle)
    End If
    End Sub
    End Class
    If you say it can`t be done then i`ll try it

  • Convincing a SQL Servery guy on Advantages of using Packages

    Our Database Version:10g Release 2
    To implement a functionality, i had to create 5 functions and four procedures(one being error logging proc). For modularity reason, I wanted all these functions and procedures to be in one single package. But my manager(which happens to be a SQL Server guy) wants these functions and procedures to be created individually. Who is right? Me or Him? If i am right, how can i convince this man that i am right?
    A question for any ex-SQL Server developers if present in this forum:
    I don't know anything about SQL Server Development. Don't these guys have an equivalent to packages?

    Certain things can be be best acchieved with packages.
    Thus, package initialization may be useful, in order not to repeatedly execute the same stuff on each function call.
    And you may have also objects that persist at package level.
    Plus, encapsulation may help the ones who have to use the package not to bother with lots of procs and/or functions that are in the package body.
    It is good to group in packages related functions and procs, that are most likely to be called by the same session for certain processing.
    It is not good to group in packages functons and/or procs that are unrelated.
    So, you may have a package for processing customers. But it would'nt be good to place in the same package functions and/or procedures that deal with inventory, for instance...
    Convince your manager to leave the technical guys deal with technical issues or have him read some Oracle documentation, which will show that Oracle differs from SQL Server in several respects.
    Or, why would they have packeges, if they were no good?
    There are lots of Oracle-supplied packages in the SYS schema.
    If he insists packages are no good, then he also has to say that Oracle DB is bull____

  • Auditing on PLSQL Objects

    This is on 10g R2.
    How can I derive auditing information from sys.aud$ specifically for PLSQL objects (function, stored procs, packages)
    In other words, what are columns or values in rows in sys.aud$ table, that gives this information.
    Thanks
    R

    SQL> desc aud$
    Name                            Null?    Type
    SESSIONID                       NOT NULL NUMBER
    ENTRYID                       NOT NULL NUMBER
    STATEMENT                       NOT NULL NUMBER
    TIMESTAMP#                             DATE
    USERID                              VARCHAR2(30)
    USERHOST                             VARCHAR2(128)
    TERMINAL                             VARCHAR2(255)
    ACTION#                       NOT NULL NUMBER
    RETURNCODE                       NOT NULL NUMBER
    OBJ$CREATOR                             VARCHAR2(30)
    OBJ$NAME                             VARCHAR2(128)
    AUTH$PRIVILEGES                        VARCHAR2(16)
    AUTH$GRANTEE                             VARCHAR2(30)
    NEW$OWNER                             VARCHAR2(30)
    NEW$NAME                             VARCHAR2(128)
    SES$ACTIONS                             VARCHAR2(19)
    SES$TID                             NUMBER
    LOGOFF$LREAD                             NUMBER
    LOGOFF$PREAD                             NUMBER
    LOGOFF$LWRITE                             NUMBER
    LOGOFF$DEAD                             NUMBER
    LOGOFF$TIME                             DATE
    COMMENT$TEXT                             VARCHAR2(4000)
    CLIENTID                             VARCHAR2(64)
    SPARE1                              VARCHAR2(255)
    SPARE2                              NUMBER
    OBJ$LABEL                             RAW(255)
    SES$LABEL                             RAW(255)
    PRIV$USED                             NUMBER
    SESSIONCPU                             NUMBER
    NTIMESTAMP#                             TIMESTAMP(6)
    PROXY$SID                             NUMBER
    USER$GUID                             VARCHAR2(32)
    INSTANCE#                             NUMBER
    PROCESS#                             VARCHAR2(16)
    XID                                  RAW(8)
    AUDITID                             VARCHAR2(64)
    SCN                                  NUMBER
    DBID                                  NUMBER
    SQLBIND                             CLOB
    SQLTEXT                             CLOB
    OBJ$EDITION                             VARCHAR2(30)

  • Execute query qutomatically ?

    I have some static queries, where nothing changes, they just need to be re-run first thing monday morning.
    I would like to learn the best way to automate this ? I am on Oracle 11G Enterprise, and am just an end-user, no Admin privilages.
    I have SQL*Plus, Toad and SQL Developer available and am trying to just figure out the best wa to do this. I was thinking that there
    is some way to store the SQL on the server-side like with Function or Procs and just instruct the database when to execute the SQL.
    Then maybe instead of an email, maybe a tracking Table could be updated with the status of the update. So if I have 3-6 different
    SQL, the tracking table would have 2 column, Table name and DDL Date column or whatever makes sense.
    So my tracking table would update when the SQL finished and tell me when it finished executing be looking into the DDL Date column,
    and then I could see which table it is talking about, not sure... or whatever the best way it is to do it.
    At this point I am in research mode, so some of my question might sound silly, but that's how I learn, thank you.

    Kodiak_Seattle wrote:
    I have some static queries, where nothing changes, they just need to be re-run first thing monday morning.
    I would like to learn the best way to automate this ? I am on Oracle 11G Enterprise, and am just an end-user, no Admin privilages.
    I have SQL*Plus, Toad and SQL Developer available and am trying to just figure out the best wa to do this. I was thinking that there
    is some way to store the SQL on the server-side like with Function or Procs and just instruct the database when to execute the SQL.
    Then maybe instead of an email, maybe a tracking Table could be updated with the status of the update. So if I have 3-6 different
    SQL, the tracking table would have 2 column, Table name and DDL Date column or whatever makes sense, at this point I am in research
    mode, so some of my question might sound silly, but that's how I learn, thank you.DBMS_SCHEDULER

Maybe you are looking for

  • All I hear when I make calls is little bits of static (most of the time)

    So this started happening about a month ago when I moved to NJ (though I upgraded from iOS 5.1.1 to 7 at the same time - so I don't know if that's connected to this issue).  I place a call and the timer starts going, but I can't hear anything except

  • How do you copy and paste on Android?

    When I'm browsing various sites there is often a need to either copy text from a web page or paste text from elsewhere on the phone (such as a password manager app) into a form on a web page. When using the stock Android browser this is generally acc

  • Aperture makes a comeback...

    Well, maybe. Some people who like Aperture are speaking up on the forum. Everyone seems to agree the overall workflow is an improvemnt over previous programs. So, the two remaining big questions for me are quality of the conversions and speed of work

  • Putting home DVD on to Itunes to view on apple TV

    Hi Everyone, I have a lot of old 8mm video that I have put on DVD discs. I would like to copy these onto my imac to watch on apple tv. How do I do this please? Thanks

  • Hp 5000 s2 SDSS application stopped

    In a nutshell the SDSS application stops error pops up on any scan larger than about 10-20 pages.  The business partner I support is doing large bunches, 100+ doublesided scans.  We upgraded Adobe Reader and are using SDSS 3.7.1, are there any upgrad