Oracle PLS-00363: expression '' cannot be used as an assignment target
p_temp_foo
is an IN
parameter. By nature, these are read only. You could define it as an IN OUT
parameter, or an OUT
parameter.
For more info see here:
http://plsql-tutorial.com/plsql-passing-parameters-procedure-function.htm
create type. pls 00363 expression cannot be used as an assignment
By default, for every non-static function, implicitly declared self
parameter is in IN
parameter mode. It means, that it simply cannot be modified. But, it should be noted that for non-static procedures self
parameter is in IN OUT
default parameter mode.
Although it is not a good practice to allow a function to return multiple values, change value ud_mosh
property of an object and return the same value to the invoker, in this case, you can explicitly declare self
parameter of the function in IN OUT
parameter mode:
create or replace type CAR as object (
mosh_dvig number,
obiem_dvig number,
color varchar2(20),
type_form varchar2(20),
massa number,
num_peredach number,
ud_mosh number,
member function ud_mosh_dvig(self in out car) return number
);
TYPE CAR compiled
create or replace type body CAR
is
member function ud_mosh_dvig(self in out car)
return number as
begin
self.ud_mosh := self.mosh_dvig/self.massa;
return self.ud_mosh;
end ud_mosh_dvig;
end;
TYPE BODY CAR compiled
But you wont be able to use that function in SQL, because of declared formal parameter of the function in IN OUT
parameter mode - only PL/SQL
set serveroutput on;
clear screen;
declare
l_obj car;
l_obj1 car;
l_res number;
begin
l_obj := new car(1,1,'1','1',4,1,1);
l_res := l_obj.ud_mosh_dvig();
dbms_output.put_line('ud_mosh prop value: ' || l_obj.ud_mosh || chr(13)
|| 'Function returns: ' || to_char(l_res));
end;
/
anonymous block completed
ud_mosh prop value: 0.25
Function returns: 0.25
expression 'string' cannot be used as an assignment target -SQL PLUS
Your procedure has IN OUT parameter. So while calling the procedure you should supply a variable to it, so that it can hold the value that the procedure gives back. You cannot supply a value directly, as it cannot be modified by the procedure.
DECLARE
param NVARCHAR2 (20) := 'hahahahaha';
BEGIN
disemvowel (param);
END;
/
Oracle error: expression '' cannot be used as an assignment target
Since you are going to insert or update the table, you need to create the table first.
If you already have the table, please ignore this step:
create table EMPLEADO
(
CEDULA NUMBER(5),
ID_CARGO NUMBER(5),
ID_EMP NUMBER(5),
NOMBRE VARCHAR2(20),
APELLIDO VARCHAR2(20),
FECHA_NAC NUMBER(5),
FECHA_CON NUMBER(5),
SALARIO NUMBER(5)
)
Then create the stored procedure:
CREATE OR REPLACE PROCEDURE INSTERT_UPDATE_EMPLEADO(
P_CEDULA IN EMPLEADO.CEDULA%TYPE,
P_ID_CARGO IN EMPLEADO.ID_CARGO%TYPE,
P_ID_EMP IN EMPLEADO.ID_EMP%TYPE,
P_NOMBRE IN EMPLEADO.NOMBRE%TYPE,
P_APELLIDO IN EMPLEADO.APELLIDO%TYPE,
P_FECHA_NAC IN EMPLEADO.APELLIDO%TYPE,
P_FECHA_CON IN EMPLEADO.FECHA_CON%TYPE,
P_SALARIO IN EMPLEADO.SALARIO%TYPE)
IS
BEGIN
IF P_ID_EMP = 0 THEN
INSERT INTO EMPLEADO("CEDULA_EMPLEADO", "ID_CARGO", "EMPLEADO_ID", "NOMBRE", "APELLIDO", "FECHA_NAC", "FECHA_CONTRATO", "SALARIO")
VALUES (P_CEDULA, P_ID_CARGO, P_ID_EMP, P_NOMBRE, P_APELLIDO, P_FECHA_NAC, P_FECHA_CON, P_SALARIO);
ELSE
UPDATE EMPLEADO
SET NOMBRE = P_NOMBRE,
APELLIDO = P_APELLIDO,
FECHA_NAC = P_FECHA_NAC,
FECHA_CONTRATO = P_FECHA_CON,
SALARIO = P_SALARIO,
CEDULA_EMPLEADO = P_CEDULA,
ID_CARGO = P_ID_CARGO
WHERE EMPLEADO_ID = P_ID_EMP;
END IF;
COMMIT;
END;
PL/SQL expression cannot be used
pnum
is an IN
parameter; why would you set it to some other value? If you insist on doing that, make it an IN OUT
parameter which makes things complicated as you can't just call that procedure, but declare a variable that will be passed to the procedure (as you have to put that OUT
value somewhere).
Also, you don't assign a value with =
, but :=
(i.e. pnum := '100';
).
Here's an example:
SQL> create table insertnum (num varchar2(10), name varchar2(20));
Table created.
SQL> create or replace procedure insertrec (pnum in out varchar2, pname in varchar2) is
2 begin
3 if pnum = '0' then
4 pnum := '100';
5 end if;
6 insert into insertnum (num, name) values (pnum, pname);
7 end ;
8 /
Procedure created.
SQL>
SQL> declare
2 l_n varchar2(10) := '0';
3 begin
4 insertrec(l_n, 'x');
5 end;
6 /
PL/SQL procedure successfully completed.
SQL>
SQL> select * from insertnum;
NUM NAME
---------- --------------------
100 x
SQL>
However, that should be rewritten with DECODE
(or CASE
) as
SQL> create or replace procedure insertrec (pnum in varchar2, pname in varchar2) is
2 begin
3 insert into insertnum (num, name) values (decode(pnum, '0', '100', pnum), pname);
4 end ;
5 /
Procedure created.
SQL> begin
2 insertrec('20', 'y');
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> select * From insertnum;
NUM NAME
---------- --------------------
100 x
20 y
SQL>
PLS-00363 Input parameter, value assignment
You should convert IN parameter to IN OUT
PROCEDURE reset_pass (in_row IN OUT users%ROWTYPE)
Alternate method is, to take a local record object in-case you can not modify it to IN OUT.
PROCEDURE reset_pass (in_row IN users%ROWTYPE)
IS
l_random_pass varchar2(4000);
in_row_local users%ROWTYPE;
BEGIN
in_row_local := in_row;
SELECT DBMS_RANDOM.string('x',10) INTO l_random_pass FROM DUAL;
in_row_local.password := l_random_pass;
account_api.upd_users( table_row => in_row_local );
END reset_pass;
Related Topics
Sql Server Store Multiple Values in SQL Variable
Oracle SQL - Max() with Null Values
Are There Any Limits on Length of String in MySQL
Oracle - Clone Table - Structure, Data Constraints and All
Transpose/Pivot Distinct Row Attribute as Column and Group Another Attribute
How to Extract Certain Nth Character from a String in Sql
Update Statement Using Join and Group By
Updating One Column Based on The Value of Another Column
Parsing Nested Xml into SQL Table
How to Remove SQL Azure Data Sync Objects Manually
Sql: How to Get All The Distinct Characters in a Column, Across All Rows
Replace Identity Column from Int to Bigint
SQL Server - Asynchronous Query Execution
How to Display the Date as Mm/Dd/Yyyy Hh:Mm Am/Pm Using SQL Server 2008 R2
Custom Sorting in SQL Order by Clause
Ora-06502: Pl/Sql: Numeric or Value Error: Character String Buffer Too Small