SQL Function to trim characters

Hi!
Can someone help me with writing SQL Function which receive a string and return it with all the below ASCII characters values removed:
chr(n)>31 AND chr(n)<48
OR
chr(n)>57 AND chr(n)<65
OR
chr(n)>90 AND chr(n)<97
OR
chr(n)>122 AND chr(n)<128
Thanks

Actually, I forgot chr(127) in there. Try this:
select regexp_replace(yourstring,  '[[:punct:] '||chr(127)||']', '') from dual;Example:
SQL> select regexp_replace(
   'hello !"#$%&''()*+,-./:;<=>?@[\]^_`{|}~'||chr(127)||'there'
   , '[[:punct:] '||chr(127)||']'
) from dual;
REGEXP_REP
hellotherecheers,
Anthony

Similar Messages

  • Sql function for trimming from center

    Hi Experts;
    Is there any function which can remove/trim from center like i have a number
    01-1552963-01 and i want to remove - from it.
    01155296301
    note that i dont want to use substr and concat ||
    regards,

    RB wrote:
    AND With REGEXP_REPLACE
    SQL>  SELECT REGEXP_REPLACE('01-1552963-01','-','')  Sample from dual;
    SAMPLE
    01155296301
    An empty string is considered null in Oracle so that's the same as:
    SQL>  SELECT REGEXP_REPLACE('01-1552963-01','-')  Sample from dual;
    SAMPLE
    01155296301which, let's face it is pretty pointless when a regular REPLACE function will do the same.
    You should only really use the regular expression versions when you have a pattern that needs matching, not just a fixed set of characters.

  • Problem with empty report parameters when passed to PL/SQL function

    Hi,
    We have come across what appears to be a bug in the JRC. When passing a report parameter to a PL/SQL function as a parameter, empty parameters are changed before being sent to the function. More specifically, an empty string "" ends up as the value "(')" in the PL/SQL function parameter. In our report we print the report parameters on the first page so we know that the parameters are OK before being passed to the database.
    The problem exists for version 12.2.203, 12.2.204 and 12.2.205 of the JRC.
    We have identified a workaround, but it is not exactly elegant: Before executing the report we modify all empty  parameters ("") to " " . In the PL/SQL function, we trim all parameters before using them.
    We call the function using a command object with a sql syntax like this example:
    select * from table (qa_batch_release.get_qa_br('{?p_report_id}','{?p_reg_set_number}','{?p_cr_number}','{?p_change_id_decode}','{?p_country_id}','{?p_mfg_item_no}','{?p_4_no}','{?p_5_no}','{?p_7_no}'))
    The PL/SQL function is a table returning function.
    Best regards, Thor

    Hi Kishore,
    using #COLUMN_VALUE# would probably not make much sense, because normally a report has multiple columns and not just the numeric column which you want to verify if it's negative. But APEX will fire the template condition for each column, because the report template is a column cell template.
    What you can do to make it more generic is to use for example
    #CHECK_AMOUNT#
    in the template and provide a not displayed column in your SQL statement which contains your value which is named CHECK_AMOUNT. For example:
    SELECT NAME
         , BALANCE
         , BALANCE AS CHECK_AMOUNT
    FROM XXX;Because this CHECK_AMOUNT column would be a generic name, you can use this template in all your reports as long as you provide this column.
    Thope that helps
    Patrick

  • 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.

  • SQL query (pl/sql function body returning query) performance issue

    I create my report in building my sql instruction with ( SQL Query pl/sql function body returning sql query );
    My report take more than 20 seconds however if i did a cut and paste with the sql code in TOAD the same sql take 1 second.
    To try to discover the source of the problem; i take the sql generated by the function and i create another report ( sql query ) this new report take 2 seconds.
    My query is very big 25,000 characters with database link.
    What is the difference between SQL-quey and sql-query(pl/sql function body returning sql query)
    Thanks
    Marc

    Marc,
    Firstly...don't compare the timings from Toad, since often Toad only fetches the first few records for you (i.e. it pages them).
    Secondly....the database link could be a factor here, but without seeing your query it's too hard to say.
    Can you post the query somewhere (on a webserver say)?

  • Sql Functions in AttributeQualification?

    Using the CMSDK Search API, is there a way to use a SQL function in an AttributeQualification, without using the FreeFormQualification? (I'm using CMSDK 9.0.4)
    My need is that I would like to make queries ignoring the accentued characters of the attribute values. I wondered doing this by applying a custom "normalizer" function on the attribute values in the attribute qualification. If it will not be possible, I will use free-form qualifications.
    Thanks.
    Daniel.

    The FreeFormQualification works fine for applying Sql functions on simple attributes. However, it is not that simple to do the same to array attributes, because the values are stored in another table.
    Please, how could I apply SQL functions on array attributes without having to reverse engineer the search API's behavior?
    Thanks!
    Daniel.

  • SQL functions in forms

    Hi
    I am using forms 4.5 and I have the following code in one of the program untis.
    SELECT     trim(leading '-' from nvl(SUM(nvl(TRANS_QTY,0)),0)) NET
         FROM      inventories     
         WHERE     TRANS_QTY LIKE '-%' ;
    i.e I want the sum of all the quantities dispatched. For received quantities, it is + and for dispatched, it is -.
    The above code works fine in SQL plus session. When used in forms, it returns
    encountered the symbol '-' when expection one of the following.........error.
    Please suggest.
    Thanks.

    As of now, I used abs instead of trim and performed desired operation.
    SELECT abs(SUM(nvl(TRANS_QTY,0))) NET
    FROM inventories
    WHERE TRANS_QTY LIKE '-%' ;
    I woudl like to know if it is possible to use trim (SQL functions) or not.
    Thanks.

  • Problem with PL/SQL Function Body

    Hi,
    I'm getting the following error, when i run the report.
    I'm trying to fetch a year value from a table based on a parameter value ":P33_YEAR"
    ORA-01403: no data found
    Error ERR-1904 Unable to compute item default: type = Function Body computation_type= DECLARE FY VARCHAR2(6); BEGIN SELECT DISTINCT YEAR1 INTO FY FROM REP WHERE YEAR = TRIM(:P33_YEAR);
    RETURN FY; END;.
    I have written this code in a PL/SQL Function Body for a Hidden item.
    Please let me know whats wrong with this code?
    Thanks
    CK
    Message was edited by:
    user536304

    Your code is in a default value for an item, right?
    You need to make sure :P33_YEAR is not null and handle the error in the PL/SQL if it is.
    How is P33_YEAR populated? do you pass it in? check to see if it is making it there..
    Message was edited by:
    Bill Carlisle

  • Sql query(PL/SQL function body return SQL query) with in(x,y,z) condition

    Hello,
    I've set up a region definition of type "SQL Query(PL/SQL function body return SQL query). In my query I make use of an "in" condition. When I populate :P755_INC_BARG_UNIT with a value of 0F (no quotes), I get the correct count. However, when I set :P755_INC_BARG_UNIT to 0F, 0E I get an invalid count. What do I have to set the page item to?
    When running the query in TOAD, and setting :P755_INC_BARG_UNIT to the string inside the brackets (0F, 0E) I get the proper count.
    The code I use is shown below. Any help would be appreciated,
    Alex.
    DECLARE
    v_sql VARCHAR2(32767);
    BEGIN
    SELECT count(*) "cnts",
    ''Faculty data file IDs missing in appt table'' "err_type"
    FROM hradmin.et_faculty_salary fs left outer join
    hradmin.appointments appt
    ON trim(fs.empl_id) = appt.emp_emp
    and appt.ear_activ <> ''Z''
    and appt.ear_type = ''F''
    and (appt.ear_class in (''A'',''B'',''C'',''D''))
    and appt.ear_bargunit in ( :P755_INC_BARG_UNIT )
    WHERE appt.emp_emp is null
    RETURN v_sql;
    END;

    Alex,
    try something like:
    DECLARE
    v_sql VARCHAR2(32767);
    BEGIN
    v_sql := <YOUR_SQL_STATEMENT_WITH_P755_INC_BARG_UNIT_IN_IT>;
    v_sql :=  REPLACE(v_sql, ':P755_INC_BARG_UNIT',:P755_INC_BARG_UNIT);
    RETURN v_sql;
    END; But before doing it read this:
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:210612357425
    After reading you will be able to find the best solution yourself.
    Lev

  • LOOP in PL/SQL Function Body Help Needed

    I have a PL/SQL function that I'm trying to run and use a LOOP but I'm having some problems. I know the loop works since it output's two commas for me, which is how many records the query used for the LOOP returns, but I can't seem to find the right syntax to reference the column.
    DECLARE
    str VARCHAR2(2000) := "";
    BEGIN
    IF :P21_GLOBAL_ID IS NOT NULL THEN
    FOR q IN (
    SELECT
    ID,
    DRAW_DATE,
    ENTERED_BY
    FROM
    SAMPLE_T
    WHERE
    ID = :P21_GLOBAL_ID
    ORDER BY
    DRAW_DATE
    LOOP
    str := str || q.ID || ',' ;
    END LOOP;
    END IF;
    RETURN STR
    END;

    I just sent you the credentials.
    Interestingly, I have this same code for the source of a textarea on the page and the source for a report. I then modified the PL/SQL code as follows:
    DECLARE
         varSelect VARCHAR2(32767) := ''; --hold query SELECT definition
         varFrom VARCHAR2(32767) := ''; --hold query FROM clause definition
         varWhere VARCHAR2(32767) := ''; --hold query WHERE clause definition
         varOrderBy VARCHAR2(32767) := ''; --hold query ORDER BY clause definition
         varQuery VARCHAR2(32767) := ''; --hold query definition
    BEGIN
         IF TRIM(LOWER(TO_NUMBER(:P21_GLOBAL_TEMPLATE_ID))) IS NOT NULL THEN
              varSelect := 'SELECT SUBJECT_ID';
              varSelect := varSelect || ', SUBJECT_ID AS PHI';
              varSelect := varSelect || ', SUBJECT_ID AS ENTER_DATA';
              varSelect := varSelect || ', SUBJECT_ID AS LOGISTICA';
    for varTempQuery IN (
    SELECT
    stc.question_name as field_name,
    sti.read_security,
    sti.write_security,
    nvl(sti.validation_type,decode(stc.validation_rules,'None','TEXT_FIELD')) as validation_type,
    sti.html_caption,
    nvl(upper(sti.html_display_type),'TEXTFIELD') as html_display_type,
    sti.html_table_row,
    sti.html_table_column
    FROM
    rix.study_subject_templates sst,
    rix.study_subject_Template_items sti,
    rix.questions stc
    WHERE
    TRIM(LOWER(TO_NUMBER(sst.ss_template_Id))) = TRIM(LOWER(TO_NUMBER(:P21_GLOBAL_TEMPLATE_ID)))
    AND TRIM(LOWER(TO_NUMBER(sst.ss_Template_id))) = TRIM(LOWER(TO_NUMBER(sti.ss_Template_id)))
    AND TRIM(LOWER(TO_NUMBER(sti.phi_qid))) = TRIM(LOWER(TO_NUMBER(stc.qid)))
    AND TRIM(LOWER(TO_CHAR(sti.template_item_Status))) <> TRIM(LOWER(TO_CHAR('RETIRED')))
    ORDER BY
    sti.html_Table_row,
    sti.html_table_column
    LOOP
    varSelect := varSelect || ', ' || varTempQuery.field_name;
    END LOOP;
              varFrom := 'FROM     RIX.SUBJECTS';
              varWhere := 'WHERE STUDY_ID = ' || TRIM(LOWER(TO_NUMBER(:P21_STUDY_ID )));
              varOrderBy := 'ORDER BY';
              varOrderBy := varOrderBy || ' subject_label ';
    varQuery := varSelect || ' ' || varFrom || ' ' || varWhere || ' ' || varOrderBy;
         ELSE
    varQuery := 'SELECT SUBJECT_ID FROM SUBJECTS WHERE study_id = :P21_STUDY_ID;';
         END IF;
    RETURN varQuery;
    END;
    When I run the page now, the textarea has the SQL statement generated from the first IF block, but the report using the statement from the ELSE block. I thought it maybe was a timing issue, but both blocks reference other fields on the page, so it doesn't seem to be a timing issue. Shouldn't be a condition issue either with the IF block as the textarea and report use the same source, but are evaluating differently.
    Very odd (to me at least).

  • PL/SQL Function to convert fields & set max length

    I am having a problem with the following assignment:
    Write a stored PL-SQL function called namefct that will convert two varchar2 fields (first and last names) into the format: lastname, firstname with a maximum length of 10 chars. If the combined size of the two names is greater than 10 characters, you will issue an error message indicating the name has been shortened to 10 characters and return only the first ten characters, otherwise return the entire name. Test the namefct function by using the staff table created in Part 1 (above). Turn in: the SQL statements to build the function, execute the sample code and the resulting output.
    This is the start of my attempt, excluding the error message that is to be issued:
    CREATE OR REPLACE FUNCTION namefct (fname VARCHAR2, lname VARCHAR2) IS
    BEGIN
    column "full name" format a10;
    SELECT namefct(fname, lname) as "full name" from staff;
    END namefct
    Any advice or assistance would be greatly appreciated, since my Professor seems unwilling to assist me. Thanks!

    Write a stored PL-SQL function called namefct that
    will convert two varchar2 fields (first and last
    names) into the format: lastname, firstname with a
    maximum length of 10 chars. If the combined size of
    the two names is greater than 10 characters, you will
    issue an error message indicating the name has been
    shortened to 10 characters and return only the first
    ten characters, otherwise return the entire name.
    Test the namefct function by using the staff table
    created in Part 1 (above). Turn in: the SQL
    statements to build the function, execute the sample
    code and the resulting output.Firstly you need to consider what you have already been taught as you need to ensure that you code your function according to the purpose of the assignment. i.e. are you supposed to be demonstrating the use of returning values in a function or are you supposed to be demonstrating the use of exception handling etc.
    The main tricky bit with this assignment is the requirement to show an error message and still return a value. If you were to just raise an exception with the error message (e.g. raise application error) then you won't be able to actually return a value. Because it's a function and not a procedure that has been specified you aren't returning the value in an OUT parameter which would have made passing the value back and raising an exception easier.
    So, the only real way to have a function and allow it to show an error message would be something like...
    SQL> ed
    Wrote file afiedt.buf
      1  CREATE OR REPLACE FUNCTION f_name(p_forename IN VARCHAR2, p_surname IN VARCHAR2) RETURN VARCHAR2 IS
      2    name_too_long EXCEPTION;
      3  BEGIN
      4    IF LENGTH(p_surname||', '||p_forename) > 10 THEN
      5      RAISE name_too_long;
      6    END IF;
      7    RETURN p_surname||', '||p_forename;
      8  EXCEPTION
      9    WHEN name_too_long THEN
    10      DBMS_OUTPUT.PUT_LINE('Name Too Long. Truncating to 10 chrs.');
    11      RETURN SUBSTR(p_surname||', '||p_forename, 1, 10);
    12* END;
    SQL> /
    Function created.
    SQL> select f_name('FRED','SIMS') from dual;
    F_NAME('FRED','SIMS')
    SIMS, FRED
    SQL> select f_name('FRED','SIMKINSON') from dual;
    F_NAME('FRED','SIMKINSON')
    SIMKINSON,
    Name Too Long. Truncating to 10 chrs.
    SQL>Note: Tutors/Professors are very wise to checking your work on the internet to make sure it hasn't been copied, so I would suggest you don't just copy this verbatim, but actually read it and understand how it's working and write your own version, taking account of what you have been taught so far and not using things you haven't been taught.
    ;)

  • Retrive records using ODATA with SQL functions

    Hi,
    I want to use SQL functions (for instance replace function) while retrieving records using ODATA endpoint using javascript. Like this:
    parent.SDK.REST.retrieveMultipleRecords(
    "$select=AccountId,Name,Telephone1&$filter=" + "replace(Telephone1,'-','') eq '12345678'",
    function (accountresults) {
    errorHandler,
    function () {
    But this is ending up with 404 bad request. Is there any way to achieve the same using any other technique?
    blog: <a href="http://technologynotesforyou.wordpress.com">http://technologynotesforyou.wordpress.com</a> | skype: ali.net.pk

    ODATA only supports simple comparison operators, and startswith, endswith and substringof. There are 2 approaches you could use without modifying the data:
    Have a less selective filter in ODATA, then filter the rest of the data in javascript. In this example, you could use ODATA to find all records where the telephone1 field has each of '1', '2', '3' etc, then use javascript to do the replace comparison. It
    depends how many records you have as to whether this is practical
    Write a plugin on RetrieveMultiple that applies the functions you want. This is not necessarily simple, and you'd need to determine how you identify in the query that you want to use a function like replace
    Another option could be to use a plugin when data is saved to strip out the characters you don't want, and store the results in a different field that you could then query on
    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

  • Convert Access Module to SQL Function - Hex To Dec conversion

    I need to convert an Access Module to a SQL Function but not sure how to successfully accomplish this.
    The module has several different functions to convert hexadecimal numbers to decimal and vice versa. I am not sure if I needed to break out each module function into a seperate function in SQL or not. Any help would be appreciated.
    Here is the actual module that needs to be converted:
    Public Function MEID_DecToHex(mMEIDDec As String) As String
        'Dim mMEIDDec As String
        Dim mManNum As Double
        Dim mSerialNum As Double
        Dim mMEIDHex As String
        Dim mManHex As String
        Dim mSerialHex As String
        'mMEIDDec = "268435457304109828"
        '*** Check MEID digits, make sure it is 18 digits else return invalid
        If Len(mMEIDDec) = 18 Then
            '*** 18 digit decimal code: 1st 10 digits is for the Manufacturer and last 8 digits is for the Serial Number
            mManNum = Left(mMEIDDec, 10)
            mSerialNum = Right(mMEIDDec, 8)
            '*** Convert MEID Dec to Hex
            mManHex = DecToHex(mManNum)
            mManHex = fntPad(mManHex, "0", 8)
            mSerialHex = DecToHex(mSerialNum)
            mSerialHex = fntPad(mSerialHex, "0", 6)
            MEID_DecToHex = mManHex & mSerialHex
        ElseIf Len(mMEIDDec) = 11 Then
            '*** 11 digit decimal code: 1st 3 digits is for the Manufacturer and last 8 digits is for the Serial Number
            mManNum = Left(mMEIDDec, 3)
            mSerialNum = Right(mMEIDDec, 8)
            '*** Convert MEID Dec to Hex
            mManHex = DecToHex(mManNum)
            mManHex = fntPad(mManHex, "0", 2)
            mSerialHex = DecToHex(mSerialNum)
            mSerialHex = fntPad(mSerialHex, "0", 6)
            MEID_DecToHex = mManHex & mSerialHex
        Else
            MEID_DecToHex = "Invalid"
        End If
    End Function
    Public Function MEID_HexToDec(mMEIDHex As String) As String
        'Dim mMEIDDec As String
        Dim mManNum As String
        Dim mSerialNum As String
        'Dim mMEIDHex As String
        Dim mManDec As String
        Dim mSerialDec As String
        'mMEIDHex = "a000001937b27a"
        ' Remove any spaces befor or after the string
        mMEIDHex = Trim(mMEIDHex)
        '*** Check MEID digits, make sure it is 14 digits else return invalid
        If Len(mMEIDHex) = 14 Then
            '*** 14 hexadecimal digits: 1st 8 digits is for the Manufacturer and last 6 digits is for the Serial Number
            mManNum = Left(mMEIDHex, 8)
            mSerialNum = Right(mMEIDHex, 6)
            '*** Convert MEID Hex to Dec
            mManDec = HexToDec(mManNum)
            mManDec = fntPad(mManDec, "0", 10)
            mSerialDec = HexToDec(mSerialNum)
            mSerialDec = fntPad(mSerialDec, "0", 8)
            MEID_HexToDec = mManDec & mSerialDec
        ElseIf Len(mMEIDHex) = 8 Then
            '*** 8 digit Hex code: 1st 2 digits is for the Manufacturer and last 6 digits is for the Serial Number
            mManNum = Left(mMEIDHex, 2)
            mSerialNum = Right(mMEIDHex, 6)
            '*** Convert MEID Dec to Hex
            mManDec = HexToDec(mManNum)
            mManDec = fntPad(mManDec, "0", 3)
            mSerialDec = HexToDec(mSerialNum)
            mSerialDec = fntPad(mSerialDec, "0", 8)
            MEID_HexToDec = mManDec & mSerialDec
        Else
            MEID_HexToDec = "Invalid"
        End If
    End Function

    Try link
    you can create & use CLR function
    or you can simply convert on fly refer below link
    http://blog.sqlauthority.com/2010/02/01/sql-server-question-how-to-convert-hex-to-decimal/
    http://blog.sqlauthority.com/2012/07/26/sql-server-answer-how-to-convert-hex-to-decimal-or-int/
    decimal to hex
    http://stackoverflow.com/questions/13643729/decimal-to-hex-conversion-in-sql-server-2008

  • 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

  • Passing Multiple Values from a worksheet to PL/SQL function.

    Hi All,
    Is there any way to pass multiple values selected in a worksheet to a PL/SQL function ?
    I will try to explain the scenario:
    We have a crosstab report that showing all the customer details, deposit sum of a customer in each date in a date range selected. With the customer details we are showing the Rank of a customer based on the deposit in the latest date selected. Filtering is based on the rank, ie Top50 or Top60 etc.( As I said rank is calculating based on the deposit in the latest date).This is working fine.
    Now the new requirement is to : For example, in Top50 report, list all the customers, who were in the Top50 list, in any of the dates selected. We are able to display the daywise rank, but when giving a condition like daywiserank <= 50, the result becomes uncertain. Some blank lines, wrong amounts etc..
    As a work around we tried to find out the rank in a PL/SQL function. But the issue there is : we have some multiple value parameters used in the worksheet.
    Is there any way to pass multiple values selected in a worksheet to a PL/SQL function ?
    Or any other work arounds for the scenario explained?
    Reagrds,
    Jeneesh

    Hi Russ,
    Thanks for the response.
    Russ Proudman wrote:
    1. I thought there was an analytical function similar to rank - or maybe an option of rank - that if there are duplicate records to have them all considered the same rank. So if you had 3 records all the same as rank=2 then a condition saying where rank=2 would return the 3 records. You could check into this.
    We are already using DENSE_RANK. But the issue is the output contains incorrect null values nd repeated rows.
    We got it solved as I explained in the previous post. But will that AGGREGATION MODE setting ( Which discoverer says - not recommended) have any issue? I mean side effects?
    Russ Proudman wrote:
    2. Another thought is that you can create a PL/SQL routine - that's called from a SQL function registered in Discoverer - where a table is created that does the first part of your query. Then a worksheet is created to use the data from that table. So, in essence, the table would have your top50 ranked customers. Then you can write any kind of worksheet against that table. However, DBAs are loath to allow tables - that they didn't create! - many times in a PROD environment.
    Here also the same problem will occur: as the top 50 will depend upon the parameters. I cannot pass those parameters to PL/SQL Function.And storing the top50 ( itmay be top100 or to 150 also) for all combinations of the parameters is impossible
    Russ Proudman wrote:
    3. Finally, are you sure you're rank function is correct in that if you're getting blank lines, maybe the 'over' part is not considering all columns needed to determine the rank?
    Yes the query we are using is correct. The output QUERY of discoverer gives correct results in Sqlplus.
    Regards,
    Jeneesh

Maybe you are looking for