Demonstrating PL/SQL Functions Using SQL Developer

Good afternoon,
I'm starting to write some PL/SQL functions to replace some of the SQL that I use most frequently.  A couple of very simple examples would be:
create or replace function func_test (p_1 number) return number
is
x number;
y number;
begin
x :=1;
y :=2;
return p_1 * x * y;
end func_test;
create or replace function func_test2 (p_1 varchar2) return varchar2
is
return_val varchar2(10);
begin
select p_1 into return_val from dual;
return return_val;
end func_test2;
However, at my workplace I haven't been granted create function privileges yet until I can demonstrate some examples, which is understandable.
For the time being, without these privileges, is there a way I can build/test functions in principle locally using SQL Developer without the need to write the functions to our database? I.e. can I demonstrate the above in SQL Developer, but without wrapping in create or replace syntax?
I hope this isn't too vague.
Using Oracle 11gR2 (not logged in to workplace database at the moment for specific version no.)
SQL Developer 3.4
Thanks,
TP

sb92075 02-Nov-2013 19:12 (in response to TinyPenguin)
populating test DB with data is a solvable problem.
You don't need client data to test code (functions).
You only need sample test data; which generally is less than a few dozen records per table.
Absolutely, of course. Our client database is pretty messy though, and includes data prior to the implementation of more recent business rules that I need to take account of. Useful perspective though, thanks.
rp0428 02-Nov-2013 19:14 (in response to TinyPenguin)
Sure, but then I wouldn't have access to all the data in our client database to test functions under various circumstances.
Huh? Why not? It's your database so what keeps you from creating a database link to your client database where all the data is?
Also, I suppose it's not good practice to constantly write/replace/drop functions to/from a database when developing them? Better to test the function in principle and then write to the database?
Huh? Why not? What you think a dev database is for if not for development?
Based on your two posts so far in this thread it's understandable why they don't want to give you privileges yet. Those sample 'functions' you posted are NOT a good use for functions.
In sql developer you can just create and save the queries you use most often. There is no need to create functions for that.
But if you do need an anonymous function now and then just create one using sql*plus syntax:
Our IT department are pretty sensitive about how they allow access, even to the dev environment. As you've identified, I'm not naturally a programmer so the option to play around with the data to develop some representative examples about how we can simplify and devolve SQL reporting to more members of staff is useful to me. I just wrote those two function quickly for the purpose of posting some sample data, which I thought would be helpful. Thanks for illustrating how to return their output using an anonymous block.
FrankKulash 02-Nov-2013 19:13 (in response to TinyPenguin)
Hi,
The obvious solution is to get the privileges.  If your employer really wants you to do something, they need to give you the necessary privileges to do it.  It's silly for them to tell you to do something, but refuse to let you do it.
Failing that, you can install Oracle on your own machine, as suggested above.  It's free and legitimate if you're only using it for learning and developing.  Oracle Express Edition is very easy to install.
As a last resort, you can write functions and procedures that are local to an anonymous block, like this:
Thanks Frank. Yeah I'm going to speak with our DBA next week about privileges. I've got XE/SQL Developer installed on my own computer - I wrote those sample functions using them - I just wasn't sure how to call/return anonymous blocks as both you and rp identified to develop at work as an interim solution.
Thanks a lot All,
TP.

