“%Type"是什么?在Oracle sql中是什么意思? [英] What does "%Type" mean in Oracle sql?
问题描述
我第一次接触Oracle和TOAD(我知道SSMS).我在更新过程中的输入参数旁边遇到了这个%Type",我不知道它是什么或意味着什么.我在Google上找到了与%Rowtype"相关的链接.是同一件事还是完全不同?
I'm getting my first experience with Oracle and TOAD (I know SSMS). I came across this "%Type" next to an input parameter in an update procedure and I have no idea what it is or what it means. I found links on Google related to "%Rowtype". Is the same thing or something entirely different?
如果该内容含糊,我深表歉意.一如既往,感谢您的帮助.
If this is vague, I apologize. As always, thanks for the help.
推荐答案
Oracle (and PostgreSQL) have:
- %TYPE
- %ROWTYPE
%TYPE
用于声明与现有表中列的数据类型有关的变量:
%TYPE
is used to declare variables with relation to the data type of a column in an existing table:
DECLARE v_id ORDERS.ORDER_ID%TYPE
这样做的好处是,如果数据类型更改,则变量数据类型保持同步.
The benefit here is that if the data type changes, the variable data type stays in sync.
参考: http://download. oracle.com/docs/cd/B19306_01/appdev.102/b14261/fundamentals.htm#i6080
在游标中用于声明单个变量可以包含游标或表的结果集中的一条记录,而无需指定单个变量(及其数据类型).例如:
This is used in cursors to declare a single variable to contain a single record from the resultset of a cursor or table without needing to specify individual variables (and their data types). Ex:
DECLARE
CURSOR c1 IS
SELECT last_name, salary, hire_date, job_id
FROM employees
WHERE employee_id = 120;
-- declare record variable that represents a row fetched from the employees table
employee_rec c1%ROWTYPE;
BEGIN
-- open the explicit cursor and use it to fetch data into employee_rec
OPEN c1;
FETCH c1 INTO employee_rec;
DBMS_OUTPUT.PUT_LINE('Employee name: ' || employee_rec.last_name);
END;
/
这篇关于“%Type"是什么?在Oracle sql中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!