Packaged Function

Hey Folks,
Still trying to get a handle on Packages but somewhere I got off the track.
The INOUT parameter returns this error
PLS-00103: Encountered the symbol "CHAR" when expecting one of
the following:
:= . ) , @ % default character
The symbol ":=" was substituted for "CHAR" to continue.
Getting me back on the path would be much appriciated.
Regards,
Mat
VARIABLE g_output VARCHAR2(30)
VARIABLE g_username VARCHAR2(8)
VARIABLE g_password VARCHAR2(8)
VARIABLE g_ck CHAR
BEGIN
:g_username := 'gma1';
:g_password := 'goofy';
:g_ck := 'N';
END;
CREATE OR REPLACE PACKAGE login_pkg IS
FUNCTION log_in_pf
(p_username IN VARCHAR2,
p_password IN VARCHAR2,
p_ck INOUT CHAR)
RETURN CHAR;
END;
CREATE OR REPLACE PACKAGE BODY login_pkg IS
FUNCTION log_in_pf
(p_username IN VARCHAR2,
p_password IN VARCHAR2,
p_ck INOUT CHAR)
RETURN CHAR
IS
lv_username_txt bb_shopper.username %TYPE;
lv_password_txt bb_shopper.password%TYPE;
BEGIN
SELECT username, password
INTO lv_username_txt, lv_password_txt
FROM bb_shopper
WHERE username = p_username
AND password = p_password;
IF lv_username_txt||lv_password_txt = p_username||p_password THEN
p_ck := 'Y';
ELSE p_ck := 'N';
END IF;
RETURN p_ck;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Invalid username or password');
END log_in_pf;
END;
BEGIN
:g_output := login_pkg.log_in_pf(:g_username, :g_password, :g_ck);
DBMS_OUTPUT.PUT_LINE( :g_output);
END;
/

Hi,
You must put space between in and out ( IN OUT ).
http://www.psoug.org/snippet/FUNCTIONS_IN_OUT_parameter_873.htm
Regards Salim
SQL>  CREATE OR REPLACE PACKAGE login_pkg IS
  2  FUNCTION log_in_pf
  3  (p_username IN VARCHAR2,
  4  p_password IN VARCHAR2,
  5  p_ck IN OUT CHAR)
  6  RETURN CHAR;
  7* END;
SQL> /
Package created.
SQL>

