Yesterday in learning oracle stored procedure, write a demo of a stored procedure, the statement is this:
CREATE OR REPLACE PROCEDURE RAISESALARY(PNAME IN VARCHAR2(20)) AS psssal TESTDELETE.TESTID%TYPE; BEGIN SELECT TESTID INTO psssal FROM TESTDELETE WHERE TESTNAME=PNAME; UPDATE TESTDELETE SET TESTID=(TESTID+10000) WHERE TESTNAME=PNAME; DBMS_OUTPUT.PUT_LINE('The original salary'||psssal||' After the raise'||(psssal+1000)); end; /
The idea is to find the number varchar type field by the table (20) Type field, change the number and types of fields. Table structure is as follows:
create table TESTDELETE ( TESTID NUMBER, TESTNAME VARCHAR2(20) )
The stored procedure calls, results appear as follows:
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options CREATE OR REPLACE PROCEDURE RAISESALARY(PNAME IN VARCHAR2(20)) 2 AS 3 psssal TESTDELETE.TESTID%TYPE; 4 BEGIN 5 SELECT TESTID INTO psssal FROM TESTDELETE WHERE TESTNAME=PNAME; UPDATE TESTDELETE SET TESTID=(TESTID+10000) WHERE TESTNAME=PNAME; DBMS_OUTPUT.PUT_LINE('The original salary'||psssal||' After the raise'||(psssal+1000)); 8 end; 9 / Warning: Procedure created with compilation errors. SET SERVEROUTPUT ON; BEGIN RAISESALARY('name2091'); COMMIT; END; SQL> 2 3 4 5 / RAISESALARY('name2091'); * ERROR at line 2: ORA-06550: line 2, column 5: PLS-00905: object TEST.RAISESALARY is invalid ORA-06550: line 2, column 5: PL/SQL: Statement ignored SQL>
Error: the stored procedure is invalid.
what? Obviously just created stored procedures ah. Then I turn to a word after you've created above, Warning: Procedure the Created with Compilation errors. Translation should be: with the process of creating a compilation error.
That created a stored procedure error, then OK, look for stored procedures and see what was wrong.
emmmm, I looked back a long time, so a few lines, life and death in the end did not see what the problem, no way, baidu, google.
Later in StackOverFlow saw this, the original link is as follows:
https://stackoverflow.com/questions/48497140/oracle-sql-stored-procedure-object-invalid
Landlord found inside such a sentence:
You can’t give a size or precision restriction for the data type of a formal parameter to a function or procedure, so NUMBER(10,0)
should just be NUMBER
;
In other words, you can not specify the size or the accuracy of the data parameters to functions and stored procedures. OK, I look back at this argument, understand, varchar2 (20) is a significant parameter specifies the type of precision to the. Varchar2 need to change this type.
Or write directly to the table name.% TYPE field is also possible (pro-test) .
After you have finished changing run as follows:
CREATE OR REPLACE PROCEDURE RAISESALARY(PNAME IN VARCHAR) 2 AS 3 psssal TESTDELETE.TESTID%TYPE; 4 BEGIN 5 SELECT TESTID INTO psssal FROM TESTDELETE WHERE TESTNAME=PNAME; UPDATE TESTDELETE SET TESTID=(TESTID+10000) WHERE TESTNAME=PNAME; DBMS_OUTPUT.PUT_LINE('The original salary'||psssal||' After the raise'||(psssal+1000)); 8 end; 9 / Procedure created. BEGIN RAISESALARY('name2091'); 3 COMMIT; 4 END; 5 / The original salary2091 After the raise3091 PL/SQL procedure successfully completed. SQL>
After we have seen no clear warning of the emergence of a Procedure created.
Running success! problem solved.