Transfer:
The meaning of %type in the oracle stored procedure
Example:
CREATE OR REPLACE procedure getDeptById ( v_deptno in dept.deptno%type ) is v_dname dept.dname%type; v_loc dept.loc%type; begin select dname,loc into v_dname,v_loc from dept where deptno = v_deptno; dbms_output.put_line(v_dname||‘***‘||v_loc); end;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11< /li>
- 12
li>
v_deptno is a defined variable, dept is a table in the database, there is a deptno field in the table, and then% type is the data type of deptno.
The popular understanding is to let the type of the variable v_deptno match the type of the table field in the database, so that you don’t have to worry about the problem of type mismatch.
There are two advantages of using %type:
- You don’t need to know the number of columns and data types in the referenced database.
- The number of columns and data types in the referenced database can be changed in real time.
2018-11-07 11:43:56 lizhi_ma Reading number 1361More
Classification column: Database
< p>
Copyright notice: This article is the original article of the blogger, and it follows the CC 4.0 BY-SA copyright agreement. Please attach the original source for reprinting Link and this statement.
Link to this article: https://blog.csdn.net/qq_31279347/article/details/83820838
Example:
CREATE OR REPLACE procedure getDeptById ( v_deptno in dept.deptno%type ) is v_dname dept.dname%type; v_loc dept.loc%type; begin select dname,loc into v_dname,v_loc from dept where deptno = v_deptno; dbms_output.put_line(v_dname||‘***‘||v_loc); end;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11< /li>
- 12
li>
v_deptno is a defined variable, dept is a table in the database, there is a deptno field in the table, and then% type is the data type of deptno.
The popular understanding is to let the type of the variable v_deptno match the type of the table field in the database, so that you don’t have to worry about the problem of type mismatch.
There are two advantages of using %type:
- You don’t need to know the number of columns and data types in the referenced database.
- The number of columns and data types in the referenced database can be changed in real time.