"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does My Oracle CONCAT Function Give an "Invalid Number of Arguments" Error?

Why Does My Oracle CONCAT Function Give an "Invalid Number of Arguments" Error?

Posted on 2025-02-10
Browse:234

Why Does My Oracle CONCAT Function Give an

Invalid Number of Arguments Error in CONCAT Function

For the given problem of formatting output in the desired format, the CONCAT function is employed. However, an error arises due to an incorrect number of arguments.

Let's analyze the code:

SELECT CONCAT(Name,"(",SUBSTR(Occupation,1,1),")") FROM OCCUPATIONS;

The CONCAT function in Oracle accepts a maximum of two arguments. It concatenates two strings, but in this case, three strings are being passed: Name, "(", and SUBSTR(Occupation,1,1). This results in the "invalid number of arguments" error.

The Solution:

To resolve this, we can use the concatenation operator (||) instead, which allows for multiple strings to be concatenated. The corrected code is:

SELECT Name || '(' || SUBSTR(Occupation,1,1) || ')' FROM OCCUPATIONS;

Additionally, remember to use single quotes (') to enclose string literals, as double quotes (") are used for identifiers in Oracle SQL.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3