Similar Messages

  • SQL report region source to call a pl/sql function using DB link

    Hi - I have a pl/sql function fn_dbtype(id NUMBER) defined in database X. The pl/sql function executes couple DML statements and returns a string (a SELECT query). I am able to call this function using SQL Plus (Connected to Database X) as below and it works fine:
    declare
    vSQL VARCHAR2(100);
    begin
    vSQL := fn_dbtype(1);
    end;
    The DML operations completed fine and vSQL contains the "Select" query now.
    In APEX:
    I am trying to create a SQL report in APEX using SQL query(PL/SQL function returning a sql statement) option. I am trying to figure out what to put in the region source so that the output of the "Select" query is displayed in the report.
    Moreover APEX is hosted in a different database instance. So I would need to call this pl/sql function using a DB Link.
    Please let me know what I need to put in the region source to execute the pl/sql function which returns the "Select" query thereby displaying the query output in the report. Thanks.
    Edited by: user709584 on Mar 19, 2009 2:32 PM
    Edited by: user709584 on Mar 19, 2009 2:34 PM

    try something like this:
    return fn_dbtype(1)@dblink;

  • Issue with running PL/SQL function returning Sql query

    hi, I am trying to create a report region by using the option of PL/SQL function returning sql query.
    I notice that it's very slow for the report region page to show up. In my PL/SQL function body, there are only 3 steps, first update all the 10 rows of varchar2 fields to null,then insert values to those fields, then select all from the table to show report results. It takes more than 5 minitues for the page to load up, how ever, if i run those steps in SQL*Plus, it only takes a couple of seconds to finish. Any suggestions?
    Thanks,
    gina

    Sergio, the codes are as followed,
    Declare
    q varchar2(32767); -- query
    Begin
    q := 'select "ID",'||
    '"ENTRY NAME","TOTAL","#CM","%CM","#CA",'||
    '"%CA", from Info_table';
    update info_table
    set "TOTAL" = '',
    "#CM" = '',
    "%CM" = '',
    "#CA" ='',
    "%CA"=''
    where "ID"<=10;
    // set all data in column Total to null,there is only 10 rows in the table
    update info_Table set Total = vTotal,
    "#CM" = vCM
    (those variables hold user key-in Text filed value)
    where ID = 1;
    return q;
    End;

  • On Submit process not firing -report (PL/SQL function returning SQL query)

    Can anyone suggest possible causes / solutions for the following problem?
    I have a report region that uses a PL/SQL function returning SQL query. The report allows the user to update multiple fields / rows and then click a button to submit the page which should run the On-Submit process to update the database. However the process does not run and I get a 'HTTP404 page cannot be found' error; and when I navigate back using the Back button I cannot then navigate to any other page in my application without getting the same error. The button was created by a wizard selecting the options to submit the page and redirect to a (same) page. The button does not actually have a redirect in its definition but the wizard created a branch to the same page which should work and the button has the text 'submit as SUBMIT' next to it so it appears to be set up correctly.
    I have recreated this page several times in my application and I cannot get the On-Submit process to run. However I have created a cut down version of the same page in the sample application on apex.oracle.com at http://apex.oracle.com/pls/otn/f?p=4550:1:179951678764332 and this works perfectly so I am at a loss to understand why it does not work in my application. I cannot post any part of the application itself but if anybody would like to check out page 30 of the sample application (Customer Update Test tab) updating the surnames only, using credentials ja, demo, demo this is pretty much what I have got in my application.
    Any ideas would be much appreciated?

    Thanks for the suggestions guys. I have now identified that the problem goes away when I remove the second table from my report query. The original report query retrieved data from two tables and the process was updating only one of the tables. I thought I had approached the task logically i.e. first get the report to display the records from the two tables, then get the process to update the first table and finally to modify the process further to update the second table.
    Can anyone point me to an example of multiple row updates on multiple tables using a PL/SQL function returning an SQL query?

  • SQL Query(PL/SQL Function Returning SQL Query)

    I am trying to write a dynamic report using SQL Query(PL/SQL Function Returning SQL Query).
    I can get the report to run but I need to concatinate some columns into one, seperated by a comma or a dash.
    I have tried select *****||','||***** alias
    also select *****||'-'||***** alias
    but I always get an error.
    Is there a way of doing this please
    Gus

    This is my full query
    declare
    v_query varchar2(4000);
    begin
    if :P63_TRAN_INFO = 2 THEN
    v_query := 'select
         A.FILENR,
         A.EXERCISENAME,
    A.STARTDATE,
    A.ENDDATE,
         A.UNIT,
    A.ACCADDRESSES, B.ADDRESS, B.ADDRESS_1, B.POST_CODE, B.TOWN,
         A.EXERCISEAREAS,
         A.TOTALVEHICLES,
    A.TOTALTROOPS+A.RNTOTALTROOPS+A.RAFTOTALTROOPS TOTALTROOPS,
    A.CAR, A.MINIBUS, A.HGV,
    A.NAMERANK, A.ADDRESS, A.ADDRESSI, A.ADDRESSII, A.POSTCODE,
    A.TRANSIT,
    A.INFOONLY
    from     BFLOG_AT A, BFLOG_ACCADDRESS B
    WHERE A.ACCADDRESSES = B.NAME
    AND A.STARTDATE >= :P63_START_DATE
    AND A.ENDDATE <= :P63_END_DATE
    AND A.AUTHORISED = 1
    AND A.INFOONLY = 1' ;
    END IF;
    RETURN v_query;
    END;
    This query runs ok, but if I try changing it to the code below with fields concatinated, then it fails
    declare
    v_query varchar2(4000);
    begin
    if :P63_TRAN_INFO = 2 THEN
    v_query := 'select
         A.FILENR,
         A.EXERCISENAME,
    A.STARTDATE,
    A.ENDDATE,
         A.UNIT,
    A.ACCADDRESSES||','||B.ADDRESS||','||B.ADDRESS_1||','||B.POST_CODE||','||B.TOWN ADDRESS,
         A.EXERCISEAREAS,
         A.TOTALVEHICLES,
    A.TOTALTROOPS+A.RNTOTALTROOPS+A.RAFTOTALTROOPS TOTALTROOPS,
    A.CAR, A.MINIBUS, A.HGV,
    A.NAMERANK, A.ADDRESS, A.ADDRESSI, A.ADDRESSII, A.POSTCODE,
    A.TRANSIT,
    A.INFOONLY
    from     BFLOG_AT A, BFLOG_ACCADDRESS B
    WHERE A.ACCADDRESSES = B.NAME
    AND A.STARTDATE >= :P63_START_DATE
    AND A.ENDDATE <= :P63_END_DATE
    --AND (A.EXERCISEAREAS LIKE "GAP, OA, OAL")
    --OR (A.EXERCISEAREAS LIKE "Harz")
    AND A.AUTHORISED = 1
    AND A.INFOONLY = 1' ;
    END IF;
    RETURN v_query;
    END;
    Cheers
    Gus

  • How to return less than 4000 characters from pl/sql function in SQL call?

    Hello,
    Is there a way to limit length for varchar when calling pl/sql function from SQL? No matter how I write it it always returns 4000 bytes.
    If there is none, then does it make sense ever to specify lenght of the return variable?
    My goal is to encapsulate business rules within pl/sql functions. But if all varchar columns are returned as 4000 it is not feasible solution. Not only this is a performance issue in a data warehousing environment, bet when using those rules within SQL views user experiance would suffer as well. Are we left with the rule hardcoding solution? Also, I think that using SUBSTRING or TRUNC functions on top of business rules function defeats the purpose.
    Please see my attempt below. Your thoughts are appreciated.
    Thank you.
    /* Formatted on 06/11/2009 2:26:41 PM (QP5 v5.126.903.23003) */
    CREATE OR REPLACE FUNCTION mytest (myvar_in VARCHAR2)
    RETURN VARCHAR2
    AS
    l_return VARCHAR2 (15);
    BEGIN
    l_return := 'TEST_' || myvar_in;
    RETURN l_return;
    END mytest;
    CREATE TABLE TEST_ME
    AS
    SELECT mytest ('ME') AS VERYLONG FROM DUAL;
    describe TEST_ME;
    RUN ABOVE CODE:
    Function created.
    Table created.
    TABLE TEST_ME
    Name Null? Type
    VERYLONG VARCHAR2(4000)
    Edited by: Ilmars2 on Jun 11, 2009 2:46 PM

    Pointless,
    Thanks for jumping in on this and I am glad you asked :).
    I do not doubt that it is an architectural challenge. Otherwise it would have been done already! I am struggling with the fact that SQL knows what data type the function will return, but does not know the length of it, precision or scale. I will leave it at that.
    I will go with some high level requirements to allow for alternative thoughts:
    1)     Business defined rules. There are multiple types of business rules. Simple lookups, bucketing, complex calculations, data retrieved from other tables etc. We have about 500 different rules. Some of them are even overloaded – different inputs will produce the same output.
    Some simple examples are:
    Rule1 - Fruit
         when ‘A’ then ‘Apple’
         When ‘O’ then ‘Orange’
         Else ‘N/A’ end
    Rule2 – Bonus
         when STATUS =’Active’ and LEVEL=’CEO’ then bonus=salary*1.0
         when STATUS =’Active’ and LEVEL=’nobody’ then bonus=salary*0.01
         else bonus=0
    Rule 3 – Income Bracket
         When more than 0 and less or equal to 30000 then INC_B=’LOW’
         When more than 30000 and less of equal to 60000 then INC_B=’MIDDLE’
    Etc.
    2)     Challenge: All data users in an organization need to use the same rules (let’s assume data source is Oracle database). How to expose all the rules to different types of users in manageable way? Types of users – analysts, application/web developers, data warehouse teams etc.
    3)     Current system: Not only each user has coded their own rules (luckily based on the common specification), but hard-coding is taking place for each query within the confines of one project. The project I just looked at had about 12 modules with 30 hardcoded queries. Oops! Few rules just changed.
    My take: I was leaning toward encapsulating business logic within UDF’s. UDF’s provide all the flexibility we need + overloading. All the functions could be consumed by data warehouse team (building summary tables, cubes etc.) and application developers. For power users we could build views by applying the same functions on top of the source data. Thus avoid data duplication. It seemed win-win until this 4000 issue :).
    Your thoughts on alternative approaches are appreciated.
    Thank you.

  • Report- Pl/sql function returning sql query parsing page items as text?

    Hi Team,
    I am facing a strange issue .
    I have four page items namely
    1)JOB_CODE
    2)MIN_EXP
    3) MAX_EXP
    4) SOURCES1
    I have a report of the type "Pl/sql function returning sql query"
    declare
    v_sql varchar2(4000);
    begin
    if (:JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql:= 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:JOB_CODE IS NULL and :MIN_EXP IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MIN_EXP IS NULL and :JOB_CODE IS NOT NULL and :MAX_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where v_experience_years <= :MAX_EXP and V_REQUIREMENT = :JOB_CODE and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    elsif (:MAX_EXP is null and :JOB_CODE IS NOT NULL and :MIN_EXP IS NOT NULL and :SOURCES1 IS NOT NULL) then
    v_sql := 'select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and source like ' || '''' || '%'|| ':SOURCES1' || '%' || '''';
    end if;
    insert into query_list values (v_sql);
    insert into debug values (:JOB_CODE , :MIN_EXP , :MAX_EXP , :SOURCES1);
    return v_sql;
    end;
    Please not that I am insertin the query into a table called Query_list and the page item values into the table called Debug thru the pl/sql function which returns teh query.
    Now I select the data from the debug tables.
    select unique(query) from query_list;
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = :JOB_CODE and v_experience_years >= :MIN_EXP and v_experience_years <= :MAX_EXP and source like '%:SOURCES1%'
    select * from debug;
    JOBCODE     MINEX     MAXEX     SOURCE
    21     1     10     donkeyHire
    And if I run the query in sql I get some records returned
    select v_candidate_id, v_fname,v_current_employer,v_Experience_years from candidature where V_REQUIREMENT = 21 and v_experience_years >= 1 and v_experience_years <= and source like 'donkeyHire'
    V_CANDIDATE_ID     V_FNAME     V_CURRENT_EMPLOYER     V_EXPERIENCE_YEARS
    2     Vengu     Andale Tech     4
    But the record does not show up in the report!
    does this type of report parse page items as text?
    Why is it so?
    Waiting for an early reply.
    Thanks,
    venkat

    Venkat - You don't want to put ':SOURCES1' in quotes like that.
    Scott

  • Tuning sql automatic using SQL Tuning Advisor Tool

    I need to work on Automatic sql tuning..
    Please give suggestion for the below
    1) I have installed oracle11g client version. confirm this is okey for my project. because i heard we should have oracle enterprise edition for this.
    2) User with only sys privelage can work on this automatic sql tuning using sql tuning advisior tool.
    Please clarify above suggestions.
    ALso suggest me best way to proceed further
    S

    Sunny kichloo wrote:
    This docs will help
    http://www.oracle-base.com/articles/10g/automatic-sql-tuning-10g.php
    http://www.oracle-base.com/articles/11g/automatic-sql-tuning-11gr1.php
    Thanks for your link. i already seen this link.
    Could u pls answer my question on above with " Yes" or "No"
    Kindly reply
    S

  • 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

  • Using a PL/SQL function in SQL

    Hello
    I wrote a function in pl/sql that create a table and return the name of the table as varchar2.
    The function is AUTONOMOUS TRANSACTION.
    I want to write a SQL that in the �FROM� section will call the function.
    The SQL will take the name of the table (from the function) and recognize it as a table.
    That way I can preform a join between the new table and other tables.
    Do you know on a way to preform that?
    I wrote the following SQL:
    (assume the name of the function is � �New_table()� return varchar2 )
    Select *
    From (select �New_Table()� from dual) ;
    This return the name of the table. But I want a SQL that will bring the data from the table
    Apreciate your help
    Hilit

    You say "I wrote a function in pl/sql that create a table and return the name of the table as varchar2.", now you want to select data from the newly created table in the same sql statement?
    Although you could cobble something together in PL/SQL using EXECUTE IMMEDIATE, or in a sql script using several statements that would work, where will the data come from?
    I'm guessing that you are populating the table in the function and are hoping to use it as something similar to a temp table in Sybase/SqlServer. If so, there are almost certainly several better ways to do this in Oracle.
    Why don't you tell us what you are trying to accomplish by building a table in the FROM clause of a sql statement, and maybe someone can give a better solution.
    TTFN
    John

  • Implementing Pivot Table like functionality using SQL

    Dear All,
    Please access a online document:
    http://docs.google.com/View?docid=dhntd3vh_0gmwgmq
    A 'query-output' is given.
    I have pasted this output in Excel and using it's Pivot table feature
    obtained an output given as 'Expected-Output' in the document.
    How can I achieve this using SQL?
    Any guidelines are most welcome.
    -Sameer

    See if this implementation could satisfy your needings.
         CREATE THE A TABLE WITH ESSENTIAL INFORMATION
    CREATE TABLE THINGS (
         WHO     VARCHAR2(32) NOT NULL,
         WHAT VARCHAR2(32) NOT NULL,
         NUM NUMBER
         FILLING THE ESSENTIAL INFORMATION
    INSERT INTO THINGS VALUES ('AFAS','TRANSACTION',4);
    INSERT INTO THINGS VALUES ('FAS-AP','TRANSACTION',2);
    INSERT INTO THINGS VALUES ('FAS-AR','TRANSACTION',2);               
    INSERT INTO THINGS VALUES ('FAS-GL','MASTER',3);
    INSERT INTO THINGS VALUES ('FAS-GL','REPORT',5);
    INSERT INTO THINGS VALUES ('INTERNATIONAL CARGO','MASTER',1);
    INSERT INTO THINGS VALUES ('INTERNATIONAL CARGO','REPORT',2);
    INSERT INTO THINGS VALUES ('INTERNATIONAL CARGO','TRANSACTION',9);
    INSERT INTO THINGS VALUES ('PACKAGE EXPRESS','INTELLIVIEW REPORT',1);
    INSERT INTO THINGS VALUES ('PACKAGE EXPRESS','MASTER',4);
    INSERT INTO THINGS VALUES ('PACKAGE EXPRESS','TRANSACTION',76);
    INSERT INTO THINGS VALUES ('PACKAGE EXPRESS','UTILITIES',1);
    INSERT INTO THINGS VALUES ('WAREHOUSE','REPORT',1);
    INSERT INTO THINGS VALUES ('WAREHOUSE','TRANSACTION',9);
         CREATE A TABLE FOR THE FULL CORRISPONDENCE
    CREATE TABLE THINGS2 AS
         SELECT A.WHO,B.WHAT, 0 NUM
         FROM (
              SELECT DISTINCT WHO
              FROM THINGS
         ) A, (
              SELECT DISTINCT WHAT
              FROM THINGS
         )B;
         SET THE RIGHT VALUES ON EACH ROW
    UPDATE THINGS2 A
    SET NUM = (
         SELECT NVL(SUM(NUM),0)
         FROM THINGS B
         WHERE ( A.WHO = B.WHO )
              AND ( A.WHAT = B.WHAT )
         SHOW THE FULL TABLE ( FULL BECAUSE IT CONTAINS THE FULL JOIN BETWEEN "WHO" AND "WHAT" )
    SELECT *
    FROM THINGS2
         RETRIVE THE EXPECTED OUTPUT
    SELECT A.WHO,"TRANSACTION","MASTER","INTELLIVIEW REPORT","UTILITIES"
    FROM (
         SELECT WHO,NUM "TRANSACTION"
         FROM THINGS2
         WHERE WHAT = 'TRANSACTION'
    ) A,(
         SELECT WHO,NUM "MASTER"
         FROM THINGS2
         WHERE WHAT = 'MASTER'
         ) B,(
         SELECT WHO,NUM "REPORT"
         FROM THINGS2
         WHERE WHAT = 'REPORT'
         ) C,(
         SELECT WHO,NUM "INTELLIVIEW REPORT"
         FROM THINGS2
         WHERE WHAT = 'INTELLIVIEW REPORT'
         ) D,(
         SELECT WHO,NUM "UTILITIES"
         FROM THINGS2
         WHERE WHAT = 'UTILITIES'
         ) E
    WHERE ( A.WHO = B.WHO )
         AND ( A.WHO = C.WHO )
         AND ( A.WHO = D.WHO )
         AND ( A.WHO = E.WHO );
    Ps.
    Could anybody tell me how is it possible to indent text on the board of this forum?
    Bye Alessandro

  • Conditional display of region with PL/SQL function returning SQL query

    Hello,
    ApEx 2.0.
    I use PL/SQL functions that return SQL queries to display the contents of a region.
    How could I conditionally display such region ? If no data is found, the region shouldn't be shown. I tried with "SQL query returns at least one row" but this doesn't seem to work.
    Thanks,
    Matthias

    Hi Matthias,
    Are the regions in question report regions? So your PL/SQL process is returning a SQL query and then populating a report?
    The EXISTS(SQL Query returns at least one row) condition should work, try running the query you are using in the Expression 1 textarea inside SQL*Plus, or SQL developer using the same parameters, and see what gets returned.
    If you are still stuck, can you post the query you are using inside your Expression 1 textarea of the Conditions section and I can take a look at it for you.
    Hope this helps,
    Cj

  • APEX, BI Publisher and SQL Query (PL/SQL Function returning SQL Query)..

    I don't know if I should be posting this in this Forum or the BI Publisher forum, so I am posting in BOTH forums..
    I love APEX, let me say that first.. And appreciate the support offered here by the group, but am running int a confusing issue when BI Publisher tries to build a report from the above type APEX report..
    Here is my dilemma:
    I have a number of reports that are part of a Oracle package. They return an SQL Query back to a reports region on a page. I am having to deal with the column names returned are col01, col02..
    The issue I have is, when building the Application Level query to download the XML sample from in building RTF layouts in Word, you can not use this code, you MUST use a standard SQL Select.
    I have taken the sql from the function returning sql, and copied into the application query, supplying the required data values for bind variables being used in the query.
    An XML file is produced, and I use this to build the RTF format file that I load back into APEX and try to use it for the PDF rendering of the report. I can view the output as a PDF in the Word add on, but when I try using it with the report, it is returning an empty PDF file.
    Can anyone tell me what error log files on the bi publisher side I can look at to see what error is happening?
    Thank you,
    Tony Miller
    UTMB/EHN
    Title changed, maybe SOMEONE has an idea on this??
    Message was edited by:
    Tony Miller

    Hi,
    1/ first check you are passing the bind variables and
    appropriate values in the call to your report - if
    the query returns no data then you get an empty page
    So if your query takes :P10_USERNAME variable then
    pass it to the report in the URL
    f?p=&APP_ID.:0:&SESSION.:PRINT_REPORT=YOUR_REP_QUERY_N
    AME:::P10_USERNAME:MYUSER
    2/ try to use the Default layout first to check your
    report query really returns the data when called
    3/ if you defined a header in your rtf template check
    there is no & (ampersand) - if using & in the header
    and preview the template from word it displays data
    OK, but if you use this template in the report query
    it fails to render the data (bug in Apex-> Bi
    Publisher integration maybe?)
    4/ If using the table in the rtf template check its
    width does not overflow the page margins - there is a
    problem with pdf export
    5/ check
    /oc4j/j2ee/home/application-deployments/xmlpserver/app
    lication.log forthe information on BI Publisher runs
    RadoIssue was in the APEX page having issues.. I recoded a new page and am able to generate BI Publisher based PDF files..
    Thank you,
    Tony Miller
    UTMB/EHN

  • Calling PL/SQL functions in SQL

    Hi,
    I had a question on the behaviour of PL/SQL function when they are embedded in SQL queries.
    I have simple PL/SQl function:
    function get_city_id
    (vCUSTOMER_GROUP_ID IN NUMBER)
    RETURN VARCHAR2 AS
    vIDs VARCHAR2(1000);
    begin
    vIDs := '2,3';
    RETURN vIDs;
    end;
    I use an SQL query call this PL SQL function;
    select equipment_id from equipment where equipment_type_id in (get_city_id(0));
    When I run this query I get this error:
    ERROR at line 1:
    ORA-01722: invalid number
    I understand that the SQL compiler is complaining that get_city_id() function is not returning a number. but isn't the PL/SQL suppose to be replace with whatever string is returned from the function.
    This brings me to the second question: How can we return multiple values from a function to the SQL query, when the function is called in a SQL query. In my above explame, can the get_city_id() function return more than one city id and if yes, the how?
    Thanks for the help in advance
    regards
    Alankar

    How can we return multiple values from a function to the SQL query,Have it return a collection, e.g.
    CREATE OR REPLACE TYPE VARCHAR2_TT AS TABLE OF VARCHAR2(4000)
    CREATE OR REPLACE FUNCTION test_collection
        RETURN VARCHAR2_TT
    AS
    BEGIN
        RETURN VARCHAR2_TT(1,2,3);
    END;
    SELECT *
    FROM   employees
    WHERE  emp_id IN
           ( SELECT column_value
             FROM   TABLE(test_collection) );

  • Dynamic SQL without using SQL

    I have a variable that contains a formula, eg.
    V_FORMULA varchar2(200) := '5 * 50 + 200';
    I want to assign the result of the formula into another variable, without using a DB call with SQL.
    eg.
    V_RESULT number;
    V_RESULT := DBMS_surprise_package(V_FORMULA);
    I want V_RESULT to be 450 after the statement is executed.
    Is that possible?? Is there such a package in PLSQL?
    I think the Forms NAME_IN package did something similar.

    970779 wrote:
    I guess I'll just have to rewrite it using execute immediate with bind variables to stop the shared pool getting filled up with thousands of these statements, since none of you have a non-db solution.Write your own if the expressions are simple enough...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    l_formula varchar2(200) := '5 * 50 + 200';
      3    l_result  number := 0;
      4    tok       varchar2(100);
      5    op        varchar2(100);
      6    function get_token(str in out varchar2) return varchar2 is
      7    begin
      8      tok := trim(regexp_substr(str,'^[0-9]+|[^0-9]+'));
      9      str := trim(regexp_replace(str,'^([0-9]+|[^0-9]+)'));
    10      return tok;
    11    end;
    12  begin
    13    loop
    14      tok := get_token(l_formula);
    15      exit when tok is null;
    16      if tok in ('*','+','-','/') then
    17        op := tok;
    18      else
    19        case op when '*' then l_result := l_result * to_number(tok);
    20                when '+' then l_result := l_result + to_number(tok);
    21                when '-' then l_result := l_result - to_number(tok);
    22                when '/' then l_result := l_result / to_number(tok);
    23        else l_result := to_number(tok);
    24        end case;
    25      end if;
    26    end loop;
    27    dbms_output.put_line(l_result);
    28* end;
    SQL> /
    450
    PL/SQL procedure successfully completed.:D

Maybe you are looking for