1

I have the following Function which I have compiled in SQL Developer without error on an Oracle 11gR2 DB. It's mostly just a test function which will be built upon later on but its purpose is to take in a text value and a category value where text might be Hello and category is French and the result should be Bonjour.

create or replace FUNCTION testTranslate
    (
      originaltext   IN VARCHAR2,
      fineoscategory IN VARCHAR2 DEFAULT NULL)
    RETURN VARCHAR2
  AS
    translatedttext VARCHAR2(255) := '';
  BEGIN
    SELECT distinct tti.translatedtex
    INTO translatedttext
    FROM toctranslationitem tti,
      todomaininstance tdi
    WHERE tti.translationty   = fineoscategory
    AND tti.originaltext    = originaltext;
    RETURN translatedttext;
  END;

I've never used SQL Developer before and I'm just getting to grips with creating functions so I'm not entirely sure how to run this.

I've tried the following:

testTranslate('Hello', 'French');

execute testTranslate('Hello', 'French');

Begin
    testTranslate('Hello', 'French');
end;

The first two give me Error 900 invalid SQL Statement and the third one gives me error 6550 testTranslate is not a procedure or is undefined

When I try to debug it in SQL developer I get a separate problem. The script seems to run but I get error message 1422 exact fetch returns more than the requested number of rows. The select statement within the function when run by itself without the distinct after the select returns quite a few values but with the distinct it just returns the one so not sure what this is giving out about.

Any pointers ?

2 Answers 2

1

In Oracle the functions executes with the select keyword. So try to execute the function like this:-

SELECT testTranslate('Decision', 'Text') FROM DUAL;

May be this can help you.

Sign up to request clarification or add additional context in comments.

1 Comment

Both correct answers but you got there 1 min earlier :).
1

Try as

SELECT testTranslate ('Hello', 'French') FROM DUAL;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.