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;
/
set serveroutput on
DECLARE
var1 table_a.id%TYPE;
var2 table_a.value%TYPE;
var3_row table_a%ROWTYPE;
BEGIN
SELECT id,value
INTO var1, var2
FROM table_a
WHERE id= 8 AND ROWNUM<=1;
SELECT id+100,value INTO var3_row from table_A where rownum=1;
INSERT INTO table_a VALUES var3_row;
dbms_output.put_line('this is a test');
dbms_output.put_line(var1);
dbms_output.put_line(var2);
NULL; -- do something useful here
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL; -- do something appropriate here
WHEN TOO_MANY_ROWS THEN
NULL; -- do something appropriate here
END;
/
4条答案
按热度按时间kknvjkwl1#
Oracle(和PostgreSQL)具有:
%类型
%TYPE
用于声明与现有表中列的数据类型相关的变量:这样做的好处是,如果数据类型发生变化,变量数据类型将保持同步。
参考:www.example.comhttp://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(及其数据类型)。例如:
2w2cym1i2#
除了OMG Ponies指出的用途外,
%TYPE
还用于继承先前声明的变量所使用的相同数据类型。语法为:
因此,不需要为第二个变量(即
L_num_Test
)声明数据类型。如果有人需要进一步澄清此主题,请发表评论。
参考:www.example.comhttps://docs.oracle.com/cd/B19306_01/appdev.102/b14261/fundamentals.htm#BEIIGBBF
bis0qfac3#
%类型及其用途:
1.%Type数据类型用于将变量定义为指定表的列名数据类型。
1.让我们举一个customer表的小例子,其中Customer_name数据类型为varchar 2(30)。如果您给予%类型,则指定的列或变量将采用varchar 2(30)数据类型。
1.**定义此值的下限?**vCustomerName客户.客户名称%TYPE;在上面的define语句中,Customer_Name的数据类型将分配给名为vCustomerName的变量。真实的示例:如果要创建一个简单的PL SQL块来检查从直接表. PL SQL块分配数据类型的情况:
bvuwiixz4#
一些示例