Variable declaration in Package and package body

Hi
Kindly reply the difference in declaring a cursor inside a package vs package body
eg:
create or replace package shapak is
cursor shacur is select * from sha;
function shafun return number;
end;
i can declare the above cursor inside the package body withoout declaring in package specification. but what is the difference?
reply appreciated
thanks
shajan

In general..Items declared in the package spec are visible outside the package..so you can say public.where as items declared in the body are restricted to use within the package..such items are called private.

Similar Messages

  • Packages and packages

    Hi
    I was rereading Martin's principles of package architecture and was wondering how the concept of package in this context relates to the concept of a Java package
    after thinking a bit, I got the feeling these two concepts have nothing to do with each other
    I feel that Java packages deal with namespace and access control, while OO packages (the components of your program's binaries) would be, in the Java world, jar files containing classes from different packages (and not especially all classes from these (Java) packages), and constructed as much as possible in order to follow these supposedly good OO principles
    Am I right ? partially ? totally ? totally not ? I need some insight on this

    Kind of. But what would stop me to define the
    namespace on a per-component base? I used structures
    like com.mycompany.myapp.database (data tier),
    com.mycompany.myapp.web (presentation tier) and the
    likes. You could put classes (or packages) belonging
    to a certain subsystem into a package dedicated to it.I did it for a long time too, traditionaly with webapps :
    be.mycompany.myapp
    dataaccess
    business
    web
    and that worked fine... but that's not my concern
    actually, what concerns me is the business package itself... I'm writing a very simple peer2peer file sharing tool for both fun & education, and the packaging becomes trickier, since the app is naturally distributed :
    * file sharing client package
    * user manager client package
    * server package (handles login requests & user management requests)
    thing is, I reuse many classes among these three "kinds of endpoint", which makes me think about properly dividing my app into small reusable, well-organised components... when java packages come into play, things are getting less clear as of how I should do...
    how do you people do when it comes to structuring (packages AND deliverables of) your business layer ?

  • UNIX: Spool out database package and package body to a file [SOLVED]

    Hello,
    Does anyone know what I need to type into the unix console in order to spool out a database package spec and body of my choosing to a file? I've been told that I've got to do something like:
    set trim spool on
    With the idea that the trim will wrap the lines in the file so that words aren't half cut off. But the unix console tells me those commands don't exist?
    Thanks,
    - A Developer Scorned
    Message was edited by:
    A Developer Scorned

    Thank you very much gintsp. I did not realise they were sqlplus commands.
    In order to spool out a datababase package spec and its accompanying body through sqlplus in unix, I found the following post helpful too: how to generate text file using spool command
    Simply load up sqlplus and enter in the commands (set verify off, set feedback off etc), and specify a file to spool out to. In order to spool out the text of a database package, simply use:
    select text from dba_source where name = <your package name here>
    That way the spec will be spooled out followed by the body.
    Thanks,
    - A Developer Scorned.

  • Why a semi-colon is not enough when creating packages and package bodies?

    Hi,
    I'm struggling with a quite simple problem - when creating a package header and body in the same script, it does not work as expected. See for example this very simple package:
    CREATE OR REPLACE PACKAGE mypackage AS
    PROCEDURE test_proc(id INTEGER);
    END mypackage;
    CREATE OR REPLACE PACKAGE BODY mypackage AS
    PROCEDURE test_proc(id INTEGER) IS
    BEGIN
    NULL;
    END test_proc;
    END mypackage;
    When executed from JDeveloper (or sqlplus), the package is created but with a "PLS-00103: Encountered the symbol CREATE" error. It seems Oracle does not recognize the script contains header and body, and uses the whole script as a header (which is obviously wrong).
    If modified so that there are "/" everything works fine:
    CREATE OR REPLACE PACKAGE mypackage AS
    PROCEDURE test_proc(id INTEGER);
    END mypackage;
    CREATE OR REPLACE PACKAGE BODY mypackage AS
    PROCEDURE test_proc(id INTEGER) IS
    BEGIN
    NULL;
    END test_proc;
    END mypackage;
    Why is this necessary? Why Oracle does not recognize that "END mypackage;" actually ends package header definition, and combines it with the body definition into an invalid block? I've thought semicolon is a valid separator, so why is the "/" necessary?
    It does not work even when I try to run the statements separately (from the same worksheet in Jdeveloper) - first select the header block, hit F9 (execute statement), then repeated the same for body. In this case both header and body are created, but are invalid because the last semicolon is removed from them (so it's not possible to compile them).

    For that to work, the SQL engine would have to understand PL/SQL syntax. Only the PL/SQL compiler knows when all the END statements have matched up with their corresponding declarations, and it doesn't do CREATE statements. I guess it could detect that the compilation unit it started has finished and pass any text left over back up to SQL to have another shot at. I'm not sure that's reasonable. There is no other example in SQL where one CREATE statement can turn into two - e.g. you can't send a block of CREATE INDEX statements together and expect the database to parse them out into separate commands.
    Edited by: William Robertson on Jun 6, 2009 6:49 PM
    Edited by: William Robertson on Jun 6, 2009 6:51 PM
    Added example about indexes.

  • What is the difference between the function declared in the package and pac

    What is the difference between defining a function in the package and package body ?
    Edited by: user10641405 on Nov 19, 2009 1:29 PM

    If you describe a package, you will only see the functions declared in the spec.
    If you only declare them in the body then they are not available to other packages (they are private to the package, not public)

  • How to find Unused variables in procedure,function or package

    Hi all,
    I want find out unused variables in procedure, function and package.
    I have written below script for doing this ,but i am not getting the expected result.
    Kindly help me to improve the below code ,so that it works as expected.
    {code}
    version details
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE    11.2.0.3.0    Production"
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    {code}
    {code}
    What i Have tried is This.
    DECLARE
      V_OBJECT_NAME VARCHAR2(30) :='PR_PRINT';
      V_OBJECT_TYPE VARCHAR2(30) :='PROCEDURE';
      CURSOR C1(CP_OBJECT_NAME VARCHAR2,CP_OBJECT_TYPE VARCHAR2)
      IS
        SELECT US.NAME,
          US.TYPE,
          US.LINE,
          REGEXP_SUBSTR(US.TEXT,'.* ') AS var_name
        FROM user_source US
        WHERE name=CP_OBJECT_NAME
        AND type  =CP_OBJECT_TYPE
        AND REGEXP_LIKE (TEXT,'(v_|g_|c_)','i')
        AND REGEXP_LIKE (TEXT,'^[^ ]')
        AND REGEXP_LIKE (TEXT,'^[^--]') ;
      v_count NUMBER ;
    BEGIN
      FOR i IN C1(V_OBJECT_NAME,V_OBJECT_TYPE)
      LOOP
        SELECT COUNT( *)
        INTO V_COUNT
        FROM USER_SOURCE US
        WHERE US.NAME=I.NAME
        AND REGEXP_LIKE(US.TEXT,i.var_name,'i' )
        AND US.LINE<>I.LINE;
        IF V_COUNT  =0 THEN
          DBMS_OUTPUT.PUT_LINE('variable '||I.VAR_NAME||'Is declared at line#'||I.LINE||' But no where used');
        END IF ;
      END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('p_err_code := '||SQLCODE||dbms_utility.format_Error_backtrace());
      DBMS_OUTPUT.PUT_LINE('p_err_msg := '||sqlerrm);
    END ;
    {code}
    Thanks,
    P Prakash

    Hello,
    as suggested by padders you can use PL/Scope, an example:
    ALTER SESSION SET PLSCOPE_SETTINGS='IDENTIFIERS:ALL';
    CREATE OR REPLACE PACKAGE ui_test1 AS
        global_number   NUMBER := 9;
    FUNCTION get_number
        RETURN NUMBER;
    END ui_test1;
    CREATE OR REPLACE PACKAGE BODY ui_test1 AS
    PROCEDURE setNull
         p_varchar          IN OUT VARCHAR2
    IS
    BEGIN
        p_varchar := NVL(p_varchar,'NULL');
    END setNull;
    FUNCTION get_number
        RETURN NUMBER
    IS
        FUNCTION setZero
             p_number       IN NUMBER
            RETURN NUMBER
        IS
        BEGIN
            RETURN NVL(p_number,0);
        END setZero;
    BEGIN
        RETURN global_number;
    END get_number;
    END ui_test1;
    SELECT  DISTINCT
            object_name
           ,object_type
           ,name
           ,type
           ,line
           ,col
    FROM    all_identifiers obj
    WHERE   obj.owner = USER
    AND     obj.usage = 'DECLARATION'
    AND     obj.object_name = 'UI_TEST1'
    AND     NOT EXISTS (
                SELECT  1
                FROM    all_identifiers with_rh
                WHERE   obj.signature = with_rh.signature
                AND     with_rh.usage IN ('REFERENCE','CALL','ASSIGNMENT')
    ORDER BY TYPE
            ,object_name
            ,object_type
            ,name;
    OBJECT_NAME  OBJECT_TYPE   NAME       TYPE       LINE COL
    UI_TEST1     PACKAGE       GET_NUMBER FUNCTION     11  10
    UI_TEST1     PACKAGE BODY  SETZERO    FUNCTION     35  14
    UI_TEST1     PACKAGE       UI_TEST1   PACKAGE       1   9
    UI_TEST1     PACKAGE BODY  SETNULL    PROCEDURE    12  11
    Regards
    Marcus

  • How to make a package and import it later

    Hi folks,
    this is a very basic question but it is not working to me so i will appreciate your comments.
    I had programmed many classes that are going to be used in many projects so they must be part of a library. Tell me whether or not this procedure is correct ?
    Compile those classes into .class files. Create a package with the jar application putting the .class files into a single file called my_utils ( .jar or .zip ?). Import the package from other projects using the import directive and storing the my_utils file in the project's library directory. Is this correct ?
    Many thanks in advance
    Marla.

    If you want to create a package and then put the package into a jar file, first compile into .class files (in appropriate package directories), then jar all of the .class files.
    Here's a link for a tutorial on packages. http://java.sun.com/docs/books/tutorial/java/interpack/packages.html
    Here's a link for a jar file tutorial. http://java.sun.com/docs/books/tutorial/jar/index.html
    You do not have put the .class files into a jar. Java packages are used for organizing classes, managing class name space, and controlling access to classes. Java jar files are a way to put multiple classes into a single file while compressing the content. Jar files can contain multiple packages and packages do not have to be inside of jar files.

  • Flex SDK 4 : mx.chart package and declaration of style 'direction' conflicts with previous declaration problem

    Hi There,
    We have recently downloaded SDK 4 and had configured the same for
    developement in flex builder 3, we are already using SDK 3.0. However
    to our surprise there were compile time error reported for mx.chart
    related classes. To resolve this we thought to import relevant .swc
    like datavisualization, automation from sdk 3.0, and it worked and
    resolved compile time error. But we landed up in on more problem that
    is 'Declaration of style 'direction' conflicts with previous
    declaration in E:\Softwares\FlexBuilder\sdks\SDK 4\frameworks\libs
    \datavisualization.swc(mx/charts/GridLines)'.
    If you could pleas help us to resolve these issues and also if you
    could answer these queries would be good
    1) SDK 4 has been declared to be open source, then why mx.chart
    package is not part of it?
    2) Why would 'Declaration of style 'direction' conflicts with previous
    declaration' occur?
    3) What are the other component and packages that are not part of open
    source for which license is still required?
    Waiting for reponse in anticipation.
    Thanks,

    I got this same error with the following setup.
    1. Building a SWC with Flex 4.0 Beta2 on FlashBuilder4
    2. SWC references other SWC that are built with Flex3.
    3. Define a <mx:ColumnChart id="column" ...> in a Flex4 skin.
    4. Got this compiler error. 
    Any idea if this is not supposed to work? I'm hoping I don't need all referenced swcs to be recompiled with Flex4 SDK. Some of those are external dependency that I do not have source code access.
    Thanks for any help.
    kam

  • View of variables declared within a package/procedure

    Does anyone know of a view which holds all the variables declared within a package/function/procedure?
    I can see that _arguments holds the parameters defined.
    PLSQL Developer displays these things in their drop downs, so I assume they are either getting it from a view or have written something which parses the _source view?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Do you mean this ?
    SCOTT@db102 SQL> desc dbms_output
    PROCEDURE DISABLE
    PROCEDURE ENABLE
    Argument Name                  Type                    In/Out Default?
    BUFFER_SIZE                    NUMBER(38)              IN     DEFAULT
    PROCEDURE GET_LINE
    Argument Name                  Type                    In/Out Default?
    LINE                           VARCHAR2                OUT
    STATUS                         NUMBER(38)              OUT
    PROCEDURE GET_LINES
    Argument Name                  Type                    In/Out Default?
    LINES                          TABLE OF VARCHAR2(32767) OUT
    NUMLINES                       NUMBER(38)              IN/OUT
    PROCEDURE GET_LINES
    Argument Name                  Type                    In/Out Default?
    LINES                          DBMSOUTPUT_LINESARRAY   OUT
    NUMLINES                       NUMBER(38)              IN/OUT
    PROCEDURE NEW_LINE
    PROCEDURE PUT
    Argument Name                  Type                    In/Out Default?
    A                              VARCHAR2                IN
    PROCEDURE PUT_LINE
    Argument Name                  Type                    In/Out Default?
    A                              VARCHAR2                IN
    SCOTT@db102 SQL>                                         

  • Package variable declaration

    I need to declare Item_To_Go_To package level variable stored in the Instace package for the below code.
    I have create a a package specification in the form as a Program Unit named "Instance".
    Now i need to declare Item_To_Go_To variable which will store control name like
    Instance.Item_To_Go_To := 'myblock.myitem';
    I have controls like text item, list item, Checkbox. How to declare these variables?
    I have used the below one:
    PACKAGE Instance IS
    Item_To_Go_To item;
    END;
    In my example Instance.Item_To_Go_To := 'User.FIRST_NAME';
    is giving expression is a wrong type error. Please let me know what i have done wrong.
    I have used timer expired trigger to overcome my illegal restricted procedure Go_item issue.
    Code snippet.
    Declare
    htimer Timer;
    Begin
    Instance.Item_To_Go_To := 'myblock.myitem';
    Create_Timer( 'wvi_nav_timer', 1, NO_REPEAT);
    End;
    Then in the When-Timer-Expired trigger...
    Begin
    If ( Get_Application_Property( Timer_Name ) = 'wvi_nav_time' ) Then
    Go_Item( Instance.Item_To_Go_To );
    End If;
    End;
    Please refer:
    Alternative trigger like post_change but can 'go_item'
    Edited by: Chris90909 on Jun 12, 2009 12:27 PM

    As you are trying to assign a varchar-value to the variable, you should declare it as varchar2 like:
    PACKAGE Instance IS
      Item_To_Go_To VARCHAR2(61);
    END;

  • Package with and without   Body

    Hi
    How can I to Know if a Package have body or no, because there are package only CONSTANTS
    tks

    Ah, is this?
    select object_name
    from user_objects o1
    where object_type = 'PACKAGE'
    and not exists
    (select 'y'
    from user_objects o2
    where o1.object_name = o2.object_name
    and object_type = 'PACKAGE BODY'
    /* This is slow */
    select owner, object_name
    from all_objects o1
    where object_type = 'PACKAGE'
    and not exists
    (select 'y'
    from all_objects o2
    where o1.owner = o2.owner
    and o1.object_name = o2.object_name
    and object_type = 'PACKAGE BODY'
    ;

  • Suppose in a Package Spec there are 3 functions and Package Body there are 5 functions will the package compile?

    Suppose in a Package Spec there are 3 functions and Package Body there are 5 functions will the package compile?

    Rather than asking these basic one-liner questions (When a package is created how many database objects are created?) why don't you explain what issues you are experiencing after you've read the documentation and tried things yourself.
    The forums are for people to help when they experience issues, not when they can't be bothered to read the documentation or searcht the web for the basic information that's already explained.
    Re: 2. How do I ask a question on the forums?
    Re: 1. Where can I find Oracle Documentation?

  • Declaring private cursors in package header

    Hi.
    Im tunning a PLSQL package , and im having the following doubt.
    This package has alot of cursors declared in the package header, but the cursors are private. (called within the package only)
    Could the public functions from the package have a loss of performance by using those cursors? (should the private cursors be declared within the functions or at least inside package body?)
    Im kind of new with plsql, so please bare with me :) .
    Cheers.

    there's no performance loss.
    however, unless the cursors are to be accessible outside the package (which is what happens when they are declared in the spec (not header)), then there's no benefit either. if they are truely meant to be private, then you can remove them from the spec. and if you're wrong, and they are called from elsewhere, you'll find out soon enough.

  • Extracting package and procedure name in code

    In my exception processing I need to log the package and procedure name that got the exception. How do I obtain these two names without manually coding the names?
    Thanks in anticipiation

    A better option is to get the package name and the line numberA still better option is to utilize pl/scope (when you are in 11g (not sure about 10g)):
    SQL> alter session set plscope_settings='identifiers:all'
    Session altered.
    SQL> set serverout on
    SQL> create or replace package pkg
    as
       procedure p1;
       procedure p2;
    end pkg;
    Package created.
    SQL> create or replace package body pkg
    as
       procedure get_scope (obj varchar2, line int)
       as
       begin
          for c in (select rpad (lpad (' ', 2 * (level - 1)) || name, 20, '.') || ' ' || rpad (type, 20) || rpad (usage, 20) identifier_usage_contexts
                    from user_identifiers t
                    where level != 1
                    start with line = get_scope.line and object_name = obj
                    connect by usage_id = prior usage_context_id)
          loop
             dbms_output.put_line (c.identifier_usage_contexts);
          end loop;
       end get_scope;
       procedure p1
       as
       begin
          null;
       end p1;
       procedure p2
       as
       begin
          get_scope ($$plsql_unit, $$plsql_line);
       end p2;
    end pkg;
    Package body created.
    SQL> exec pkg.p2
      P2................ PROCEDURE           DEFINITION         
        PKG............. PACKAGE             DEFINITION         
        PKG............. PACKAGE             DECLARATION        
    PL/SQL procedure successfully completed.

  • Can we declare a Cursor in Package Specs?

    Dear buddies
    Can I Declare a Cursor in Package Specs so that I can call that cursor and use its data in some procedures and functions of package. Otherwise I've to write that cursor for every sub-program of a package which I don't feel a smart way to accomplish the job.

    Hi,
    here is a short example with the whole way down. Maybe the concept is getting clearer with this:
    first of all, if you do not have the table emp, here the DDL for this example.
    Be carefull, works only for german clients because of the names of months, sorry for that.
    CREATE TABLE EMP
    (EMPNO NUMBER(4) NOT NULL,
    ENAME VARCHAR2(10),
    JOB VARCHAR2(9),
    MGR NUMBER(4),
    HIREDATE DATE,
    SAL NUMBER(7, 2),
    COMM NUMBER(7, 2),
    DEPTNO NUMBER(2));
    set echo on
    INSERT INTO EMP VALUES
    (7369, 'SMITH', 'CLERK', 7902,
    TO_DATE('17-DEZ-1980', 'DD-MON-YYYY'), 800, NULL, 20);
    INSERT INTO EMP VALUES
    (7499, 'ALLEN', 'SALESMAN', 7698,
    TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600, 300, 30);
    INSERT INTO EMP VALUES
    (7521, 'WARD', 'SALESMAN', 7698,
    TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30);
    INSERT INTO EMP VALUES
    (7566, 'JONES', 'MANAGER', 7839,
    TO_DATE('2-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20);
    INSERT INTO EMP VALUES
    (7654, 'MARTIN', 'SALESMAN', 7698,
    TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);
    INSERT INTO EMP VALUES
    (7698, 'BLAKE', 'MANAGER', 7839,
    TO_DATE('1-MAI-1981', 'DD-MON-YYYY'), 2850, NULL, 30);
    INSERT INTO EMP VALUES
    (7782, 'CLARK', 'MANAGER', 7839,
    TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10);
    INSERT INTO EMP VALUES
    (7788, 'SCOTT', 'ANALYST', 7566,
    TO_DATE('09-DEZ-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
    INSERT INTO EMP VALUES
    (7839, 'KING', 'PRESIDENT', NULL,
    TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);
    INSERT INTO EMP VALUES
    (7844, 'TURNER', 'SALESMAN', 7698,
    TO_DATE('8-SEP-1981', 'DD-MON-YYYY'), 1500, 0, 30);
    INSERT INTO EMP VALUES
    (7876, 'ADAMS', 'CLERK', 7788,
    TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);
    INSERT INTO EMP VALUES
    (7900, 'JAMES', 'CLERK', 7698,
    TO_DATE('3-DEZ-1981', 'DD-MON-YYYY'), 950, NULL, 30);
    INSERT INTO EMP VALUES
    (7902, 'FORD', 'ANALYST', 7566,
    TO_DATE('3-DEZ-1981', 'DD-MON-YYYY'), 3000, NULL, 20);
    INSERT INTO EMP VALUES
    (7934, 'MILLER', 'CLERK', 7782,
    TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);2. Package Spec:
    create or replace
    package test_cursor as
      --Type for the returncode of the function
      TYPE typ_emp IS TABLE OF emp%rowtype;
      --Array for fetching, of course also possible in the body
      t_emp typ_emp;
      --function wich returns the array from fetching the cursor
      function get_emp return typ_emp;
      --function for manupilation data retrieved by the function
      PROCEDURE man_emp;
    end test_cursor;3. Package Body
    create or replace
    package body test_cursor as
      FUNCTION get_emp RETURN typ_emp AS
      cursor c_emp is select * from emp;
      BEGIN
        open c_emp;
        fetch c_emp BULK COLLECT INTO t_emp;
        CLOSE c_emp;
        --t_emp returns the whole table set from emp
        return t_emp;
      end get_emp;
      PROCEDURE man_emp AS
      --just for not confusing names, is the same as t_emp of course
      v_emp_array typ_emp;
      BEGIN
        --call the function and retrieve the whole data set
        v_emp_array := get_emp;
        --now manipulate the data, in this case just write the names to the calling client
        FOR rec IN v_emp_array.FIRST .. v_emp_array.LAST
        loop
          dbms_output.put_line(v_emp_array(rec).ename);
        end loop;
      end man_emp;
    end test_cursor;4. Calling the procedure
    SET serveroutput ON
    exec test_cursor.man_emp;5. And this is the result:
    anonymer Block abgeschlossen
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLERPlease be aware, this is just for demonstration purpose, of course it makes no sense to display the names this way. But how to call a funktion returning arrays with datasets from fetching cursors is shown here.
    Hth
    Joerg

Maybe you are looking for