Using package constant in SQL

I am trying to use a package constant in a query as follows:
SELECT field1 FROM table t WHERE CEIL(sysdate - t.field2) > schema.package.constant
field1 is a name
field2 is a timestamp
constant is an integer indicating the expiration time in days
basically I am trying to find all expired items.
I get the error "ORA-06553: PLS-221: 'constant' is not a procedure or is undefined" on this query.
I use this same query as a cursor in the package itself with no errors.

Unfortunately you cannot directly use package global variables in select statements like this.
One workaround is to use bind variables for that:
<p>
SQL> CREATE OR REPLACE PACKAGE pkg
AS
   myconstant   VARCHAR (20) := 'This is my constant';
END pkg;
Package created.
SQL> VAR myconstant  VARCHAR2 (20)
SQL> EXEC :myconstant :=  pkg.myconstant
PL/SQL procedure successfully completed.
SQL> SELECT :myconstant
  FROM DUAL
:MYCONSTANT                                                                    
This is my constant                                                            

Similar Messages

  • Using package constants in package SQL - acts as bind variable or literal?

    I'm looking for confirmation on the performance impact of using package constants in package SQL.
    Let's say I have a number of queries in package code that refer to various literals that are prone to typos e.g. "CANCELLED" instead of "CANCELED". To reduce the chances of this happening, I have an APP_GLOBALS package where I declare constants for each literal:
    C_CANCELED CONSTANT VARCHAR2(12) := 'CANCELED';And in queries that refer to literal 'CANCELED' I use APP_GLOBALS.C_CANCELED instead. This way the typo is caught during compilation. For example:
    BEGIN
    --Do something with all 'Canceled' orders
      FOR r IN (SELECT order_id
                  FROM orders
                 WHERE status = APP_GLOBALS.C_CANCELED)
      LOOP
      END LOOP;
    END;Assume that:
    - the STATUS column is indexed
    - the possible values are PENDING, APPROVED, CANCELED
    - a small percentage of orders are CANCELED
    From the optimizer's perspective is the query equivalent to
    SELECT order_id
      FROM orders
    WHERE status = :varor
    SELECT order_id
      FROM orders
    WHERE status = 'CANCELED'?
    According to what I see in v$sqltext_with_newlines, it's the first one. Can anyone suggest an alternative way of replacing literals in package SQL to prevent typos? Worst case, I suppose I can start with constants so that it compiles successfully then do a global replace of the constants with the literals.

    Can anyone suggest an alternative way of replacing literals in package SQL to prevent typos?I cannot think of any. But, here is the thing. If the typos are there, then, it technically is a bug even though both the codes would compile. The bug will be hunted down when the program doesn't work as intended. Wouldn't most typos be caught in unit testing of the code?
    Also, if you replace a string literal with a variable, then, maybe (just maybe, depending on your version of the dbms), it may end up picking a different execution plan. That might be an unintended consequence.

  • Using named constants in SQL rather than magic numbers

    We are running Oracle 7.3.4. In our system we have a number of
    tables that just store static data. For example, we have a table
    that stores the different types of statuses that a docket can
    have:
    Docket_Status: docket_status_id NUMBER(8), description VARCHAR
    (100)
    It has a small number of records as follows:
    docket_status_id description
    1 New
    2 Issued
    3 Completed
    4 Finalised
    and so on.
    When we want to select all of the dockets with a status of
    "New", we could do something like:
    select d.*
    from docket d
    where d.docket_status_id = 1
    However, this SQL statement is not particularly readable or
    maintainable since the "1" is meaningless unless you have
    memorised the id fields for the docket.
    So we defined constants for each of the static data tables, in a
    package of their own:
    PACKAGE DOCKET_STATUS_PL IS
    New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 1;
    Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 2;
    Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 3;
    and so on.
    Ideally you could directly reference these values in SQL as
    follows:
    select d.*
    from docket d
    where d.docket_status_id = Docket_Status_Pl.New_Id
    But SQL does not let allow this - an invalid column error is
    raised when this is parsed.
    So the package must then be changed to have functions pass back
    each of the constants.
    PACKAGE DOCKET_STATUS_PL IS
    FUNCTION New_Id RETURN NUMBER;
    PRAGMA RESTRICT_REFERENCES(New_Id, WNDS, WNPS);
    FUNCTION Issued_Id RETURN NUMBER;
    PRAGMA RESTRICT_REFERENCES(Issued_Id, WNDS, WNPS);
    FUNCTION Completed_Id RETURN NUMBER;
    PRAGMA RESTRICT_REFERENCES(Completed_Id, WNDS, WNPS);
    and so on.
    PACKAGE BODY DOCKET_STATUS_PL IS
    N_New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 1;
    N_Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 2;
    N_Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 3;
    FUNCTION New_Id RETURN NUMBER IS
    BEGIN
    RETURN N_New_Id;
    END;
    FUNCTION Issued_Id RETURN NUMBER IS
    BEGIN
    RETURN N_Issued_Id;
    END;
    and so on.
    Once these functions have been defined in the packages, they can
    be called in a SQL statement as follows:
    select d.*
    from docket d
    where d.docket_status_id = Docket_Status_Pl.New_Id
    This makes the SQL statement a lot more readable, but has the
    unfortunate by-product of having the Docket_Status_Pl.New_Id
    function called for every row in the docket table. Although it
    is very quick to call, once there are thousands of records in
    the docket table this can add up to a lot of extra
    time/processing.
    An alternative is to select the constant from the dual table as
    follows:
    select d.*
    from docket d
    where d.docket_status_id = (select Docket_Status_Pl.New_Id from
    dual)
    This works but is not really an ideal solution, since it
    decreases the readability of the SQL statement.
    Does anyone know of alternatives to this approach? Ideally
    package constants could be referenced from SQL, but this does
    not work under our version of Oracle. Do any later versions
    support this ability?
    Any suggestions would be much appreciated.
    null

    I don't understand why you cannot just select on the description
    column if you don't no the id. If speed is a problem create a
    unique not null index on the column description. Technically
    this should have been done since your id column is a is not
    the "REAL" primary key.
    Having said that you could also create a view on top of this
    table which mimics your package.
    CREATE OR REPLACE VIEW name_of_view AS
    SELECT DECODE(docket_status_id, 1, 'New_id',
    2, 'Issued_Id',
    3, 'Completed_Id',
    'OTHER') alt_description,
    docket_status_id description
    FROM name_of_table
    then select * from name_of_view
    where alt_description = 'New_id'
    Geoff Hardy (guest) wrote:
    : We are running Oracle 7.3.4. In our system we have a number of
    : tables that just store static data. For example, we have a
    table
    : that stores the different types of statuses that a docket can
    : have:
    : Docket_Status: docket_status_id NUMBER(8), description VARCHAR
    : (100)
    : It has a small number of records as follows:
    : docket_status_id description
    : 1 New
    : 2 Issued
    : 3 Completed
    : 4 Finalised
    : and so on.
    : When we want to select all of the dockets with a status of
    : "New", we could do something like:
    : select d.*
    : from docket d
    : where d.docket_status_id = 1
    : However, this SQL statement is not particularly readable or
    : maintainable since the "1" is meaningless unless you have
    : memorised the id fields for the docket.
    : So we defined constants for each of the static data tables, in
    a
    : package of their own:
    : PACKAGE DOCKET_STATUS_PL IS
    : New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 1;
    : Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 2;
    : Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE := 3;
    : and so on.
    : Ideally you could directly reference these values in SQL as
    : follows:
    : select d.*
    : from docket d
    : where d.docket_status_id = Docket_Status_Pl.New_Id
    : But SQL does not let allow this - an invalid column error is
    : raised when this is parsed.
    : So the package must then be changed to have functions pass back
    : each of the constants.
    : PACKAGE DOCKET_STATUS_PL IS
    : FUNCTION New_Id RETURN NUMBER;
    : PRAGMA RESTRICT_REFERENCES(New_Id, WNDS, WNPS);
    : FUNCTION Issued_Id RETURN NUMBER;
    : PRAGMA RESTRICT_REFERENCES(Issued_Id, WNDS, WNPS);
    : FUNCTION Completed_Id RETURN NUMBER;
    : PRAGMA RESTRICT_REFERENCES(Completed_Id, WNDS, WNPS);
    : and so on.
    : PACKAGE BODY DOCKET_STATUS_PL IS
    : N_New_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE :=
    1;
    : N_Issued_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE :=
    2;
    : N_Completed_Id CONSTANT Docket_Status.Docket_Status_Id%TYPE :=
    3;
    : FUNCTION New_Id RETURN NUMBER IS
    : BEGIN
    : RETURN N_New_Id;
    : END;
    : FUNCTION Issued_Id RETURN NUMBER IS
    : BEGIN
    : RETURN N_Issued_Id;
    : END;
    : and so on.
    : Once these functions have been defined in the packages, they
    can
    : be called in a SQL statement as follows:
    : select d.*
    : from docket d
    : where d.docket_status_id = Docket_Status_Pl.New_Id
    : This makes the SQL statement a lot more readable, but has the
    : unfortunate by-product of having the Docket_Status_Pl.New_Id
    : function called for every row in the docket table. Although it
    : is very quick to call, once there are thousands of records in
    : the docket table this can add up to a lot of extra
    : time/processing.
    : An alternative is to select the constant from the dual table as
    : follows:
    : select d.*
    : from docket d
    : where d.docket_status_id = (select Docket_Status_Pl.New_Id
    from
    : dual)
    : This works but is not really an ideal solution, since it
    : decreases the readability of the SQL statement.
    : Does anyone know of alternatives to this approach? Ideally
    : package constants could be referenced from SQL, but this does
    : not work under our version of Oracle. Do any later versions
    : support this ability?
    : Any suggestions would be much appreciated.
    null

  • How to use package in PL/SQL

    HI,
    How to create a pachake in PL/SQL.
    how can we atore the sql files in a package.
    expalin about the package concept in PL/SQL

    Here's the docs:
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10807/toc.htm

  • Accessing package CONSTANT in a SQL query

    Hi,
    Can anybody explain why I cannot access the package constant in a SQL but can use it in dbms_output.put_line:
    SQL> create package scott.xx_test_const_pkg
    2 as
    3 a constant varchar2(1) :='A';
    4 end;
    5 /
    Package created.
    SQL> begin
    2 dbms_output.put_line( scott.xx_test_const_pkg.a);
    3 end;
    4 /
    A <------------------THIS WORKS
    PL/SQL procedure successfully completed.
    SQL> select * from scott.emp where ename=scott.xx_test_const_pkg.a;
    select * from scott.emp where ename=scott.xx_test_const_pkg.a <------------------THIS DOES NOT WORK
    ERROR at line 1:
    ORA-06553: PLS-221: 'A' is not a procedure or is undefined
    Thanks

    You can't refer to a pl/sql package constant in a sql statement.
    Create a function that returns the constant value and then refer to the function in a sql statement.

  • Error "To run a SSIS package outside of SQL Server data tools you must install task name used in package of Integration service or highter.

    Hello Team,
    I am trying to execute a SSIS package from web page. When i try to do that i am getting following error.
    "To run a SSIS package outside of SQL Server data tools you must install <task name used in package> of Integration service or highter."
    In my machine Integration Services are installed and its service is also in running state.
    Please help me on this.
    Thanks,
    Ramesh
    Thanks, Ramesh Arige

    The SSIS package developed using SSIS 2008 Server R2 and Integrations Services 10.0 is exists in my machine. Is this wrong configuration, please help me on this.
    I am using the below code copied from CodeProject
    Thank you so much for responding.
    Ramesh
    Thanks, Ramesh Arige
    Which way are you using from the provided blog? Using 1) C# Code or 2) C# and Stored Procedure?
    Cheers,
    Vaibhav Chaudhari
    MCP, MCTS, MCSA (SQL Server 2012)

  • Package constants in DBMS_CRYPTO

    Anyone any idea why I can't reference the constants in the DBMS_CRYPTO package.
    I've looked in the package spec and they are there, and if I use the actual value then that works fine, but I can't reference it by name for some reason.
    SQL> create view vw_tab1 as select myid, dbms_crypto.hash(myclob, DBMS_CRYPTO.HASH_SH1) as myclob from mytab1;
    create view vw_tab1 as select myid, dbms_crypto.hash(myclob, DBMS_CRYPTO.HASH_SH1) as myclob from mytab1
    ERROR at line 1:
    ORA-06553: PLS-221: 'HASH_SH1' is not a procedure or is undefined
    SQL> create view vw_tab1 as select myid, dbms_crypto.hash(myclob, 3) as myclob from mytab1;
    View created.
    SQL>

    Hello
    It's not just dbms_crypto, it's package constants in general:
    SQL> create or replace package pkg_test
      2  as
      3  pc_test_const constant number:=1;
      4  end;
      5  /
    Package created.
    SQL> select pkg_test.pc_test_const from dual;
    select pkg_test.pc_test_const from dual
    ERROR at line 1:
    ORA-06553: PLS-221: 'PC_TEST_CONST' is not a procedure or is undefined
    SQL> select to_char(pkg_test.pc_test_const) from dual;
    select to_char(pkg_test.pc_test_const) from dual
    ERROR at line 1:
    ORA-06553: PLS-221: 'PC_TEST_CONST' is not a procedure or is undefinedI had a look in the docs to try to find the reason but I couldn't.
    HTH
    David

  • DBMS_JOB using Packaged Functions but Package goes invalid

    Is there any way to check a package while running a PL/SQL procedure to see if it's state is valid and then catch the exception?
    In my case usually just calling any function in the package 1x clears it up but the procedure in question runs as a DBMS_JOB it just keeps failing. This procedure could run often enough that Oracle will mark it as broken but I want to give it every shot at execution on time instead of having to make it wait till the next cycle.
    What I would like to do is to catch the exception for the package state being invalid and basically have it go back to the beginning of the procedure and give it another try before failing in case it is just a failure because the package has been altered.
    Is there any way to do this?

    Firstly, I'll copy/paste my standard response regarding package state going invalid as it usually helps to have an understanding of these things...
    Packages tend to fail because of their "package state". A package has a "state" when it contains package level variables/constants etc. and the package is called. Upon first calling the package, the "state" is created in memory to hold the values of those variables etc. If an object that the package depends upon e.g. a table is altered in some way e.g. dropped and recreated, then because of the database dependencies, the package takes on an INVALID status. When you next make a call to the package, Oracle looks at the status and sees that it is invalid, then determines that the package has a "state". Because something has altered that the package depended upon, the state is taken as being out of date and is discarded, thus causing the "Package state has been discarded" error message.
    If a package does not have package level variables etc. i.e. the "state" then, taking the same example above, the package takes on an INVALID status, but when you next make a call to the package, Oracle sees it as Invalid, but knows that there is no "state" attached to it, and so is able to recompile the package automatically and then carry on execution without causing any error messages. The only exception here is if the thing that the package was dependant on has changes in such a way that the package cannot compile, in which case you'll get an Invalid package type of error.
    And if you want to know how to prevent discarded package states....
    Move all constants and variables into a stand-alone package spec and reference those from your initial package. Thus when the status of your original package is invlidated for whatever reason, it has no package state and can be recompiled automatically, however the package containing the vars/const will not become invalidated as it has no dependencies, so the state that is in memory for that package will remain and can continue to be used.
    As for having package level cursors, you'll need to make these local to the procedures/functions using them as you won't be able to reference cursors across packages like that (not sure about using REF CURSORS though.... there's one for me to investigate!)
    This first example shows the package state being invalided by the addition of a new column on the table, and causing it to give a "Package state discarded" error...
    SQL> set serveroutput on
    SQL>
    SQL> create table dependonme (x number)
      2  /
    Table created.
    SQL>
    SQL> insert into dependonme values (5)
      2  /
    1 row created.
    SQL>
    SQL> create or replace package mypkg is
      2    procedure myproc;
      3  end mypkg;
      4  /
    Package created.
    SQL>
    SQL> create or replace package body mypkg is
      2    v_statevar number := 5; -- this means my package has a state
      3
      4    procedure myproc is
      5      myval number;
      6    begin
      7      select x
      8      into myval
      9      from dependonme;
    10
    11      myval := myval * v_statevar;
    12      DBMS_OUTPUT.PUT_LINE('My Result is: '||myval);
    13    end;
    14  end mypkg;
    15  /
    Package body created.
    SQL>
    SQL> exec mypkg.myproc
    My Result is: 25
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        VALID
    SQL>
    SQL>
    SQL> alter table dependonme add (y number)
      2  /
    Table altered.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        INVALID
    SQL>
    SQL> exec mypkg.myproc
    BEGIN mypkg.myproc; END;
    ERROR at line 1:
    ORA-04068: existing state of packages has been discarded
    ORA-04061: existing state of package body "SCOTT.MYPKG" has been invalidated
    ORA-06508: PL/SQL: could not find program unit being called: "SCOTT.MYPKG"
    ORA-06512: at line 1
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        INVALID
    SQL>
    SQL> exec mypkg.myproc
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        VALIDAnd this next example shows how having the package variables in their own package spec, allows the package to automatically recompile when it is called even though it became invalidated by the action of adding a column to the table.
    SQL> drop table dependonme
      2  /
    Table dropped.
    SQL>
    SQL> drop package mypkg
      2  /
    Package dropped.
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL> create table dependonme (x number)
      2  /
    Table created.
    SQL>
    SQL> insert into dependonme values (5)
      2  /
    1 row created.
    SQL>
    SQL> create or replace package mypkg is
      2    procedure myproc;
      3  end mypkg;
      4  /
    Package created.
    SQL>
    SQL> create or replace package mypkg_state is
      2    v_statevar number := 5; -- package state in seperate package spec
      3  end mypkg_state;
      4  /
    Package created.
    SQL>
    SQL> create or replace package body mypkg is
      2    -- this package has no state area
      3
      4    procedure myproc is
      5      myval number;
      6    begin
      7      select x
      8      into myval
      9      from dependonme;
    10
    11      myval := myval * mypkg_state.v_statevar;  -- note: references the mypkg_state package
    12      DBMS_OUTPUT.PUT_LINE('My Result is: '||myval);
    13    end;
    14  end mypkg;
    15  /
    Package body created.
    SQL>
    SQL> exec mypkg.myproc
    My Result is: 25
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        VALID
    SQL>
    SQL> alter table dependonme add (y number)
      2  /
    Table altered.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        INVALID
    SQL>
    SQL> exec mypkg.myproc
    My Result is: 25
    PL/SQL procedure successfully completed.---------------------------------------------------------------------------------------------
    Secondly, from this above standard response, you can see how to check for package state if you want to determine it programatically.
    ;)

  • Using MapViewer from PL/SQL vs Java

    Hi group!
    The MapViewer User's Guide has this to say about using MapViewer from PL/SQL:
    "The usage model for the SDO_MVCLIENT package is almost identical to that of
    MapViewer JavaBean-based API" etc etc .. "For usage and reference information about specific functions or procedures, see the description of the associated JavaBean-Based API. methods and interfaces in Chapter 4"
    If I don't misunderstand the basic concept, in a Java Web App (using the MapViewer Bean) you create a MapViewer object for each HTTP-user-session, like so:
    MapViewer mv = new MapViewer("http://my_corp.com:8888/mapviewer/omserver");
    ... which you would then store in the user's session object, so that the MapViewer Bean conveniently holds the map's state on the user's behalf.
    To do the equivalent in PL/SQL, the User's Guide suggests:
    "connect scott/tiger
    call sdo_mvclient.createmapviewerclient(
    'http://www.mycorp.com:8888/mapviewer/omserver') ;
    The preceding example creates, in the current session, a unique MapViewer client
    handle to the MapViewer service URL"
    Does "current session" refer to the HTTP-user-session? While I've used PL/SQL before, I've not used the PL/SQL Web Toolkit. Is the session handling implicit here (and invisible?) or should the sdo_mvclient be subsequently stored in the PL/SQL equivalent of a (J2EE) HttpSession object?
    YT

    Part of the answer will depend on how you plan to deploy the application. If you have a few, local clients you could go with the traditional client/server model. If you have a lot of clients and/or they are spread out over a relatively large area (like a campus setting), a web front-end will save you a lot of hassels down the road when it comes time to upgrade.
    Regardless of the the front end, I can tell you that I have been greatly impressed with the throughput you can get by moving most of the code to PL/SQL packages. A few years ago we reworked a VB/Oracle app by moving a lot of the code out of VB and into packages, leaving the client to essentially call procedures and format the output. We had more than a 3x performance increase on the same hardware and our network utilization decreased noticably.
    I am now in the process of replacing the client code with Java servlets/JSP, primarily because of the maintenance hassles I mentioned earlier. There are some limitations with an HTML page but most of these have been cosmetic so far.
    We are still relying heavily on PL/SQL packages. The servlet code basically gets a request, calls a package to get the data, then hands the results to a JSP page. The JSP then formats the output and sends it to the client. We are little more than halfway through the re-write, but it appears performance will increase again. Not as noticably as before, but I will take what I can get. As you have seen, once something is rolled out it always ends up getting used more than you anticipated. Better to over-engineer now than have to patch it once it is live.
    HTH

  • Using packaged functions in Apex

    Hi,
    I'm fairly new to apex and I am about to write an app which needs to access a SQL server database. My local dba has set up the transparent gateway and I can select from and update the SQLServer database no problem via a db link. What I need to decide is whether to code the sql for reports etc directly into the apex page or to call a pl/sql function returning a select statement. I would like to have all the code in packages as a lot of it will be used by multiple apps in future but is there any extra overhead in doing this:
    declare
    l_sql varchar2(4000);
    begin
    select package.function into l_sql from dual;
    return l_sql;
    end;
    rather than coding the SQL directly in the page? Also is there a more efficient way of using packaged functions to select data rather that just have it returning sql statements.
    Thanks in advance.
    Dave

    Hi
    I only use function returning select when I have a strong reason to do so, because it is so much more difficult to test and maintain. Not sure about performance, but I think it is not that much worse.
    If you simply want to reuse SELECT statements, you could use views instead.
    Anyway, if you decide to use the package solution, at least you can make it much simpler -- just code like this in the page:
    return package.function;
    I hope this helps.
    Luis

  • Using PPR in PL/SQL generated webpages

    I have a question about using PPR with web pages written in PL/SQL.
    I have a dropdown menu that I want to limit by the value selected in the preceding dropdown (pick-list).
    So far I have not found much information on PPR other than on OTN, and was unable to find any PL/SQL coding samples; so I guess I should ask...
        - Is it possible to use PPR in a webpage generated from a stored PL/SQL procedure/package?
        - If so, how do I make use of PPR in PL/SQL?
        - If it is NOT possible to use PPR with PL/SQL, what other methods could I make use of other than JavaScript?
    Thank you in advance,
    Charlie

    When I run the following script, the 2nd time the test1 procedure runs, it fails with "PLS-00905: object TEST1 is invalid", whereas test2 runs fine both times.
    Feel free to try it yourself!
    create table boneist_test (col1 number, col2 varchar2(10));
    insert into boneist_test values (1, 'a');
    commit;
    create procedure test1
    is
      v_num number;
      v_var varchar2(10);
    begin
      select *
      into v_num, v_var
      from boneist_test
      where rownum = 1;
    end test1;
    create procedure test2
    is
      v_num number;
      v_var varchar2(10);
    begin
      select col1, col2
      into v_num, v_var
      from boneist_test
      where rownum = 1;
    end test2;
    begin
      test1;
    end;
    begin
      test2;
    end;
    alter table boneist_test add (col3 number);
    begin
      test1;
    end;
    begin
      test2;
    end;
    drop table boneist_test;
    drop procedure test1;
    drop procedure test2;

  • Using Collection in a sql statement.

    Hi I want to perform the following statement:
    DELETE FROM ALLOCATION_ELEC_MATRIX
    WHERE dgo_ean_id in (lt_inter_dgos);
    The collection lt_inter_dgos holds my dgo_ean_id's(varchars).
    I can't find a way to get it to work.
    The collection is declared as follows:
    TYPE Interface_param_dgos IS TABLE OF VARCHAR2(20);
    lt_inter_dgos Interface_param_dgos := Interface_param_dgos();
    then later on the collection gets filled. But how can i get it to work to use it in my sql statement?
    I don't won't to use a for loop around it since it would give me problems if I use more collections with a different amount of values in it.

    The standard approach is to use SQL collection type and table function,
    for example
    SQL> create TYPE Interface_param_dgos IS TABLE OF VARCHAR2(20);
      2  /
    Type created.
    SQL> create or replace package my_pkg
      2  is
      3   lt_inter_dgos Interface_param_dgos := Interface_param_dgos();
      4   function get_coll return Interface_param_dgos;
      5  end;
      6  /
    Package created.
    SQL> create or replace package body my_pkg
      2  is
      3   function get_coll return Interface_param_dgos
      4   is
      5   begin
      6    return lt_inter_dgos;
      7   end;
      8  end;
      9  /
    Package body created.
    SQL> begin
      2   my_pkg.lt_inter_dgos.extend(3);
      3   my_pkg.lt_inter_dgos(1) := 'SMITH';
      4   my_pkg.lt_inter_dgos(2) := 'KING';
      5   my_pkg.lt_inter_dgos(3) := 'ALLEN';
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    SQL> select ename from emp;
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> delete from emp where ename in (select column_value from table(my_pkg.get_coll));
    3 rows deleted.
    SQL> select ename from emp;
    ENAME
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    11 rows selected.Rgds.

  • Package creation in SQL*Plus

    DB Version: 10gR2
    Sometimes, we have huge Packages, stored procs to compile. I don't want the entire code of Package to be 'Echoed'. I just want to see if a particular package/SP/Function has been Compiled succesfully or not.
    So, i set the ECHO to off.
    set echo off
    set feedback on
    set define off
    Spool test9.log
    create table xyz_tab1
      empid          varchar2(15 byte)           not null,
      emp_Code       varchar2(15 byte)           not null,
      updated_c      varchar2(1 byte)            not null
    alter table xyz_tab1 add constraint pk_xyz_tab1 primary key (empid, emp_Code);
    CREATE OR REPLACE PACKAGE lms
    AUTHID CURRENT_USER
    AS
    FUNCTION get_emp_x
       (in_code            NUMBER,
       iv_period            VARCHAR2,
       iv_emp_id            VARCHAR2,
       id_date            DATE
       RETURN VARCHAR2;
    end ;
    spool off;But it doesn't say which procedure got created (or errored in compilation)
    SQL > drop table xyz_tab1;
    Table dropped.
    MANU:rac > @test.sql
    Table created.
    Table altered.
    Package created.
    SQL >How can I get the Package/SP name to be printed ?

    you could use PROMPT:
    PROMPT Create Package: lms
    CREATE OR REPLACE PACKAGE lms
    AUTHID CURRENT_USER
    AS
    FUNCTION get_emp_x
       (in_code            NUMBER,
       iv_period            VARCHAR2,
       iv_emp_id            VARCHAR2,
       id_date            DATE
       RETURN VARCHAR2;
    end ;
    {Code}
    Output:
    Create Package: lms
    Package created.
    Edited by: jowahl on 19.10.2010 13:35                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Reading package contents in SQL Plus

    Hi,
    I'd asked a similar question last week, but didn't see it responded to with a proper reply.
    Ive created a package in SQL Plus, and much like you use the DESCRIBE command to see info on tables that are created, I'd like to see the contents and script of my package to verify some contents of it.
    How can I do that? Or can I do that?
    I've read this:
    http://download-west.oracle.com/docs/cd/A87860_01/doc/appdev.817/a77069/08_packs.htm#4376
    But it doesn't explain within how to go about doing that if indeed that is possible at all. Would anyone that knows if this can be done please reply with the way to do it?
    Thanks!

    Hi,
    You can query USER_SOURCE (or ALL_SOURCE, at your choice) to get what you need.
    Consider:
    SQL> create or replace package small is
      2    procedure Test;
      3  end;
      4  /
    Package created.
    SQL> create or replace package body small is
      2
      3  procedure Test is
      4  begin
      5    null;
      6  end;
      7
      8  end;
      9  /
    Package body created.We just created simple package, for demonstration purposes. Now, we're about to view its source:
    SQL> column text format a100
    SQL>
    SQL> select line, text
      2    from user_source
      3   where name = 'SMALL'
      4     and type = 'PACKAGE'
      5   order by line;
          LINE TEXT
             1 package small is
             2   procedure Test;
             3 end;
    SQL> select line, text
      2    from user_source
      3   where name = 'SMALL'
      4     and type = 'PACKAGE BODY'
      5   order by line;
          LINE TEXT
             1 package body small is
             2
             3 procedure Test is
             4 begin
             5   null;
             6 end;
             7
             8 end;
    8 rows selected.
    SQL>Alternatively, you can make use of DBMS_METADATA package.
    Regards.

  • SSIS: To run a SSIS package outside of SQL Server Data Tools you must install SCR - DP1 Connections of Integration Services or higher

    We have SSIS installed on a machine that is not part of a cluster but it is accessible by the cluster.
    Our job we have running on the cluster is failing with the following error:
    Error: 2014-01-31 09:14:37.52     Code: 0xC000F427     Source: SCR - DP1 Connections  
    Description: To run a SSIS package outside of SQL Server Data Tools you must install SCR - DP1 Connections of Integration Services or higher.  End Error
    Any advice or information on how to resolve this would be great.
    Many Thanks.

    Hi NessaBella,
    Integration Services service is not a cluster-aware service, and does not support failover from one cluster node to another. Therefore, in a clustered environment, Integration Services should be installed and started as a stand-alone service on each node
    in the cluster.
    Based on the error message, it seems that SSIS is not installed on the cluster node on which the job was running. Although SSIS is installed on a machine that is not part of the cluster and can be accessed by each cluster node, the SSIS service installed
    on a remote server cannot be used a cluster node. So, please install the shared feature SQL Server Integration Services on each cluster node. Besides, if certain packages need to run in 32-bit mode in certain jobs and the SQL Server installed is 64-bit version,
    you also need to install BIDS/SSDT on the cluster node to get the 32-bit runtime of SSIS.
    References:
    Integration Services (SSIS) in a Cluster
    Loading and Running a Remote Package Programmatically
    Regards,
    Mike Yin
    TechNet Community Support

Maybe you are looking for