Building the varchar string to return from a pl sql function

i'm new with pl/sql and i'm having trouble trying to build the string that i want to return from a function that is inside a package. it seems my problem stems from the fact that i'm trying to incorporate a variable (varchar2) into the string to be returned. below are two attempts that i've made which do not work:
function test_policy (p_schema_name IN varchar2, p_object_name IN varchar2) return varchar2 as
predicate_value varchar2(2000);
user_name varchar2(100);
begin
select first_name
into user_name
from employees
where first_name = SYS_CONTEXT('hr_app_context', 'username');
predicate_value := 'first_name = ' || user_name;
predicate_value := 'first_name = ' || '' || user_name || '';
return predicate_value;
end test_policy;
Can someone help me with the proper syntax to build my string for the return value? Thanks.

this function implements the code for a policy i've created. basically, the policy says that when i do a select on the employees table, i should only see a record whose first_name = sys_context('hr_app_context', 'username'). so, when i perform a simple select * from employees, i get an error which says policy predicate has error. i'm pretty sure the error is caused by how i'm building the return value for that function. if i hard code some return value like:
predicate_value := 'first_name = ''HR''' ;
the select statement above works fine, and i only see the record from employees where first_name = 'HR'

Similar Messages

  • How to Customize the Message "No Row Returned" from a Report

    Hi,
    I've been trying to customize the Message "No Row Returned" from a Report.
    First i followed the instructions in Note:183131.1 -
    How to Customize the Message "No Row Returned" from a Report
    But of course the OWA_UTIL.REDIRECT_URL in this solution did not work (in a portlet) and i found the metalink document 228620.1 which described how to fix it.
    So i followed the "fix" in the document above and now my output is,..
    "Portlet 38,70711 responded with content-type text/plain when the client was requesting content-type text/html"
    So i search in Metalink for the above and come up with,...
    Bug 3548276 PORTLET X,Y RESPONDED WITH CONTENT-TYPE TEXT/PLAIN INSTEAD OF TEXT/HTML
    And i've read it and read it and read it and read it and can't make heads or tails of what it's saying.
    Every "solution" seems to cause another problem that i have to fix. And all i want to do is customize the Message "No Row Returned" from a Report. Please,...does anyone know how to do this?

    My guess is that it only shows the number of rows it has retrieved. I believe the defailt is for it to only retrieve 50 rows and as you page through your report it retrieves more. So this would just tell you how many rows was retireved, but probably not how many rows the report would contain if you pages to the end. Oracle doesn't really have a notion of total number of rows until the whole result set has been materialized.

  • How do you limit the number of rows return from query?

    How do you limit the number of rows return from query? Do all databases support this kind of feature?

    i think the standard is limit
    to get the top 30
    select * from mytable LIMIT 30;returns the first 30 rows
    also if you want a range
    select * from mytable LIMIT 10,30;returns 30 rows starting from 10
    this last one is useful for displaying ranges... something similar happens in these forums when viewing topics and messages

  • Pass a value from a PL/SQL function to a javascript (html header) ? ?

    Hey Guys,
    Have a question regarding how to pass a value from a PL/SQL function to a javascript in the HTML Header.
    I have created a PL/SQL function in my database, which does looping.
    The reason for this is:  On my apex page when the user selects a code, it should display(or highlight buttons) the different project id's present for that particular code.
    example= code 1
    has project id's = 5, 6, 7
    code 2
    has project id's = 7,8
    Thank you for your Help or Suggestions
    Jesh
    The PL/SQL function :
    CREATE OR REPLACE FUNCTION contact_details(ACT_CODE1 IN NUMBER) RETURN VARCHAR2 IS
    Project_codes varchar2(10);
    CURSOR contact_cur IS
    SELECT ACT_CODE,PROJECT_ID
    FROM ACTASQ.ASQ_CONTACT where ACT_CODE = ACT_CODE1;
    currec contact_cur%rowtype;
    NAME: contact_details
    PURPOSE:
    REVISIONS:
    Ver Date Author Description
    1.0 6/25/2009 1. Created this function.
    BEGIN
    FOR currec in contact_cur LOOP
         dbms_output.put_line(currec.PROJECT_ID || '|');
         Project_codes := currec.PROJECT_ID|| '|' ||Project_codes;
    END LOOP;
    RETURN Project_codes;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END contact_details;
    /

    Jesh:
    I have made the following modifications to your app to get it to work as I thing you need it to.
    1) Changed the source for the HTML Buttons Region(note use of id vs name for the Buttons)
    <script>
    function hilitebtn(val) {
    //gray buttons
    $x('graduate').style.backgroundColor='gray'
    $x('distance').style.backgroundColor='gray'
    $x('career').style.backgroundColor='gray'
    $x('photo').style.backgroundColor='gray'
    //AJAX call to get project-ids
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=GETPROJECTS',0);
    get.addParam('x01',val)
    gReturn = get.get();
    var arr=gReturn.split(':');  //dump into array
    get = null;
    for (i=0;i<arr.length;i++) {
    // alert('val=' + arr);
    if ( arr[i]==5)
    $x('graduate').style.backgroundColor='red';
    if ( arr[i]==6)
    $x('distance').style.backgroundColor='red';
    if ( arr[i]==7)
    $x('career').style.backgroundColor='red';
    if ( arr[i]==8)
    $x('photo').style.backgroundColor='red';
    </script>
    <table cellpadding='0' cellspacing='0' border='0'>
    <tr><td>
    <input type='button' id='graduate' value='Graduate'>
    </td>
    <td>
    <input type='button' id='distance' value='Distance'>
    </td>
    <td>
    <input type='button' id='career' value='Career/Tech'>
    </td>
    <td>
    <input type='button' id='photo' value='Photos'>
    </td>
    </tr></table>
    2) Defined the application process  GETPROJECTS as DECLARE
    IDS varchar2(1000);
    l_act_code varchar2(100) :=4;
    begin
    IDS:='';
    l_act_code := wwv_flow.g_x01;
    for x in(
    SELECT ACT_CODE,PROJECT_ID
    FROM ASQ_CONTACT
    where ACT_CODE = l_act_code)
    LOOP
    IDS := IDS || X.PROJECT_ID|| ':' ;
    END LOOP;
    HTP.PRN(IDS);
    END;
    3) Changed the 'onchange' event-handler on p1_act_code to be 'onchange=hilitebtn(this.value)'
    4) Added the JS to the HTML Page Footer <script>
    hilitebtn($v('P1_ACT_CODE'));
    </SCRIPT>

  • Catch a value from a pl*sql function in a shell script

    Hi all,
    I have a shell script that simply calls the following pl*sql function.
    echo "execute scott.my_pkg.test('FDLmaster');\n exit;" >./pippo.sql
    sqlplus scott/tiger @/fidcap_ftp/FDL/SCRIPTS/pippo.sql
    What I have to do to catch the value returned from the function test?
    Thanks in advance
    best regards
    Mario

    SQL> create or replace function do_something return varchar2 is
      2  begin
      3      return ('Something');
      4* end;
    SQL> /
    Function created.
    SQL> select do_something from dual;
    DO_SOMETHING
    Something
    SQL> save pippo
    Created file pippo.sql
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
    With the Partitioning, OLAP and Data Mining options
    [linuxas tmp test10]$ echo exit >>pippo.sql
    [linuxas tmp test10]$ VAR=`sqlplus -s scott/tiger @pippo`
    [linuxas tmp test10]$ echo $VAR | cut -f3 -d" "
    Something
    [linuxas tmp test10]$

  • Show refcursor returned by a PL/SQL function ?

    Is it possible to show the results returned by a
    PL/SQL function that returns a refcursor ?
    In sqlplus it goes like this:
    SQL> variable a refcursor;
    SQL> execute :a := p_front.get_invoice_list;
    PL/SQL procedure successfully completed.
    SQL> print a;
    INVOICE_ID CLIENT_ID INVOICE_D
    101 100 01-APR-06
    100 100 06-APR-06
    If not, this would be on the top of my wishlist...
    By the way: you did a good job on this tool!
    Regards,
    Willem

    Is it possible to show the results returned by a
    PL/SQL function that returns a refcursor ?
    In sqlplus it goes like this:
    SQL> variable a refcursor;
    SQL> execute :a := p_front.get_invoice_list;
    PL/SQL procedure successfully completed.
    SQL> print a;
    INVOICE_ID CLIENT_ID INVOICE_D
    101 100 01-APR-06
    100 100 06-APR-06
    If not, this would be on the top of my wishlist...
    By the way: you did a good job on this tool!
    Regards,
    Willem

  • How-To Display the Number of Records Returned from a List to the User?

    We currently are using lists to identify accounts that meet various criteria. Because the territories vary from 4k to 60k customers the users have stated that they don't know the size of the list and therefore don't know if they need to refine the list. Currently they are exporting to Excel to look at the row count to see if they need to further refine their searches. This takes quite a while and while shuffling through many lists is a bit painful. Isn't there a way to just show the total records returned from the list down at the bottom of the screen where it allows you to see 25/50/75/100 records at a time?
    There is probably a simple way to do this but it is a large user dissatisfier at the time because we simply don't know how to make this show up. Again we are using lists and not analytics for simple lists at this time.
    - john
    Edited by: user11286597 on Jun 19, 2009 11:02 AM

    Thanks Bobb. I can't believe that one wasn't in R1 :)
    Is there a link to the items being worked in the next release by any chance?
    - john

  • Can the return from xsql:ref-cursor-function be saved & looped through XSQL?

    If <xsql:ref-cursor-function> returns one field for a number of rows, is there a way to save those values and loop through the data retrieved for other query process within XSQL? Any example?
    Thanks.
    null

    You have a couple of options.
    You can process the XML returned by <Xsql:ref-cursor-function> as the normal part of XSLT processing, or you can write a custom action handler that aggregates the action handler for <xsql:ref-cursor-function> and then uses DOM to operate on the return value.
    Search the Online XSQL Pages Documentation for the term "MyIncludeXSQLHandler" for some sample code that illustrates building a customer action handler that aggregates one of the built-in handlers.

  • Getting the number of rows returned from ResultSet

    Hi,
    Does anyone know a method to get the number of rows returned with a query using the Resultset class?
    Thanks.

    Hi 281080,
    If your database and JDBC driver support it, in order to use the solution that da-alexj has suggested, you need to create a 'scrollable' "ResultSet" -- the javadoc for method "createStatement()" (in class "java.sql.Connection") has more details.
    However, I have found with Oracle 8.1.7.4 database and Oracle (thin) JDBC driver, that part of their implementation of the "last()" method (in class "java.sql.ResultSet") is to actually iterate through the entire "ResultSet" in order to reach the last row. If your "ResultSet" is very large (I tested it with a 100,000 row "ResultSet"), this will take a long time.
    Just wanted to make you aware of that.
    Of-course, this may be irrelevant to you since I didn't see any mention in your post of what database and JDBC driver you are using.
    Hope this has helped you, anyway.
    Good Luck,
    Avi.

  • Unable to retreive the return value of pl/sql function using DB Adapter

    Dear Experts,
    I am using DB Adapter in my BPEL Process. Using DB Adapter I am invoking a PL / SQL function. I am able to send two input parameters for the pl/sql function. But I dont know how to retrieve the return value from the function. Please suggest me.
    Thanks,
    Rajesh

    Yes I am returning a value from PL/SQL function.
    Please see the code segments below,
    FUNCTION "TD_INSERT" (a TDINIT_TYPE, stops TDDETAIL_TABLE )
    RETURN VARCHAR2
    AS
    td_no Number;
    td_id Number;
    stop TDDETAILFULL_TYPE;
    length number;
    BEGIN
    insert into TD_INIT values( ----passing all the values here --------- );
    select max(tdno) into td_no from TD_INIT ;
    length := stops.count;
    for i in 1.. length loop
    stop := stops(i);
    insert into TD_DETAIL_FULL values(
    td_no, ------- );
    end loop;
    commit;
    RETURN td_no;
    END;
    Thanks,
    Rajesh

  • APEX_MAIL.SEND from a pl/sql function

    I have created a pl/sql function, in the database, in which I would like to use APEX_MAIL.SEND to send out emails.
    When I try to compile I get the following errors:
    Compilation failed,line 10 (08:44:32)
    PLS-00307: too many declarations of 'SEND' match this callCompilation failed,line 10 (08:44:32)
    PL/SQL: Statement ignored
    Here is the relavent code. Line 10 is the line where I have APEX_MAIL.SEND
    LOOP
    APEX_MAIL.SEND (
    P_TO => email_rec.TO_EMAIL,
    P_FROM => email_rec.FROM_EMAIL,
    P_BODY => email_rec.BODY,
    P_BODY_HTML => email_rec.BODY,
    P_SUBJ => email_rec.SUBJECT );
    I am in APEX version 3.0.0.00.20
    I can send mail from a APEX application procedure. The function I am having trouble with is one that can be accessed under the SQL Workshop --> Object Browser --> Functions.
    Other functions work fine.
    Thanks.

    Have a look at the following thread Re: HTMLDB_MAIL.SEND Cursor for loop
    It might be a problem of your data types you have defined in email_rec. Eg. do you have a CLOB for SUBJECT?
    Patrick
    My APEX Blog: http://inside-apex.blogspot.com
    The ApexLib Framework: http://apexlib.sourceforge.net
    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/

  • Setting Oracle Permissions for file access from a pl/sql function

    I have a pl/sql function that calls a java method which moves a
    file from a directory to another.
    Since we are using Linux, Oracle wants some permissions.
    Those permissions are set using:
    call dbms_java.grant_permission(USER, 'java.io.FilePermission',
    FILE, permission)
    OK, i want to use this in my pl/sql function, but it doesn't
    work.
    My function looks like something like this:
    -- some pl/sql code
    dbms_java.grant_permission(someUSER, 'java.io.FilePermission',
    sourceFILE, 'write');
    dbms_java.grant_permission(someUSER, 'java.io.FilePermission',
    destFILE, 'write');
    flag := move(sourceFILE, destFILE);
    -- flag is for 1 -> done and 0 -> error
    -- some more code ...
    The problem is the lines of
    dbms_java.grant_permission(someUSER, 'java.io.FilePermission',
    sourceFILE, 'write');
    do not work!
    When i grant permissions manually in sql plus it works great,
    but when i do it from the function it does not work!
    Any ideas anyone?
    Any help would be appreciated.

    The command :
    dbms_java.grant_permission
    (someUSER, 'java.io.FilePermission',sourceFILE, 'write');
    is right.
    Open sqlplus
    Connect as sys or system
    type :
    execute dbms_java.grant_permission
    (someUSER, 'java.io.FilePermission',sourceFILE, 'write');
    commit;
    try to compile again your procedure...does it work now ?
    bye
    Giovanni Regola

  • Unicode string now returned from Stored Proc., used to be ANSI.

    Using ADO to connect VB6 to Oracle 8 stored procedures used to return strings in ANSI format. At some point in the last year or so, strings suddenly began to be returned as Unicode, unreadable by VB.
    Same problem now occurs using VB.Net and ODP.Net; I need to support both VB6 and .NET versions.
    Why are strings being encoded differently than before? Has anybody else seen this problem? What can be done?
    The NLS_LANG registry entries on the server and client machines match each other. Some of our installed base of customers reported this change, too.
    Below are some demonstration code examples.
    Stored procedure looks like this:
    CREATE OR REPLACE PROCEDURE MyStoredProc
    (sMyMsg IN OUT VARCHAR2) AS
    BEGIN
         sMyMsg := 'My test string';
    RETURN;
    END;
    On the VB6 side, my code looks like this:
    Dim vParam As Variant
    Dim cmdExecute As ADODB.Command
    Dim pParam As ADODB.Parameter
    Set cmdExecute = New ADODB.Command
    cmdExecute.CommandType = adCmdStoredProc
    cmdExecute.CommandText = "MyStoredProc"
    Set pParam = cmdExecute.CreateParameter("PARAM1", vbString, adParamInputOutput, 0, vParam)
    cmdExecute.Parameters.Append pParam
    cmdExecute.ActiveConnection = ADOConnect
    cmdExecute.Execute
    vParams = cmdExecute.Parameters(0)
    Result of VB code is that vParams now contains a Unicode string.
    Any suggestions as to what's happening, where the problem might be, what to do about it, or where else to post this question (I'm not sure which Forum is the best place to look for answers) would be appreciated.
    Is "force SQL_WCHAR" relevant to this problem? If so, what does that mean and how/where do I apply it?

    The Force WCHAR option forces the ODBC driver to
    report columns and return data as Unicode. If that
    is checked, you probably want to uncheck it.But how do I do that? I can't find any documentation for a SQL_WCHAR option. Where do I go to read/change the current setting of this switch?
    What character set is your client & database?NLS_LANG, for both machines, is "AMERICAN_AMERICA.WE8ISO8859P1". BTW, the client is 9.2, but the database is version 8.1.7. I'm fairly certain that the problem also existed when the client was also running ver. 8.

  • Not all the connect strings are shown from tnsnames.ora

    Hi Guys,
    I am having a very strange problem. While trying to create a new connection in SQL Developer (I am using Version 1.1.2.25), and choosing " TNS " as connection type, I am just able to see 15-20 database entries, where my tnsnsames.ora contains more than 100 entries. And these 15-20 connect strings seem to have been picked randomly. So its like I am seeing the 1st entry, 4-8th entry, 20-24th entry from the tnsnames.ora.
    Any idea what needs to be done?
    Thanksm

    Hi there,
    I found what was wrong and would like to update it for the benefit of others. The tnsnames.ora was read upto all the entries which was in correct format. All the entries after the first incorrect entry was being ignored.
    E.g. if you tnsnames.ora is having 100 entries and entry number 50 is in wrong format, then SQLDEVELOPER will only show entries upto 49. Entry 50th onwards will not be shown.
    Hope this helps.
    Ashish

  • Getting the no. of rows returned from the resultset

    Could somebody tell how can I get the count of rows from the resultset object.
    Thanks a lot in advance

    hmmm 20,710 topics and 69,000 odd posts and no one has EVER asked this question before.. it's a miracle....
    or maybe it has been asked and dealt with approx... 11,000 times.
    here is a discussion from 1998 for example http://forum.java.sun.com/thread.jsp?forum=48&thread=83958

Maybe you are looking for