易截截图软件、单文件、免安装、纯绿色、仅160KB

oracle 多表删除 同时删除多表中关联数据

oracle 多表删除 同时删除多表中关联数据
2009-04-27 14:40
1、从数据表t1中把那些id值在数据表t2里有匹配的记录全删除掉
DELETE t1 from t1,t2 WHERE t1.id=t2.id    或DELETE from t1 USING t1,t2 WHERE t1.id=t2.id
2、从数据表t1里在数据表t2里没有匹配的记录查找出来并删除掉
DELETE t1 from t1 LEFT JOIN T2 ON t1.id=t2.id WHERE t2.id IS NULL 或
DELETE from t1,USING t1 LEFT JOIN T2 ON t1.id=t2.id WHERE t2.id IS NULL
3、从两个表中找出相同记录的数据并把两个表中的数据都删除掉
DELETE t1,t2 from t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t1.id=25
注意此处的delete t1,t2 from 中的t1,t2不能是别名
如:delete t1,t2 from table_name as t1 left join table2_name as t2 on t1.id=t2.id where table_name.id=25 在数据里面执行是错误的(MYSQL 版本不小于5.0在5.0中是可以的)
上述语句改写成
delete table_name,table2_name from table_name as t1 left join table2_name as t2 on t1.id=t2.id where table_name.id=25 在数据里面执行是错误的(MYSQL 版本小于5.0在5.0中是可以的)
多表连接查询很相似,不详加说明了


相关文档:

启用oracle的archive模式

经验:
alter system set log_archive_dest=’D:\oracle\archivelog’ scope=spfile;
alter system set log_archive_start=true scope=spfile;
之后,
create pfile from spfile
可验证加上没
一、查看数据库运行模式 
可以用超级用户(INTERNAL)在SQLPLUS中使用命令ARCHIVE LOG LIST查看 
......

oracle 存储过程

1.创建过程
   与其它的数据库系统一样,Oracle的存储过程是用PL/SQL语言编写的能完成一定处理功能的存储在数据库字典中的程序。
  语法:
  create [or replace] procedure procedure_name
  [ (argment [ { in| in out }] type,
  argment [ { in | out | in out } ] type
  { is | as }
  <类型 ......

Oracle学习笔记:linux下启停Oracle


1. linux下启动oracle
su - oracle
sqlplus /nolog
conn /as sysdba
startup
exit
lsnrctl start
exit
2. linux下关闭oracle
su - oracle
sqlplus /nolog
conn /as sysdba
shutdown immediate
exit
lsnrctl stop
exit
3、启动监听器
oracle@suse92:~> lsnrctl start
4、停止监听器
oracle@suse92:~ ......

在Oracle 中查询某个字段存在于哪几个表 (转)

如果查询整库的话得以DBA权限查询数据字典dba_tab_columns
非DBA用户只能查看自己有读取权限的表
可以这样写查询
select owner, table_name
from dba_tab_columns
where lower(column_name)='firstname';
查询出哪些表包含firstname字段以及这些表属于哪个用户
注:dba_tab_columns是一个属于SYS用户的一个View ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号