剑指Offer--常用SQL语句.存储过程和函数 常用SQL语句 1.在MySQL数据库建立多对多的数据表关系 2.授权.取消授权 grant.revoke grant select, insert, update, delete on testdb.* to common_user@'%': revoke all on *.* from dba@localhost; create user guest@localhost identified by '123456': grant select…
在oracle10中写好了存储过程,代码如下: CREATE OR REPLACE Procedure Proc_Insert ( sName in varchar2, sAge in int, sExeTime in varchar2 ) is begin Insert into T_TEST(C_ID, C_NAME, C_AGE, C_INTIME, C_EXETIME) values(T_TEST_CID.nextval,sName,sAge, sysdate, to_date(sExe…
一.异常 1.处理异常 (1)除数不为0 declare b number; begin b:; exception when zero_divide then dbms_output.put_line('除数不能为0'); end; DBMS输出:除数不能为0. (2)找不到参数 declare vename ); begin ; --此处会报no date found异常 exception when no_date_found then dbms_output.put_line('未找到任…
-- 1. 使用一个变量 declare -- Local variables here v_name ); begin -- Test statements here select t.user_name into v_name from pay_mer_order t ; dbms_output.put_line(v_name); end; -- 2. 使用多个变量 declare -- Local variables here v_name ); v_trans_no ); v_app_c…
一:PL/SQL时间相关类型 PL/SQL提供两个和日期时间相关的数据类型: 日期时间(Datetime)数据类型 时间间隔类型 二:日期时间类型 datetime数据类型有: DATE TIMESTAMP TIMESTAMP WITH TIME ZONE TIMESTAMP WITH LOCAL TIME ZONE 三:时间间隔类型 INTERVAL YEAR TO MONTH INTERVAL DAY TO SECOND 四:日期时间类型 和 时间间隔类型 的可能字段 字段名称 有效日期…
select * from protype;select * from product;---笛卡尔连接查询(交叉连接)select * from protype,product;select * from protype cross join product;---标准写法---内链接查询select * from protype pt,product pd where pt.pt_id=pd.p_type;select * from protype pt inner join product…
原文参考:http://plsql-tutorial.com/ 创建语法: CREATE [OR REPLACE ] TRIGGER trigger_name {BEFORE | AFTER | INSTEAD OF } {INSERT [OR] | UPDATE [OR] | DELETE} [OF col_name] ON table_name [REFERENCING OLD AS o NEW AS n] [FOR EACH ROW] WHEN (condition) BEGIN ---…
原文参考:http://plsql-tutorial.com/ 组成: 1) 异常类型 2) 错误码 3) 错误信息 代码结构: DECLARE Declaration section BEGIN Exception section EXCEPTION WHEN ex_name1 THEN -Error handling statements WHEN ex_name2 THEN -Error handling statements WHEN Others THEN -Error handl…
一:PL/SQL集合 集合是一个有序且存有相同的类型数据的数据结构. PL/SQL提供了三种集合类型: 索引表(关联数组) 嵌套表 数组 二:索引表:一个索引表(也叫关联数组)是一组键 - 值对.每个键是唯一的,并且用于定位对应的值.键可以是整数或字符串.[其实就是 Map类型] 1)创建索引表 TYPE type_name IS TABLE OF element_type [NOT NULL] INDEX BY subscript_type; //定义索引表类型:指明值类型和键类型 table…