Similar Messages

  • Calling Oracle Package Function from Visual Basic

    Hi,
    Oracle Client 8.04
    Oracle ODBC Driver 8.00.04
    VB 6.0
    Windows 2000
    I'm stumped here. I want to have a Oracle stored procedure run a
    query and return a result set which I can assign to a recordset
    object in VB. Based on things I've read here and on MS's site,
    here's what I've done:
    In the Oracle Schema Manager under the Packages folder I created
    the following package:
    PACKAGE test
    IS
    TYPE test_cur IS REF CURSOR;
    FUNCTION mycur RETURN test_cur;
    END test;
    and under the Package Body folder created:
    PACKAGE BODY test
    IS
    FUNCTION mycur RETURN test_cur
    IS
    c_return test_cur;
    BEGIN
    OPEN c_return FOR
    SELECT * FROM table_A;
    RETURN c_return;
    CLOSE c_return;
    END mycur;
    END test;
    They both compile without errors and in Oracle SQL Worksheet I
    can enter the following:
    variable x refcursor;
    execute :x :=test.mycur;
    print x;
    and the query results are displayed as expected.
    The problem is trying to get the result back into a VB recordset
    object.
    In VB 6.0 I have done this:
    Dim RS As ADODB.Recordset
    Dim Conn As ADODB.Connection
    Dim sConnection As String
    Dim sSQL As String
    sSQL = "{call test.mycur}"
    sConnection = "Provider=MSDASQL;UID=" & sUserID & ";PWD=" &
    sPassword & ";Driver={Microsoft ODBC for Oracle}; Server=" &
    sInstance & ";"
    Conn.Open sConnection
    RS.CursorLocation = adUseClient
    RS.Open sSQL, Conn, adOpenForwardOnly, adLockOptimistic,
    adCmdStoredProc ' or adCmdText
    but get:
    ?err.Number -2147217900
    ?err.Source Microsoft OLE DB Provider for ODBC Drivers
    ?err.Description [Microsoft][ODBC driver for Oracle]Syntax error
    or access violation
    The problem is not with the connection or permissions, since the
    query works fine when I just use the select statement in the
    package function as the string, instead of calling the function
    in the package (eg sSQL = "Select * from table_A") and can
    process the resulting recordset in VB.
    I've also tried variations using:
    Set RS = Conn.Execute("{call test.mycur}")
    or using a Command object something like:
    Dim com As ADODB.Command
    Set com = New ADODB.Command
    With Conn
    .ConnectionString = sConnection
    .CursorLocation = adUseClient
    .Open
    End With
    With com
    .ActiveConnection = Conn
    .CommandText = sSQL
    .CommandType = adCmdText
    End With
    Set RS.Source = com
    RS.Open
    But still get the same errors. Any help is appreciated. Also, in
    my package body, is it necessary to explicitly close the cursor,
    or does the function just exit when it executes the return and
    not ever hit the close statement?
    Thanks,
    Ed Holloman

    Hi
    i don't know if you got your answer, but i work with VB and
    Oracle.
    the procedure in the DB should have the cursor like you writen
    in your mail.
    to call a procedure in Oracle and get the data back
    into a recordset you shuld use a Command object like this:
    Dim conn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rs As ADODB.Recordset
    Set conn = CreateObject("adodb.connection")
    Set cmd = CreateObject("adodb.command")
    Set rs = CreateObject("adodb.recordset")
    With conn
    .ConnectionString = ""
    .CursorLocation = adUseClient
    .Open
    End With
    'THE IMPORTENT SECTION IS THIS WHERE YOU SET THE COMMAND TO THE
    STORE PROCEDURE TYPE
    With cmd
    .ActiveConnection = conn
    .CommandText = "proc.fun"
    .CommandType = adCmdStoredProc
    End With
    'Then you set the rs to the command
    Set rs = cmd.Execute
    Set conn = Nothing
    Set rs = Nothing
    Set cmd = Nothing

  • 2.1.0.62: Problem with Package.Functions and Unit Tests

    I like the new Sqldeveloper - I startet trying Unit Tests as described here: Link: [http://www.oracle.com/technology/obe/11gr2_db_prod/appdev/sqldev/sqldev_unit_test/sqldev_unit_test.htm#t4]
    It worked with a test-procedure. Now i am trying to test my package functions, but all i get is this:
    Die folgende Prozedur wurde ausgeführt.
    Ausführungsaufruf
    BEGIN
    :1 := "PKG_MYPACK"."CREATEFUNCTION"(IN_PROGRAMMEID=>:2,
    IN_AMOUNT=>:3,
    IN_SWS=>:4);
    END;
    Bind-Variablen verwendet
    1 INTEGER OUT (null)
    2 INTEGER IN 1
    3 INTEGER IN 10
    4 INTEGER IN 11
    Ausführungsergebnisse
    ERROR
    Ungültige Konvertierung angefordert
    oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
    oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:110)
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:171)
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:439)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7723)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7496)
    oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7978)
    oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4063)
    oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:221)
    oracle.dbtools.raptor.datatypes.strategies.callablestatement.CallableBindingDatum.customBindIN(CallableBindingDatum.java:135)
    oracle. ...
    what can i do?

    Created
    Bug 8976245 - EA1: UNIT_TEST: INVALID CONVERSION ERROR USING INTEGER PARAMETER
    and have asked bug responder to keep you updated on status here in the forum.
    Bad news is that any INTEGER parameter for which you specify a non-null value will fail.
    Possibly helpful news is that if you create a 'clone' of you function using NUMBER as the data type, you can continue to experiment with how unit testing may be of use to you.
    Sorry no instant answer. :(
    Brian
    SQL Developer Team

  • Regarding Packaged function...!

    Hi,
    i have a packaged function which i am trying to use in my
    report query....
    i am passing 2 params for this function.....
    one is report parameter and the other one is a col in the select query....
    so i need to get rows returned based on the conditon satisfying in the query...!
    i have a select stat for each condition which will return one column value to the
    local variable which i am trying to check in the condition....
    My problem is whenever i am running it it's get hanged or it takes a lot of time..
    if iam hard coding the parameter value it's fetching records...
    plz do the needful....
    select
    a.latest_version_no,
    a.custom_ref_no,
    d.customer_name1,
    etc.....
    etc.....
    from
    cstbs_contract a,
    fxtbs_contract_master b,
    cstbs_contractis c,
    sttms_customer d
    where
    a.contract_ref_no=b.contract_ref_no
    and
    a.latest_version_no=b.version_no
    and
    b.contract_ref_no = c.contract_ref_no
    and
    d.customer_no=b.counterparty
    and
    NVL(b.netting_status,'N') ='N'
    AND
    b.VERSION_NO = (SELECT MAX(M1.VERSION_NO) FROM FXtbs_contract_master M1 WHERE M1.CONTRACT_REF_NO = B.CONTRACT_REF_NO)
    AND
    B.CONTRACT_REF_NO IN(SELECT PK_RET_ROWS.FN_RET_ROWS(:P_INST_CHANGE,'FXWFWXP023290102') FROM DUAL)

    Ravi
    For one thing you could avoid the unnecessary select from dual:
    AND B.CONTRACT_REF_NO IN(SELECT PK_RET_ROWS.FN_RET_ROWS(:P_INST_CHANGE,'FXWFWXP023290102') FROM DUAL)can be changed to:
    AND B.CONTRACT_REF_NO = PK_RET_ROWS.FN_RET_ROWS(:P_INST_CHANGE,'FXWFWXP023290102')You could simplify further, to make sure you only evaluate the function once, and definitely drive off M1, then B:
    AND (B.CONTRACT_REF_NO, B.VERSION_NO) = (
    SELECT M1.CONTRACT_REF_NO, M1.VERSION_NO
    FROM FXtbs_contract_master M1
    WHERE M1.CONTRACT_REF_NO = PK_RET_ROWS.FN_RET_ROWS(:P_INST_CHANGE,'FXWFWXP023290102')
    )As for the speed: if you still have a problem, check you have the right indexes (eg on CONTRACT_REF_NO and (LATEST_)VERSION_NO for M1, A, B, C and on D.CUSTOMER_NO)?
    HTH
    Regards Nigel

  • 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

  • How to use type, packages, functions, and procedures in another schema ?

    I have two target schema in one OWB project, such as A and B. In a mapping of A, I would like to use some types, packages, functions, and procedures from B. I have tried the method of synonym as suggested, but I could not find the metadata of these when importing ... The only type of synonym I can import is the synonym for table. Is there a bug for synonym?
    If I cannot use synonym for this issue, is there another way to solve the problem?

    Now, in some instances you will absolutely need to create the second module as Carsten describes, however it should also be noted that you can reference objects in things like Expressions even if you have not loaded up the metadata. It is only when you need strong binding that it becomes neccessary to import objects. For everything else, as long as the reference will resolve at compile-time then you are good to go.
    For example, I have a function in one target schema (S1) and a private synonym to it in another(s2). A mapping in the S2 schema has an expression object that uses the synonym to the function in the expression property for a couple of the output attirbutes. The synonym has not been loaded into metadata - indeed OWB has no knowledge of its existance. But it resolves at compile time so the mapping validates and generates successfully.
    Mike

  • How to debug a Package / function in PL SQL developer ??

    How can we debug a Package / function in PL SQL developer ??
    i want to debug a code line by line

    Karthick_Arp wrote:
    This question does not belong to this fourm. We have a {forum:id=260} forum for such question.Not even there Karthick. PL/SQL Developer is a 3rd party tool, not Oracle's SQL Developer, so it doesn't even belong on the Oracle forums.

  • Using a packaged function in a query

    Hi ,
    I have read the following statement (correct option for the question)in 1z0-147 questions.
    The question is :: WHEN USING A PACKAGED FUNCTION IN A QUERY which of the following is true ::
    The packaged function cannot execute DML statements against the table that is being queriedI tried the following to understand the above statement
    create or replace package test_pk is
    function fn_test(i number) return number ;
    end;
    create or replace package body test_pk is
    function fn_test (i number) return number is
      j number:=1;
    begin
        insert into a values(200,300);
        commit;
       return j;
       end;
    end test_pk;  Upon executing the above function in the select statement
    select TEST_PK.FN_TEST(1) from dualI got the error saying that Can't perform DML Inside SElect
    Is this example for the above statement is TRUE ????
    Could you please explain me if my example is wrong
    Thanks
    Edited by: Smile on Nov 22, 2012 9:47 AM

    No, it is not true. Any function used in SQL is not allowed to perform a DML operation other than SELECT regardless if it is against the table that is being queried or not. Select is allowed against any table. And function in your example does INSERT which is not allowed. Also, Any function used in SQL is not allowed to perform commit/rollback/savepoint.
    SY.
    Edit: unless function is autonomous transaction.
    Edited by: Solomon Yakobson on Nov 22, 2012 10:22 AM

  • JPublisher generated wrapper package function name contains "ORIG_PKG"$FN

    jPublisher generated wrapper package function name contains "ORIG_PKG"$FN
    which shows compilation error as
    Compilation errors for PACKAGE BODY <schema>.JPUB_PLSQL_WRAPPER
    Error: PLS-00181: unsupported preprocessor directive '$FN'
    Line: 2699
    Text: FUNCTION "ORIG_PKG"$FN (P_SOURCE VARCHAR2,
    Along with this, the generated .sqlj file have a calling sqlj content having the same format as
    #sql [getConnectionContext()] __jPt_result = { VALUES(JPUB_PLSQL_WRAPPER."ORIG_PKG"$FN( ...
    This also show sqlj compilation error such as
    Error(91,5): Expected "$FN" and found ")" instead.
    and a warning
    Warning(91,5): Invalid SQL syntax at:
    JPUB_PLSQL_WRAPPER."ORIG_PKG"$FN(
    ^^^^
    Encountered "$FN" :
    Was expecting one of:
    <EOF>
    "AND" ...
    "BETWEEN" ...
    "IN" ...
    "IS" ...
    "LIKE" ...
    "NOT" ...
    "OR" ...
    "ROW" ...
    "AT" ...
    "MOD" ...
    "RANGE" ...
    <CONCAT_OP_> ...
    Any suggestion would be helpful. thank you.

    Just to put a proper closure to this thread, there were 2 issues with the Jdev version I was using (11.1.2.0.0)
    1) Wrapper for PL/SQL not getting generated properly.
    2) Webservice proxies are not getting generated properly.
    The 2 issues were taken care by generating the wrapper and proxy on a much higher version of Jdev.

  • Pass more parameter to the packaged function with REMAP_DATA in EXPDP

    1) can we pass more than one parameter to the packaged function specified in REMAP_DATA during DATA pump export?
    2) if yes to point#1 then, how can we pass rownum & some other columns value in the same record passed into the function?

    when all else fails, Read The Fine Manual
    http://download.oracle.com/docs/cd/E11882_01/server.112/e16536/dp_export.htm#sthref115

  • ORA-00904 and packaged function in report

    Oracle 9.2.0.7
    APEX 2.0
    Is APEX not able to deal with SQL that calls a packaged function?
    I ask because I'm able to execute this query:
    SELECT s.doc_id,
    s.last_name || ', ' || s.first_name full_name,
    s.p_id,
    s.create_date
    , rwa_wfrole.get_role_list(s.proj_id, s.p_id) wfrole_label
    FROM signatures_vw s
    WHERE s.proj_id = 182
    AND s.status = 'APPROVED'
    ORDER BY s.create_date, s.last_name, s.first_name
    in SQL*Plus, but not in the SQL Workshop or in a report region. In the latter case I get "ORA-00904 invalid identifier" for "rwa_wfrole.get_role_list"... which is a packaged function. Actually, to be more precise, it's a package in a remote database. In the APEX instance, I have a synonym pointing to it.
    Thanks for insight.
    -John

    I can't reproduce this in 10g. I did find bug 4177810 (Fixed in 9.2.0.8 Server Patch Set) that looks a bit like this problem.
      Description
        An unexpected ORA-904 can occur for some internally generated SQL
        when the select list contains non-column constants and the select
        appears in the FROM clause. This can occur for SQL produced for
        parallel query or for remote / distributed queries.
        Workaround:
          Rewrite the query to avoid constant expressions in the FROM clause select lists.***************************
    There are also recommendations dating way back that you should include the schema name in the Create Synonym statement.
    Scott

  • Execute Oracle Package Function call from FORTE

    Has anyone EVER successfully execute an Oracle Package Function call from FORTE
    via " sql execute procedure "?
    Here's my question, I am able to execute a stored procedure but hasn't figured
    out a way to execute a function which defined in a package. The syntax goes
    like this: sql execute procedure <PackageName>.<FunctionName> ( input
    input_parm, output output_parm). If anyone EVER successfully execute a
    function, please let me know, thanks.

    You'll need to provide a column alias for the function call:
    select func(val) as alias from dual

  • Calling a package function inside a sql

    Hi friends!!!
    First of all happy Christmas! And them please help! :)
    We have a query calling a package function:
    SELECT * FROM DW025H WHERE DW025H_NR=MPPCI.ENCR ('0000000000000000');There is a primary key just with one column DW025H_NR and the problem is that is not accessing by INDEX UNIQUE SCAN,
    it's accessing by TABLE ACCESS FULL.
    May be the problem is that we are calling a procedure inside the query?
    I have been able to run that query accessing by primary key from my computer but a workmate hasn't!
    We both are connecting the same data base 10.2.0.4 and using Oracle SQL Developer!
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 5343K| 1406M| 15670 (7)| 00:02:43 |
    |* 1 | VIEW | DW025H | 5343K| 1406M| 15670 (7)| 00:02:43 |
    |* 2 | FILTER | | | | | |
    | 3 | TABLE ACCESS FULL| DW025H | 5343K| 1406M| 15670 (7)| 00:02:43 |
    Predicate Information (identified by operation id):
    1 - filter("DW025H_NR"="MPPCI"."ENCRIPTAPAN"('0000000000000000'))
    2 - filter(CASE "OPS$SISINFO"."IS_USER_DNI"() WHEN 1 THEN
    SYS_AUDIT('OPS$SISINFO','DW025H','CMINFOGR001',3) ELSE NULL END IS
    NULL)
    The correct path would be:
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 276 | 3 (0)| 00:00:01 |
    |* 1 | FILTER | | | | | |
    | 2 | TABLE ACCESS BY INDEX ROWID| DW025H | 1 | 276 | 3 (0)| 00:00:01 |
    |* 3 | INDEX UNIQUE SCAN | PK_DW025H | 1 | | 2 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - filter(CASE "OPS$SISINFO"."IS_USER_DNI"() WHEN 1 THEN
    SYS_AUDIT('OPS$SISINFO','DW025H ','CMINFOGR001',3) ELSE NULL END IS NULL)
    3 - access("DW025H_NR"="MPPCI"."ENCR"('0000000000000000'))
    Please any ideas!?!?!
    Thanks a lot!
    José
    Edited by: jamv on Dec 20, 2011 10:50 AM

    Hello
    Have a read of this and try to pull together the information in it and post it up here. That will help immensely with getting to the root of your problem...
    HOW TO: Post a SQL statement tuning request - template posting
    In the mean time:
    From the execution plan you have extra predicates that aren't present in the query you supplied, so that's either not the SQL or you have something like VPD switched on.
    Anyway, there could be lots of reasons for the difference in execution plan. Sorry if this is very basic and possibly patronising question but it's always worth checking the basics I think - are you both definitely connecting to the same database? If so, have a look in v$sqlarea for this SQL statement and find the SQL_ID, use this to query v$sql and look at the child_number column.
    select
        sql_id
    from
        v$sqlarea
    where
        sql_text like '%SELECT * FROM DW025H WHERE DW025H_NR=MPPCI.ENCR%(''0000000000000000'')%'
    and
        sql_text not like '%v$sqlarea%'
    select child_number from v$sql where sql_id='<enter the sql id returned by the query above>'as an example...
    XXXX> select /* my sql statement*/ rownum id from dual;
            ID
             1
    1 row selected.
    Elapsed: 00:00:00.10
    XXXX> select sql_id from v$sqlarea where sql_text like '%my sql statement%'
    and sql_text not like '%v$sqlarea%';
    SQL_ID
    a6ss4v79udz6g
    1 row selected.
    Elapsed: 00:00:03.56
    XXXX> select child_number from v$sql where sql_id='a6ss4v79udz6g'
      2  /
    CHILD_NUMBER
               0
    1 row selected.   If you have more than one row in v$sql there could be differences in the optimiser environment. The supplied like shows you how to gather the information that should help find what the differences are if any.
    Also as a side note if you're calling PL/SQL functions from SQL, you can take advantage of subquery caching to help reduce the number of calls (depending on your version). As it stands, your function is most likely going to be called for every row - when there is only a single row returned, that's not necessarily a problem but for multiple rows, the overhead can quickly grow. If there's no way to get rid of the function call, select the function from dual instead i.e.
    SELECT * FROM DW025H WHERE DW025H_NR= (SELECT MPPCI.ENCR%('0000000000000000') FROM dual);This also (as I learnt a couple of weeks ago) works when you're using columns in the table your selecting from as parameters to the function.
    HTH
    David

  • When i export schema Packages,function will export or not??

    Hi,
    i am importing schema so in that schema, i have Packages,function, Procedure, is there, so all packages and proedure etc.. will export or not??? pls tell me sir...
    Thank you,

    Hi,
    >>will export or not??? pls tell me sir...
    Yourself can see the results ...
    Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    Export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
    server uses WE8ISO8859P1 character set (possible charset conversion)
    . exporting pre-schema procedural objects and actions
    . exporting foreign function library names for user LEGATTI
    . exporting PUBLIC type synonyms
    . exporting private type synonyms
    . exporting object type definitions for user LEGATTI
    About to export LEGATTI's objects ...
    . exporting database links
    . exporting sequence numbers
    . exporting cluster definitions
    . about to export LEGATTI's tables via Conventional Path ...
    . . exporting table                     TEST
    . exporting synonyms
    . exporting views
    . exporting stored procedures
    . exporting operators
    . exporting referential integrity constraints
    . exporting triggers
    . exporting indextypes
    . exporting bitmap, functional and extensible indexes
    . exporting posttables actions
    . exporting materialized views
    . exporting snapshot logs
    . exporting job queues
    . exporting refresh groups and children
    . exporting dimensions
    . exporting post-schema procedural objects and actions
    . exporting statistics
    Export terminated successfully without warnings.Cheers

  • Using package functions in an update

    Okay, I have a package function that returns a correct value when used in a SELECT, but when used in an UPDATE, it returns Null. Why can't I used its result in the UPDATE?
    Package Spec
    FUNCTION fpub_get_contract_attribute
         (     n_contract_id_in                    IN               CONTRACT.CONTRACT_ID%TYPE,
              s_attribute_in                         IN               VARCHAR2 )
    RETURN VARCHAR2;
    PRAGMA RESTRICT_REFERENCES(fpub_get_contract_attribute,TRUST,WNDS);
    Source :
    clear;
    rollback;
    select
         contract_functions.fpub_get_contract_attribute(CONTRACT_ID,'ORIGINAL_SALES_CHANNEL') "Before",
         original_sales_channel
    from contract
    where contract_id = 52549615;
    update contract
    set original_sales_channel = NVL(contract_functions.fpub_get_contract_attribute(CONTRACT_ID,'ORIGINAL_SALES_CHANNEL'),'Null')
    where contract_id = 52549615;
    select
         NVL(contract_functions.fpub_get_contract_attribute(52549615,'ORIGINAL_SALES_CHANNEL'),'Null') "After",
         original_sales_channel
    from contract
    where contract_id = 52549615;
    rollback;
    Result :
    Rollback complete
    Before                ORIGINAL_SALES_CHANNEL
    RE                                                                              
    1 row updated
    After                 ORIGINAL_SALES_CHANNEL
    Null                  Null
    Rollback completeAny ideas?
    Thanks,
    Jason

    Pragma restrict_references has not been required since 8i, so you can get rid of that. However, certain things will still be enforced, with or without the pragma. For example, you cannot perform DML from within a packaged function when that function is used in a select statement, although you can perform DML within a packaged function when it is used in an update statement. So, if you are performing some sort of DML in your function, it would not raise an error when used in the update statement, but would cause it to return whatever is specified in the exception block when used in a select statement, causing the different results.
    Please see the demonstration below in which I have created a sample function that contains an insert statement. When I use the function from a select statement, it raises an error and does not insert a row. However, when I use the function in an update statement, it does not raise an error and inserts a row. I have then added an exception clause to the function and re-tested. When I used the function in a select statement, it now returns the value in the exception block, but still does not insert a row. When I used the function in an update statement, it returns a different value, not from the exception block, and inserts a row. Then I removed the insert statement from the function and re-tested. Now it returns the same value, whether used in a select statement or an update statement.
    scott@ORA92> SELECT banner FROM v$version
      2  /
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE     9.2.0.1.0     Production
    TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 - Production
    scott@ORA92> CREATE TABLE test
      2    (col1 VARCHAR2(30))
      3  /
    Table created.
    scott@ORA92> CREATE TABLE contract
      2    (contract_id            NUMBER,
      3       original_sales_channel VARCHAR2(30))
      4  /
    Table created.
    scott@ORA92> INSERT INTO contract (contract_id) VALUES (52549615)
      2  /
    1 row created.
    scott@ORA92> COMMIT
      2  /
    Commit complete.
    scott@ORA92> CREATE OR REPLACE PACKAGE contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2;
      7  END contract_functions;
      8  /
    Package created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- test with insert statement and no exception handling:
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2
      7    IS
      8    BEGIN
      9        INSERT INTO test (col1) VALUES ('inserting');
    10        RETURN 'Null';
    11    END fpub_get_contract_attribute;
    12  END contract_functions;
    13  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> SELECT * FROM contract
      2  /
    CONTRACT_ID ORIGINAL_SALES_CHANNEL
       52549615
    scott@ORA92> COLUMN "Before" FORMAT A30
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
    ERROR at line 1:
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SCOTT.CONTRACT_FUNCTIONS", line 9
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> update contract
      2  set    original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
      3  where  contract_id = 52549615
      4  /
    1 row updated.
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> COLUMN "After" FORMAT A30
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
    ERROR at line 1:
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SCOTT.CONTRACT_FUNCTIONS", line 9
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> --
    scott@ORA92> -- repeat test with insert statement and exception handling:
    scott@ORA92> ROLLBACK
      2  /
    Rollback complete.
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2
      7    IS
      8    BEGIN
      9        INSERT INTO test (col1) VALUES ('inserting');
    10        RETURN 'Null';
    11    EXCEPTION
    12        WHEN OTHERS THEN RETURN 'RE';
    13    END fpub_get_contract_attribute;
    14  END contract_functions;
    15  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    Before                         ORIGINAL_SALES_CHANNEL
    RE
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> update contract
      2  set    original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
      3  where  contract_id = 52549615
      4  /
    1 row updated.
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    After                          ORIGINAL_SALES_CHANNEL
    RE                             Null
    scott@ORA92> SELECT * FROM test
      2  /
    COL1
    inserting
    scott@ORA92> --
    scott@ORA92> -- repeat test with no insert statement and no exception handling:
    scott@ORA92> ROLLBACK
      2  /
    Rollback complete.
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY contract_functions
      2  AS
      3    FUNCTION fpub_get_contract_attribute
      4        (n_contract_id_in IN CONTRACT.CONTRACT_ID%TYPE,
      5         s_attribute_in   IN VARCHAR2 )
      6        RETURN            VARCHAR2
      7    IS
      8    BEGIN
      9        RETURN 'Null';
    10    END fpub_get_contract_attribute;
    11  END contract_functions;
    12  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "Before",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    Before                         ORIGINAL_SALES_CHANNEL
    Null
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> update contract
      2  set    original_sales_channel = NVL (contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL'), 'Null')
      3  where  contract_id = 52549615
      4  /
    1 row updated.
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92> select contract_functions.fpub_get_contract_attribute (CONTRACT_ID, 'ORIGINAL_SALES_CHANNEL') "After",
      2           original_sales_channel
      3  from   contract
      4  where  contract_id = 52549615
      5  /
    After                          ORIGINAL_SALES_CHANNEL
    Null                           Null
    scott@ORA92> SELECT * FROM test
      2  /
    no rows selected
    scott@ORA92>

  • Packaged function not compiling

    This one is driving me mad as I cannot see any possible
    reason for it.
    I have two packages containing functions. They are both owned by one schema, different to the schema I am using to build my form. They are both granted execute to public and have public synonyms which are the same as the package name.
    The schema I am using to build my form can access the functions in sqlplus by specifying package.function.
    In my form I have:
    variable1 := package1.function1;
    variable2 := package2.function2;
    The first line compiles OK. The second comes up with function2 must be declared. If I prefix it with owner. it is OK.
    I cannot find any difference between the packages to explain this behaviour. Any ideas anyone please.

    Steve
    I had discussed it with someone else. He claimed afterwards that he had thought of that solution but it was so obvious he didn't like to insult me by suggesting it. I don't know if I believe him.
    Pavel
    Nice idea but we have too much code to retrospectively tidy up. Also with changes of personnel over the years we have such a mixture of different naming conventions that they are pretty meaningless. However, I do prefix my pll procedures with lib to give a clue where to look for them.

Maybe you are looking for

  • White screen of death - iMac OSX Lion

    I upgraded my 2007 iMac to Lion and after a few days of perfect running the think locked up.  When I forced the power off and back on it seemed to be booting fine (chimes, apple logo, disk spinning up and I could hear the drive head seeking) but then

  • Media Center hard drive upgrade.

    Is there any way to get more capicity as currently low for HD recordings? If not are there any other options?

  • Using Workspace Manager on Object tables

    Is it possible to implement WM on object tables? I have tried to enable but with no success. See test below where I try to version enable an object table 'SAS_INSTANCE' in schema TEST. TEST ==========> Oracle9i Enterprise Edition Release 9.2.0.5.0 -

  • FTPEx : 550 Unexpected reply code

    Hi Experts I am trying to connect one of the vendor's site and get the files by using the file adapter, I am able to access the file folders when i try from the https site , but this is secured site and I configured as  ftpssl when I activate my CC i

  • Fade out left not working

    When I use the fade out left behavior on text, the text just disappears and does not fade out. The funny thing is it works on the first text assest that I apply it on. From then on everytime I try to use it, the text just disappears without fading ou