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!
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!!
This did it! Thank you for this. So, that's how it works. I'm probably going to use this knowledge for quite some time. Thank you again!