Warm tip: This article is reproduced from stackoverflow.com, please click
oracle oracle-sqldeveloper sql

Is there an easier version of this SQL script?

发布于 2020-04-16 11:55:06

I'm trying to run a script on an Oracle Database via SQL Developer. There are five columns: ID, LAST_NAME, FIRST_NAME, USERID, and SALARY. This is the code I've written to accept values and edit the USERID field with the lowercase of the 1st letter of the FIRST_NAME and the whole LAST_NAME.

INSERT INTO ACT_MY_EMPLOYEE
    VALUES (&P_ID, '&P_LAST_NAME', '&P_FIRST_NAME',
    LOWER(SUBSTR('&P_FIRST_NAME', 1, 1) ||
    SUBSTR('&P_LAST_NAME', 1, 7)), &P_SALARY);

Is there an easier version to this? Thank you!

Questioner
Viany Manuel
Viewed
38
368k 2020-02-04 14:52

You should definitely use && instead of & as single & will ask you for the value each time it is uses in your sql while double & will store substitution value (asks for value only once) and use it if same variable is used second time in the same session.

INSERT INTO ACT_MY_EMPLOYEE
    VALUES (&P_ID, '&&P_LAST_NAME', '&&P_FIRST_NAME',
    LOWER(SUBSTR('&&P_FIRST_NAME', 1, 1) ||
    SUBSTR('&&P_LAST_NAME', 1, 7)), &P_SALARY);

Cheers!!