SQL Replace function - error

I am little bit struggling to get the my sql function below, to execute the correct output:
ALTER FUNCTION [dbo].[ReplaceTags](@XML VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
SELECT @XML = REPLACE(@XML,[Name],'<a href="<a href="pagename.aspx?tag='+[name]+'">'+[name]+'</a>')
FROM [dbo].[database_tags]
where UploadDate >= '2014-09-01'
RETURN @XML
END
When I call the function (select title, [dbo].[ReplaceTags](XML) from article ), it outputs the following result below, whereas the original data is this - (One is a 1m block of AIREM 2006-1X 2A3,).
Query output:
One is a &amp;#163;1m block of <a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a href="pagename.aspx?tag=<a href="<a
href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>"><a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a></a>"><a href="<a href="pagename.aspx?tag=<a
href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a>"><a href="<a href="pagename.aspx?tag=AIREM 2006-1X 2A3">AIREM 2006-1X 2A3</a></a></a>"><a href="<a
href="pagename.aspx?tag=<a href="<a
I am not sure, why it keep duplicating the name.  Please advice, where I may be going wrong. 
Thank you for your help and time.

Hi,
There is no problem do this using CLR in the database side, as well. You can use SQLCLR regular expression function.
In any case your HTML is wrong in the original question. You asked for 
SELECT @XML = REPLACE(@XML,[Name],'<a href="<a href="pagename.aspx?tag='+[name]+'">'+[name]+'</a>')
but you need 
SELECT @XML = REPLACE(@XML,[Name],'<a href="pagename.aspx?tag='+[name]+'">'+[name]+'</a>')
Please post DDL+DML for the [database_tags] table.
  Ronen Ariely
 [Personal Site]    [Blog]    [Facebook]

Similar Messages

  • SQL Replace function: errors if replacement text is 8191 characters

    Oracle 10.2.0.3.0 Enterprise Edition
    I'm working on an application which has a function to generate emails.
    We have a template, which gets filled with data from the database depending on the email being sent.
    To do this I'm using the Replace function to replace certain parts of the template with the right data.
    It seems that if the replacement text (the third argument to the function) is longer than 8191 bytes the function throws a PL/SQL: numeric or value error.
    This limitation doesn't appear to be documented anywhere, certainly nowhere that I can find.
    Anyone know of a way around this short of building my own replace function?

    I've figured out what was going on.
    The database column for the replacement text is defined as a clob, but there is a front end limit of 10,000 characters for the field being used.
    When using the replace function I was assigning the value to a varchar2(32767) field in the PL/SQL.
    So in terms of datatypes the function call is:
    varchar2 := replace(varchar2, varchar2, clob)
    If the length of the clob is over 8191 characters it errors.
    (Presumably because of the bug mentioned in this thread DBMS_LOB.SUBSTR() returning 8191 characters instead of 32767
    I've fixed it by simply changing the datatype of the variable to which the value is being assigned to a clob.

  • Create Or Replace Function Error

    Hello,
    I'm doing text mining using Oracle SQL Developer: ODMiner.. I imported the data "WEBLOG" into a table.. This weblog data consist of users activity, date, time, url, etc. The first step I took was to use a function to transform date and time that I have in the data table, into a number representing the 40 mins since 01-01-1990. I did this by dividing it by 2400 (seconds in 40 mins). The main purpose is to have a time frame for the sessions.
    I used the following code,
    CREATE OR REPLACE FUNCTION ssnDate(
    DATE IN VARCHAR2 DEFAULT 03-01-18,
    TIME IN VARCHAR2
    ) RETURN NUMBER
    AS
    BEGIN
    RETURN TRUNC((to_date(DATE||' '||TIME, 'DD-MM-YY HH:MM:SS')- to_date('01-JAN-1990','DD-MON-YYYY')) * (86400/2400);
    END ssnDate;
    This was what appeared in the log after running the statement,
    FUNCTION ssnDate compiled
    Warning: execution completed with warning
    After this, I tried to create a VIEW to transform the DATE and TIME with the ssnDate that was created earlier on, and concatenate the CS_URI_STEM (which is the resource accessed), and CS_URI_QUERY (which is the the query, if any, the client was trying to perform)into a new field called WEB_LINK.
    This is the code used,
    CREATE OR REPLACE VIEW WEBLOG_VIEWS("C_IP", "WEB_LINK", "CS_USER_AGENT", "SESSION")
    AS
    SELECT ssnDate(LOG_DATE, LOG_TIME) AS 'SESSION',
    C_IP,
    CS_USER_AGENT,
    (CS_URI_STEM||'?'||CS_URI_QUERY) AS WEB_LINK
    FROM WEBLOG;
    Now from this I got the following error..
    Error starting at line 1 in command:
    CREATE OR REPLACE VIEW WEBLOG_VIEWS("C_IP", "WEB_LINK", "CS_USER_AGENT", "SESSION")
    AS
    SELECT ssnDate(LOG_DATE, LOG_TIME) AS 'SESSION',
    C_IP,
    CS_USER_AGENT,
    (CS_URI_STEM||'?'||CS_URI_QUERY) AS WEB_LINK
    FROM WEBLOG
    Error at Command Line:3 Column:38
    Error report:
    SQL Error: ORA-00923: FROM keyword not found where expected
    00923. 00000 - "FROM keyword not found where expected"
    *Cause:
    *Action:
    I don't get where I'm going wrong with this.. This is the data preparation stage which requires me to prep the data before applying modeling techniques or algorithms.. The next step would be grouping the data, based on the session time, ip and the user agent of each session along with the web_links fields visited by the user in that session.
    I would really be grateful for any inputs on where I'm going wrong and any solutions for that!

    Ok, not sure I really understand, but I posted the query and this is the output I got..
    ORA-31603: object "WEBLOG" of type TABLE not found in schema "WEBLOG_TABLE_OWNER_NAME"
    ORA-06512: at "SYS.DBMS_METADATA", line 2625
    ORA-06512: at "SYS.DBMS_METADATA", line 2668
    ORA-06512: at "SYS.DBMS_METADATA", line 2983
    ORA-06512: at "SYS.DBMS_METADATA", line 3897
    ORA-06512: at "SYS.DBMS_METADATA", line 5678
    ORA-06512: at line 1
    31603. 00000 - "object \"%s\" of type %s not found in schema \"%s\""
    *Cause:    The specified object was not found in the database.
    *Action:   Correct the object specification and try the call again.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • SQL replace function in JDeveloper

    In SQL*Plus I run the following queries...
    select last_name, phone_number from employees
    LAST_NAME PHONE_NUMBER
    Chung 650.505.1876
    Dilly 650.505.2876
    Gates 916.764.6600
    select last_name, replace (phone_number, '.', '-') from employees
    LAST_NAME REPLACE(PHONE_NUMBER
    Chung 650-505-1876
    Dilly 650-505-2876
    Gates 916-764-6600
    If I try to use the "REPLACE" function in the JDeveloper by editing the sql statement in the view object editor and run the page the results returned for the phone number column on the page are blank.
    How can I substitute a dash for the period on the page?

    Try using AS:
    select last_name, replace (phone_number, '.', '-') AS phone_number from employees
    In this case is recommended for your VO a read only query.

  • SQL Replace Function

    I have a small software to generate Letters. This is integrated with the Sales module. Both Sales and Letter modules are developed using Oracle10g.
    In the Letters module user can write his/her own letter and if we want to add some information from the sales module, he can include a tag. For example if the user wants to write a letter to a particular customer who has placed an order he will write as follows:
    "Customer: <CUSTOMER_NAME>
    Address: <CUSTOMER_ADDRESS>
    Thanks for placing order to us. Your order number is <ORDER_NUMBER>"
    Now the letter module automatically looks for tags in the letter typed by the user and replaced the tags with the appropriate values.
    But the problem I am facing is when the value of tag is on two lines the second line starts from position 1 like
    "Customer: Oracle Corporation
    Address: Oracle Corporation
    500 Oracle Parkway
    Redwood Shores, CA 94065
    Thanks for placing order to us. Your order number is 123"
    Please note that 2nd and 3rd lines of address are starting from position 1 where as it should look like
    "Customer: Oracle Corporation
    Address: Oracle Corporation
    500 Oracle Parkway
    Redwood Shores, CA 94065
    Thanks for placing order to us. Your order number is 123"
    (Note the spaces before 2nd and 3rd lines of address)
    My code is given below
    Please help
    FUNCTION PREPARE_LETTER_FORMAL_SUPPLIER(P_SUPPLIER_ID VARCHAR2,P_SUPPLIER_LOC_ID VARCHAR2,P_SUPPLIER_CONTACT_ID VARCHAR2, P_LETTER_ID NUMBER, P_STATION_ID VARCHAR2) RETURN VARCHAR2 IS
    V_TEXT VARCHAR2(4000);
    CURSOR C_LETTER_TAGS IS
    SELECT LT.COLUMN_NAME, LT.LETTER_TAG
    FROM LETTER_TAG_FORMAL LT;
    BEGIN
    SELECT L.TEXT
    INTO V_TEXT
    FROM LETTERS L
    WHERE L.LETTER_ID = P_LETTER_ID;
    FOR LP IN C_LETTER_TAGS LOOP
    IF INSTR( V_TEXT, LP.LETTER_TAG ) > 0 THEN
    V_TEXT := REPLACE( V_TEXT, LP.LETTER_TAG, GET_TAG_VALUE_FORMAL_SUPPLIER(P_SUPPLIER_ID ,P_SUPPLIER_LOC_ID , P_SUPPLIER_CONTACT_ID , LP.LETTER_TAG, P_STATION_ID));
    END IF;
    END LOOP;
    RETURN V_TEXT;
    END;
    FUNCTION GET_TAG_VALUE_FORMAL_SUPPLIER (P_SUPPLIER_ID VARCHAR2,P_SUPLIER_LOC_ID VARCHAR2,P_SUPPLIER_CONTACT_ID VARCHAR2, P_LETTER_TAG VARCHAR2,P_STATION_ID VARCHAR2) RETURN VARCHAR2 IS
    V_COLUMN_NAME VARCHAR2(30);
    V_VALUE VARCHAR2(4000);
    V_QUERY VARCHAR2(4000);
    BEGIN
    SELECT LT.COLUMN_NAME
    INTO V_COLUMN_NAME
    FROM LETTER_TAG_FORMAL LT
    WHERE UPPER(LT.LETTER_TAG) = UPPER(P_LETTER_TAG);
    V_QUERY :=
    'SELECT string_agg( DISTINCT ' || V_COLUMN_NAME || ') FROM(
    SELECT COMMON.GET_SUPPLIER('||P_SUPPLIER_ID||')SUPPLIER,
    SYSDATE DATED,
    COMMON.GET_SUPPLIER_LOCATION('||P_SUPLIER_LOC_ID||')SUPPLIER_LOCATION,
    COMMON.GET_SUPPLIER_ADDRESS('||P_SUPLIER_LOC_ID||')SUPPLIER_ADDRESS,
    COMMON.GET_SUPPLIER_ADDRESS2('||P_SUPLIER_LOC_ID||')SUPPLIER_ADDRESS_MAIL,
    COMMON.GET_COMPANY_BY_STATION('||P_STATION_ID||')COMPANY,
    LETTER.GET_MULTI_SUPPLIER_CONTACTS('||P_SUPLIER_LOC_ID||')SUPPLIER_CONTACT
    FROM DUAL
    EXECUTE IMMEDIATE( V_QUERY ) INTO V_VALUE;
    RETURN V_VALUE;
    END;

    an idea
    select 'Address: 1st line'||chr(10)||'2nd line'||chr(10)||'3rd line' old_address,
           replace('Address: 1st line'||chr(10)||'2nd line'||chr(10)||'3rd line',chr(10),rpad(chr(10),10)) new_address
      from dualRegards
    Etbin

  • PL/SQL Function error

    Hi Guys,
    I've been getting driven a little crazy with this piece of code...
    create or replace function "GetHeirachy" (current VARCHAR2) return VARCHAR2 is
         name VARCHAR2(4000);
         hold VARCHAR2(4000);
         parent VARCHAR2(4000);
    BEGIN
         LOOP
         SELECT PARENT_ITEM_ID, ITEM_NAME INTO parent, name
         FROM HTMLDB_OARS.ITEM_REGISTER
         WHERE ITEM_ID = current;
         IF hold IS NULL THEN
              hold := name;
         ELSE
              hold := name || '/' || hold;
         END IF;
         current := parent;
              EXIT WHEN current IS NULL;
         END LOOP;
         RETURN hold;
    END "GetHeirachy";
    basically the table structure is a self referencing table that creates a heirachy effect, and i need to be able to return a string of "parent/child/grandchild" for display purposes, the function begins with the grandchild and then uses the references to collect each parent and add it to the return.
    When i put the function into sql workshop it is fine but if i try soemthing as simple as
    begin
    htp.prn(GetHeirachy('34'));
    end;
    i get these errors;
    ORA-06550: line 2, column 9:
    PLS-00905: object HTMLDB_OARS.GETHEIRACHY is invalid
    ORA-06550: line 2, column 1:
    PL/SQL: Statement ignored1. begin
    2. htp.prn(GETHEIRACHY('34'));
    3. end;
    Is there something simple wrong with my function code? pl/sql isn't my native language... and i don't know how to debug properly!
    Cheers,
    Alex

    alright - code complete, i'll post it for the sake of others doing soemthing similar;
    create or replace function GetHeirachy (current varchar2) return VARCHAR2 is
    name VARCHAR2(4000);
    hold VARCHAR2(4000);
    parent VARCHAR2(4000);
    cur VARCHAR2(4000);
    BEGIN
    cur := current;
    for i in 1..10 LOOP
    SELECT PARENT_ITEM_ID, ITEM_NAME INTO parent, name
    FROM HTMLDB_OARS.ITEM_REGISTER
    WHERE ITEM_ID = cur;
    IF hold IS NULL THEN
    hold := name;
    ELSE
    hold := name || '/' || hold;
    END IF;
    cur := parent;
    EXIT WHEN cur IS NULL;
    END LOOP;
    RETURN hold;
    END GetHeirachy;
    :) - cheers for the help.

  • Incorrect syntax errors in sql server function. Please help.

    This is my sql server function:
    create function dbo.CleanTheStringAdv (@theString nvar
    char(500), @CleanMode as int) 
    returns nvarchar(500)  
    begin  
    --define variables
    declare @strAlphaNumeric nvarchar(500)  
    declare @i int
    declare @strChar nvarchar(500)
    declare @CleanedString nvarchar(500)
    --initiate values
    set @CleanedString =''  
    set @theString = @theString + ''
    SET @i = 1
    --Determine if we are looking for numeric values only or numbers and letters
    return case @CleanMode
       WHEN 1
       THEN @strAlphaNumeric = '0123456789'
       WHEN 2
       THEN @strAlphaNumeric = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
       WHEN 3
       THEN @strAlphaNumeric = '|0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
       else 0
     end 
    --Search through chars in the string passed to the function
        while (@i <= Len(@theString))
    begin
    @strChar = substring(@theString, @i, 1)
    If (charindex(@strAlphaNumeric, @strChar) <>0)
    --if the current char being reviewed is valid then add it to the new string
    begin
    @CleanedString = @CleanedString + @strChar
    end
    end
    return @CleanedString
    and below are the syntax errors I see when I press F5:
    Msg 102, Level 15, State 1, Procedure CleanTheStringAdv, Line 24
    Incorrect syntax near '='.
    Msg 102, Level 15, State 1, Procedure CleanTheStringAdv, Line 39
    Incorrect syntax near '@strChar'.
    Msg 102, Level 15, State 1, Procedure CleanTheStringAdv, Line 43
    Incorrect syntax near '@CleanedString'.
    Any help is highly appreciated.....

    Here is the full code for the function:
    create function dbo.CleanTheStringAdv (@theString nvarchar(500), @CleanMode as int)
    returns nvarchar(500)
    as
    begin
    --define variables
    declare @strAlphaNumeric nvarchar(500)
    declare @i int
    declare @strChar nvarchar(500)
    declare @CleanedString nvarchar(500)
    --initiate values
    set @CleanedString =''
    set @theString = @theString + ''
    SET @i = 1
    --Determine if we are looking for numeric values only or numbers and letters
    SET @strAlphaNumeric = case @CleanMode
    WHEN 1
    THEN '0123456789'
    WHEN 2
    THEN '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    WHEN 3
    THEN '|0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    else 0
    end
    --Search through chars in the string passed to the function
    while (@i <= Len(@theString))
    begin
    set @strChar = substring(@theString, @i, 1);
    If (charindex(@strAlphaNumeric, @strChar) <>0) --if the current char being reviewed is valid then add it to the new string
    begin
    SET @CleanedString = @CleanedString + @strChar;
    end
    END
    return @CleanedString;
    END

  • ADO function error:SQL execute.vi is not executable​.

    Thanks for everyone who is willing to help me out of this problem that puzzled me several days,I can't find a similar one from Google or other forum..
    Problem:
    When I was using LabSQL,it come an error:
    Subvi "SQL execute":subvi isnot executable. and then I searched the source of the error,it was finally found to be the 
    "ADO Recordset GetString.vi":
    "invoke node:invalid method"
    "invoke node:invalid refnum class". 
    What I used is Windows 7 and LabVIEW7.1.
    Attached is the detail of this problem that includes the vi and some error pictures,and the ADO functions I used.
    ute.vi" is
    Attachments:
    Error.zip ‏1865 KB

    Duplicate - http://forums.ni.com/t5/LabVIEW/ADO-function-error​-SQL-execute-vi-is-not-executable/m-p/2397360#M742​...
    Try to take over the world!

  • SQL Developer Bug: NVL() function error when debug/run stored procedure

    Version:
    SQL Developer: 1.5.3 (build main-5783)
    Oracle DB connected: Oracle9i Enterprise Edition Release 9.2.0.6.0
    Stored procedure code like this:
    procedure search(V_STATUS_IN IN CHAR(1)) is
    begin
    declare
    V_STATUS CHAR(1) := NULL;
    begin
    V_STATUS := NVL(V_STATUS_IN, '%'); -- error line
    end;
    end;
    The stored procedure runs well (I mean no oracle exception) when called through Java code (and in TOAD). But when debug/run in SQL Developer, following error at the error line:
    $Oracle.EXCEPTION_ORA_6502:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    --------------------------------------------------*/

    What parameter are you passing in? It is possible you are trying to cram a multibyte character into a singlebyte container. What are the nls settings for the database and for sqldeveloper?

  • How to Passing clob to PL/SQL pipeline function

    I have a PL/SQL stored function which takes clob as input parameter and sends the results in a pipe line.
    create or replace function GetIds(p_list clob, p_del varchar2 := ',') return ideset_t pipelined is
    I am using ojdbc14.jar (Oracle 10g driver) with oracle 9i (9.2.0.1.0).
    I want to use the following SQL Query select * from table(GetIds(clob))
    Now the question is how can I pass the clob from JDBC?
    Here is my client code
    PreparedStatement stmt = con.prepareStatement("SELECT COLUMN_VALUE FROM TABLE(GETIDS(?, ','))");
    stmt.setCharacterStream(1, new StringReader(str), str.length());
    stmt.executeQuery();
    I get the following error when I try to run the program. The same thing works fine if the chracter lenght is less than some chaaracters.
    java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
         at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:623)
         at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
         at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:420)
         at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:896)
         at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:452)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:986)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2888)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:2960)
         at Test.main(Test.java:42)
    Exception in thread "main"
    The setChracterStream works for any insert/update clob. Example when I tried the query (INSERT INTO CLOB_TEST VALUES(?)) setCharacterStream just works fine.
    Please any one can help me how to solve this.
    Thanks in advance.

    Hóla LuÃs,
    when you pick the PL/SQL function body returning a boolean, it implicitly means that TRUE means OK, while FALSE means error, always.
    In order to associate such error to a given form field, you have to go back to the page definiton / validations and specify the name of the item in the corresponding field.
    When you first create the validation rule, this value is not present even if you ask for the error message inline with the field.
    The error message text can be specified in the validation definition, if I am not wrong.
    When you need to return special error messages, including dynamic content for instance, you can use the Function Returning Error Message type, which reports an error when the string returned by the function is not null. This comes in handy when you want to display an item's code, for example, rather than generic text.
    Even in this case, you must go back to the validation and specify the name of the field if you want to see it inline.
    Hope it helps,
    Flavio

  • Local function calling remote function - error

    Dear All
    i have following remote function wich return some value from both methods ie.
    1) select func1(variable, varialbe) from dual@remoteDB; working
    2) select func1(variable, varialbe) from dual; -- by making a synonym at local
    Now i create a local function funclocal calling remote functino i.e. func1 in this example as:
    CREATE OR REPLACE FUNCTION funclocal(locc varchar2, artnoo number)
    RETURN NUMBER IS
    query_str VARCHAR2(1000);
    STKQTYY NUMBER;
    artno number(10);
    loc varchar2(80);
    BEGIN
    artno := artnoo;
    loc := locc;
    query_str := 'select func1(loc, artno) from dual ';
    EXECUTE IMMEDIATE query_str
    INTO STKQTYY;
    RETURN STKQTYY;
    END;
    compiled successfully.
    But when i run as:
    SQL> select funclocal('abc', 469183) from dual;
    select funclocal('@st3', 469183) from dual
    ERROR at line 1:
    ORA-00904: "ARTNO": invalid identifier
    ORA-06512: at "funclocal", line 11
    Please guide me.
    Regards
    Saeed

    EXECUTE IMMEDIATE query_strAs Andreas states: Why are you using dynamic sql?
    From what I see all you need is sth like
    create or replace function funclocal (locc varchar2, artnoo number)
       return number
    is
    begin
       return func1 (locc, artnoo);
    end funclocal ;
    /even the whole concept of a »local« function seems suspicious. Why do you need that one?

  • Function error! pls help.

    Here is the code:
    CREATE OR REPLACE FUNCTION id_is_good
    (i_student_id IN NUMBER)
    RETURN BOOLEAN
    AS
    v_id_cnt NUMBER;
    BEGIN
    SELECT COUNT(*)
    INTO v_id_cnt
    FROM student
    WHERE student_id = i_student_id;
    RETURN 1 = v_id_cnt;
    EXCEPTION
    WHEN OTHERS
    THEN
    RETURN FALSE;
    END id_is_good;
    Error report:
    ORA-06550: line 5, column 20:
    PL/SQL: ORA-00904: "I_STUDENT_ID": invalid identifier
    ORA-06550: line 2, column 1:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 6, column 1:
    PLS-00372: In a procedure, RETURN statement cannot contain an expression
    ORA-06550: line 6, column 1:
    PL/SQL: Statement ignored
    ORA-06550: line 10, column 1:
    PLS-00372: In a procedure, RETURN statement cannot contain an expression
    ORA-06550: line 10, column 1:
    PL/SQL: Statement ignored
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    This function run troubleless however it can not run troubleless in my computer, I have database though, I mean my database is ok, and i use sql developer but i dont understand why this code cant run good?? pls help me.
    thanks

    RETURN BOOLEANPerhaps you should read Oracle Doc about returning boolean value in SQL.
    Check the following link ->
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:6263249199595
    Your solution might be something like this if you want to return boolean ->
    CREATE OR REPLACE FUNCTION id_is_good(i_student_id IN NUMBER)
    RETURN BOOLEAN
    IS
      v_id_cnt NUMBER;
    BEGIN
      SELECT COUNT(*)
      INTO v_id_cnt
      FROM student
      WHERE student_id = i_student_id;
      IF v_id_cnt > 0 THEN
         RETURN TRUE;
      ELSE
        RETURN FALSE;
      END IF;
    EXCEPTION
    WHEN OTHERS THEN
      RETURN FALSE;
    END id_is_good;Or, if you want to return the value then ->
    CREATE OR REPLACE FUNCTION id_is_good(i_student_id IN NUMBER)
    RETURN NUMBER
    IS
      v_id_cnt NUMBER;
    BEGIN
      SELECT COUNT(*)
      INTO v_id_cnt
      FROM student
      WHERE student_id = i_student_id;
      RETURN v_id_cnt;
    EXCEPTION
    WHEN OTHERS THEN
      RETURN 0;
    END id_is_good;Hope this will help.
    Regards.
    Satyaki De.

  • Function error:  Too many records

    I have writing a function that needs to return the total count of a sql statement. It will divide two calculated columns to get an average. I have two versions. Version 1 compiled successfully and I am trying to either run it in Reports or in the database and call it. I get an error stating that the function returns too many records. I understand that is a rule for stored functions but how can I modify the code to get it return one value for each time it is called?
    Here is the main calculation. SUM(date1-date2) / (date1-date2) = Avg of Days
    version1:
    create or replace FUNCTION CALC_OVER_AGE
    RETURN NUMBER IS
    days_between NUMBER;
    days_over NUMBER;
    begin
    select (determination_dt - Filed_dt), SUM(determination_dt - Filed_dt) into days_between, days_over
    from w_all_cases_mv
    where (determination_dt - Filed_dt) > 60
    and ;
    return (days_between/days_over);
    END CALC_OVER_AGE;
    version2:
    CREATE OR REPLACE FUNCTION CALC_OVER_AGE (pCaseType VARCHAR2)
    RETURN PLS_INTEGER IS
    v_days_between W_ALL_CASES_MV.DAYS_BETWEEN%TYPE;
    v_total NUMBER;
    days_over NUMBER;
    i PLS_INTEGER;
    BEGIN
    SELECT COUNT(*)
    INTO i
    FROM tab
    WHERE case_type_cd = pCaseType
    AND determination_dt - Filed_dt > 60;
    IF i <> 0 THEN
    select SUM(determination_dt-Filed_dt), days_between
    into v_total, v_days_between
    from tab
    where determination_dt - Filed_dt > 60;
    RETURN v_total/v_days_between;
    ELSE
    RETURN 0;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    RETURN 0;
    END CALC_OVER_AGE;

    Table Structure:
    WB_CASE_NR NUMBER(10)
    RESPONDENT_TYPE_CD VARCHAR2(10)
    INV_LOCAL_CASE_NR VARCHAR2(14)
    CASE_TYPE_CD VARCHAR2(10)
    FILED_DT DATE
    FINAL_DTRMNTN_DT DATE
    REPORTING_NR VARCHAR2(7)
    INVESTIGATOR_NAME VARCHAR2(22)
    OSHA_CD VARCHAR2(5)
    FEDERAL_STATE VARCHAR2(1)
    RESPONDENT_NM VARCHAR2(100)
    DAYS_BETWEEN NUMBER
    LAST_NM VARCHAR2(20)
    FIRST_NM VARCHAR2(20)
    DETERMINATION_DT DATE
    DETERMINATION_TYPE_CD VARCHAR2(2)
    FINAL_IND_CD VARCHAR2(1)
    DESCRIPTION VARCHAR2(400)
    DETERMINATION_ID NUMBER(10)
    ALLEGATION_CD VARCHAR2(1)
    ALGDESCRIPTION VARCHAR2(50)
    Output is for Reports, I am trying to get the last calculation, which is the Average Days. The reports is grouped on Case Types and has several bucket counts for each like this.
    Case Type Count All Completed Pending Over Age Avg Days
    A 5 3 4 2 15
    Z 10 7 6 3 30
    4 8 3 5 4 22
    To get the Avg Days, the Over Age calculation is used as well as the Days Between (Determination_Dt - Filed_Dt). That is the (date1-date2) example that I gave in my first post. So the calcuation would be the SUM(Days_Between) / Days_Between.

  • Query of queries disallows SQL right() function

    We're attempting to do a query of queries using the SQL
    right() function like this:
    select *
    from getresults
    where right([key],charindex('\',reverse([key]),1)-1) not in
    (#quotedvaluelist(getexcluded.file_name)#)
    We've even replaced that where clause with a much more simple
    where right([key])='m'
    just to make sure that it wasn't the nesting functions that
    were causing the problem.
    In either case, we get the error:
    Query of Queries syntax error.
    Encountered "right" at line 0, column 0. Incorrect
    conditional expression,
    Expected one of [like|null|between|in|comparison] condition,
    What SQL functions are disallowed from query of queries?
    Thanks,
    Kris

    Nasty stuff huh. Just happened to discover myself today that
    Left doesn't work. I'd suspect that Aggregate functions are the
    ONLY ones that will work. It would have been nice if they'd at
    least allowed CF vs DB functions in their own "database" language.
    BTW, also discovered that Count() returns Null rather than 0
    when there aren't any per your WHERE clause.

  • Replace() function doesn't work in Application Designer?

    I'm using PeopleSoft Application Designer 8.51. I'm trying to do a simple Replace function so I can escape single quotes rather than allow them to blow up the sql query.
    &deptid = Replace(&deptid, "'", "''");
    App Designer chokes when I hit Save: "Invalid function parameter type. (2,19)"
    According to the docs I'm using this correctly: http://docs.oracle.com/cd/E26239_01/pt851h3/eng/psbooks/tace/book.htm?File=tace/htm/tace14.htm#H4095
    Even if I try to execute the example right out of the documentation, I get the same error: REPLACE("StringFun", "Fun", "Number");
    Is this a bug in app designer? REPLACE is a super common thing, it's not something obscure. How can this not work?
    Thanks in advance.

    I figured this out. “Replace” is a strange duck function that relies on offsets. “Substitute” is the magic I needed, works just like I was expecting Replace to work. The documentation I was reading on Replace was for “ PeopleSoft Analytic Calculation Engine” rather than peoplecode. I’ll pay closer attention to that next time. Maybe this will help someone else...

Maybe you are looking for

  • Personal File Sharing with Fast User Switiching

    I have 2 users set up on the iBook. I want file sharing turned on for only one of the users and off for the other. Both are logged in. Any way to do this? It appears that personal file sharing is either on or off for all users.

  • After The updating of IOS I can't find my hotspot even after the latest update IOS 7.0.4 ,I need help please!

    After The updating for IOS I can't find my hotspot even after the latest update IOS 7.0.4 ! I can't use my IPad as a modem any more again! please I need some one to tell me how can I return my hotspot option?

  • Open Directory / Active Directory SSH access

    I have recently bound all of our web and database servers on our active directory and open directory realms. I am able to augment the AD records for my account and the accounts of the other admins, give them NFS home directories and all is great. We

  • New Payment process in R12, MICR font dropped by PREPROCESS

    Hi, With the new way of doing Payments in R12, meaning can not use the bursting engine and at the same time CUPS printers, I can't get the MICR font to be on the output .ps file after it goes through the preprocess command of the pasta config file. A

  • Elementary configuration on rv082

    Hey Guys, I am setting up a SBS 2011 Essentials sever using a rv082 router. I have a decent understanding of how everything is suppose to work, but execution has been sloppy. My aim is to set up a central storage location, back up services, remote ac