变量的声明Symfoware
1.常用类型变量:
binary_integer :整数,主要用来计数而不是用来表示字段类型,(提高效率)
number;数字类型
char:定长字符串;
date:日期;
long:长字符串,最长2G;
boolean 布尔类型,可以取值true,false,null值;
2.使用%type属性
3.复合变量的声明:
Table变量类型(相当于java的数组) 例子:type type_table_emp_empno is table of emp.empno%type index by binary_integer;
Record变量类型:(相当于java的类) 例子:type type_record_dept is record(
deptno dept.deptno%type,
dname dept.dname%type,
loc dept.loc%type
);
v_temp type_record_dept;
4.constant 数据类型标识符 声明不可变的变量 类似于编程语言中的final
5.数组的声明
(1)游标用
type row_type is record(
prog_num varchar2x,
information varchar2x,
container_num varchar2x
);
dataTemp row_type;
循环游标
fetch data1 into dataTemp;
loop
DBMS_OUTPUT.PUT_LINE('1 = '|| dataTemp.information);
DBMS_OUTPUT.PUT_LINE('2 = '|| dataTemp.container_num);
fetch data1 into dataTemp;
exit when data1%notfound;
end loop;
(2)可用t_com_data.first||t_com_data.end方法
TYPE type_t_com_temp is record(
amount T_COM.受注%type,
invoice_no T_COM.出荷NO%type,
drow_no T_COM.首配%type,
delivery_term T_COM.日期%type
);
TYPE t_com_temp IS TABLE OF type_t_com_temp;
t_com_data t_com_temp;--对象数组
t_com_data type_t_com_temp;--对象
6.rpad函数从右边对字符串使用指定的字符进行填充
语法格式如下rpad(string,padded_length,[pad_string])
例如:
rpad('tech', 7); 将返回'tech '
rpad('tech', 2); 将返回'te'
rpad('tech', 8, '0'); 将返回'tech0000'
rpad('tech on the net', 15, 'z'); 将返回 'tech on the net'
rpad('tech on the net', 16, 'z'); 将返回 'tech on the netz'
7.NVL函数的格式如下:NVL(expr1,expr2)
含义是:如果oracle第一个参数为空那么显示第二个参数的值,如果第一个参数的值不为空,则显示第一个参数本来的值。
8.1)substr函数格式 (俗称:字符截取函数)
格式1: substr(string string, int a, int b);
1、string 需要截取的字符串
2、a 截取字符串的开始位置(注:当a等于0或1时,都是从第一位开始截取)
3、b 要截取的字符串的长度
格式2:substr(string string, int a) ;
1、string 需要截取的字符串
2、a 可以理解为从第a个字符开始截取后面所有的字符串。(包括第a个)
9.lpad在左边填充
语法格式如下:SQL> select lpad('abcde',10,'x') from dual;
LPAD('ABCDE',10,'X')
--------------------
xxxxxabcde
lpad( string, padded_length, [ pad_string ] )
string
准备被填充的字符串;
padded_length
填充之后的字符串长度,也就是该函数返回的字符串长度,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;
pad_string
填充字符串,是个可选参数,这个字符串是要粘贴到string的左边,如果这个参数未写,lpad函数将会在string的左边粘贴空格。
Rpad()函数的用法: 右边填充
10.1)instr()函数的格式 (俗称:字符查找函数)查找字符在字符串中的位置
格式一:instr( st