oracle 常用 sql
1. 表格数据备份复制
? 1) ?备份表格
? ? ? ?create table new_table ?as select * from old_table;
? 2) ?数据从一张表格copy至另外一张结构有改动的新表格
insert into teqm_relation_tree? ? ? ? select t.relation_id,'q','1',t.in_order,t.level_num,t.node_path,t.node_id,t.parent_id from t_tree t
? 3) 更新错误行数据
? ? ? ??update teqm_relation_tree t set t.node_name=(select n.node_name from teqm_relation_node n where n.node_id=t.node_id)
?
2. 树相关
? 1)向上追溯父节点,并将得到的结果集反转,(level 显示节点所属树的层级,用于结果反转)
?select t.* from (select t.*,level as lev" +
" ?from teqm_relation_tree t " +
"connect by prior t.parent_id = t.relation_id" +
" start with t.relation_id = '"+relationId+"') t order by t.lev desc";