匿名sql

declare

TYPE VARCHAR2_ARRAY IS TABLE OF VARCHAR2(100);

p_product_codes VARCHAR2_ARRAY;

p_date varchar2(50):=‘2016-07-13‘;

v_product_code       varchar2(50);

v_product_codes      varchar2(1000);

v_techinalproduct_codes    varchar2(1000);

v_date       varchar2(50);

v_column     varchar2(3000);

v_sql        varchar2(5000);

v_insert     varchar2(6000);

v_plans      varchar2(3000);

v_delete     varchar2(5000);

v_sql_delete varchar2(5000);

cursor curdeleteproduct(v_product_code varchar2) is

select ‘ FROM CHANNEL_AUTHORIZE A‘ as from_name,

‘ WHERE A.ID_MARKETPRODUCT_INFO =‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select

‘ FROM PACKAGE_DUTY_ATTR A‘ as from_name,

‘ WHERE A.ID_PACKAGE_INFO IN (SELECT B.ID_PACKAGE_INFO FROM PACKAGE_INFO B WHERE  B.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘)‘  as where_name

from dual

union all

select

‘ FROM PACKAGE_PLAN_DUTY_REL A‘ as from_name,

‘ WHERE A.ID_PACKAGE_INFO IN (SELECT B.ID_PACKAGE_INFO FROM PACKAGE_INFO B WHERE  B.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘)‘  as where_name

from dual

union all

select  ‘ FROM PACKAGE_INFO A‘ as from_name,

‘ WHERE A.ID_MARKETPRODUCT_INFO =‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select  ‘ FROM MARKETPRODUCT_DEPARTMENT A‘ as from_name,

‘ WHERE A.ID_MARKETPRODUCT_INFO =‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select  ‘ FROM MP_ASSISTANCE_SERVICE A‘ as from_name,

‘ WHERE A.ID_MARKETPRODUCT_INFO =‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select  ‘ FROM MARKETPRODUCT_RULE_PARAM A‘ as from_name,

‘ WHERE A.ID_MARKETPRODUCT_INFO =‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select  ‘ FROM MARKETPRODUCT_PLAN_DUTY_REL A‘ as from_name,

‘ WHERE A.ID_MARKETPRODUCT_INFO =‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select  ‘ FROM MARKETPRODUCT_DUTY_ATTR A‘ as from_name,

‘ WHERE A.ID_MARKETPRODUCT_INFO =‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select  ‘ FROM MARKETPRODUCT_INFO A‘ as from_name,

‘ WHERE A.ID_MARKETPRODUCT_INFO =‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

;

cursor cur(v_product_code varchar2,v_plan varchar2) is

select ‘PRODDATA‘ as owner,

‘MARKETPRODUCT_INFO‘  as table_name,

‘ FROM MARKETPRODUCT_INFO A‘ as from_name,

‘ WHERE  A.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘CHANNEL_AUTHORIZE‘  as table_name,

‘ FROM CHANNEL_AUTHORIZE A‘ as from_name,

‘ WHERE  A.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘MARKETPRODUCT_DUTY_ATTR‘  as table_name,

‘ FROM MARKETPRODUCT_DUTY_ATTR A‘ as from_name,

‘ WHERE  A.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘MARKETPRODUCT_PLAN_DUTY_REL‘  as table_name,

‘ FROM MARKETPRODUCT_PLAN_DUTY_REL A‘ as from_name,

‘ WHERE  A.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘MARKETPRODUCT_RULE_PARAM‘  as table_name,

‘ FROM MARKETPRODUCT_RULE_PARAM A‘ as from_name,

‘ WHERE  A.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘MARKETPRODUCT_DEPARTMENT‘  as table_name,

‘ FROM MARKETPRODUCT_DEPARTMENT A‘ as from_name,

‘ WHERE  A.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘MP_ASSISTANCE_SERVICE‘  as table_name,

‘ FROM MP_ASSISTANCE_SERVICE A‘ as from_name,

‘ WHERE  A.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘PACKAGE_INFO‘  as table_name,

‘ FROM PACKAGE_INFO A‘ as from_name,

‘ WHERE  A.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘PACKAGE_PLAN_DUTY_REL‘  as table_name,

‘ FROM PACKAGE_PLAN_DUTY_REL A,PACKAGE_INFO B‘ as from_name,

‘ WHERE A.ID_PACKAGE_INFO=B.ID_PACKAGE_INFO AND B.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘PACKAGE_DUTY_ATTR‘  as table_name,

‘ FROM PACKAGE_DUTY_ATTR A,PACKAGE_INFO B‘ as from_name,

‘ WHERE A.ID_PACKAGE_INFO=B.ID_PACKAGE_INFO AND B.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual

union all

select ‘PRODDATA‘ as owner,

‘PROD_FORMULA_INFO‘  as table_name,

‘ FROM PROD_FORMULA_INFO A,PACKAGE_PLAN_DUTY_REL B,PACKAGE_INFO C‘ as from_name,

‘ WHERE A.ID_PROD_FORMULA_INFO=B.FORMULA_ID AND B.ID_PACKAGE_INFO=C.ID_PACKAGE_INFO AND C.ID_MARKETPRODUCT_INFO=‘‘‘||v_product_code||‘‘‘‘  as where_name

from dual;

begin

p_product_codes := VARCHAR2_ARRAY(‘2F4104D4B6293BD0E054002128F3CB8E‘);

v_date :=p_date;

delete from sqltext;--这个需要创建的表

commit;

--生成要删除的数据

for j in 1..p_product_codes.count    loop

dbms_output.put_line(p_product_codes(j));

begin

execute immediate ‘alter session set NLS_DATE_FORMAT =‘‘YYYY-MM-DD HH24:MI:SS‘‘‘;

v_product_code := upper(p_product_codes(j));

for kf in curdeleteproduct(v_product_code) loop

v_delete:=‘delete  ‘|| kf.from_name ||kf.where_name||‘;‘;

v_delete:=REPLACE(v_delete,‘‘‘‘,‘‘‘‘‘‘);

v_sql_delete := ‘insert into sqltext values (‘‘‘ || v_delete || ‘‘‘,SYSTIMESTAMP)‘;

execute immediate v_sql_delete; ---执行动态sql的函数

end loop ;

end;

end loop;

for j in 1..p_product_codes.count    loop

v_product_codes:=v_product_codes||‘,‘‘‘||p_product_codes(j)||‘‘‘‘ ;

end loop;

v_product_codes:=substr(v_product_codes,2);

commit;

for j in 1..p_product_codes.count    loop

dbms_output.put_line(p_product_codes(j));

begin

execute immediate ‘alter session set NLS_DATE_FORMAT =‘‘YYYY-MM-DD HH24:MI:SS‘‘‘;

v_product_code := upper(p_product_codes(j));

for k in cur(v_product_code,v_plans) loop

--组装列

v_column :=‘‘;

for i in (select case

when t.DATA_TYPE = ‘VARCHAR2‘ then

‘‘‘‘‘‘‘||A.‘ || t.COLUMN_NAME || ‘||‘‘‘‘‘‘‘

when t.DATA_TYPE = ‘CHAR‘ then

‘‘‘‘‘‘‘||A.‘ || t.COLUMN_NAME || ‘||‘‘‘‘‘‘‘

when t.DATA_TYPE = ‘NUMBER‘ then

‘‘‘||A.‘||t.COLUMN_NAME||‘||‘‘‘

when t.DATA_TYPE = ‘DATE‘ then

‘to_date(‘‘‘‘‘‘||to_char(A.‘||t.COLUMN_NAME||‘,‘‘yyyy-mm-dd hh24:mi:ss‘‘)||‘‘‘‘‘‘,‘‘‘‘yyyy-mm-dd hh24:mi:ss‘‘‘‘)‘

when t.DATA_TYPE = ‘CLOB‘ then

‘‘‘‘‘‘‘||to_char(A.‘||t.COLUMN_NAME||‘)||‘‘‘‘‘‘‘

else

‘‘ || t.TABLE_NAME || ‘‘

end as column_name

from dba_tab_columns t

where owner = k.owner

and table_name = k.table_name

order by column_id) loop

v_column := v_column || ‘,‘ || i.column_name;

end loop;

v_insert := ‘‘‘insert into ‘ || k.owner || ‘.‘ || k.table_name ||

‘ values(‘ || substr(v_column, 2) || ‘);‘‘‘||‘,SYSTIMESTAMP‘;

--根据表和表对应的where条件查询到此产品对应的数据,然后批量插入数据到表sqltext中

v_sql := ‘insert into sqltext select  ‘ || v_insert || k.from_name||k.where_name;

execute immediate v_sql;

update sqltext set text=replace(text,‘,,‘,‘,null,‘) ;

update sqltext set text=replace(text,‘,,‘,‘,null,‘) ;

update sqltext set text=replace(text,‘,)‘,‘,null)‘) ;

commit;

end loop;

end;

end loop;

end;

/

时间: 2024-10-11 11:59:50

匿名sql的相关文章

【数据库】基础知识总结

数据库完整性 为了维护数据库完整性DBMS需要提供: 1. 提供定义完整性约束条件的机制 2. 提供完整性检查方法:一般在INSERT UPDATE DELETE语句执行后开始检查或者在事物提交之前进行检查 3. 违约处理机制:比如拒绝,级联或者其他操作 实体完整性 用PRIMARY KEY进行定义,对于单属性,实体完整性可以定义为列级约束也可以定义为表级约束:对于多个属性构成的码,只能定义为表级约束. 例如: 定义为列级约束(列级主码) CREATE TABLE S( Sno CHAR(9)

PL/SQL语法简介(匿名PL/SQL块)

PL/SQL PL/SQL是Oracle在关系数据库结构化查询语言SQL基础上扩展得到的一种过程化查询语言. SQL与编程语言之间的不同在于,SQL没有变量,SQL没有流程控制(分支,循环).而PL/SQL是结构化的和过程化的结合体,而且最为重要的是,在用户执行多条SQL语句时,每条SQL语句都是逐一的发送给数据库,而PL/SQL可以一次性将多条SQL语句一起发送给数据库,减少网络流量 SQL执行 PL/SQL执行 匿名Pl/SQL块 – 动态构造,只能执行一次 一次性完成,没有名字 存储过程,

sql、linq和lambda查询语句比较inner join和group by组合使用及匿名类型的处理

使用EF自己做的小功能需要遇到inner join和group by组合使用及匿名类型的处理,搜了很多,基本不能满足自己的需要,所以总结了也实现了就自己写出来,已备查看及伙伴查询参考(一般的语句查询就不说了,网络搜索很多) 语句查询的背景(要不直接看语句故估计也够呛):主要想实现类似QQ相册的功能展示,页面展示所有相册列表,主要包括:相册里面的相册个数,相册中的某一个张照片作为相册的默认背景图,相册名,相册描述,删除和编辑功能 sql server:(这个就比较简单) select count(

.net 根据匿名类生成实体类,根据datatable生成实体类,根据sql生成实体类

在开发中可能会遇到这几种情况 1.EF或LINQ查询出来的匿名对象在其它地方调用不方便,又懒的手动建实体类 2.通过datatable反射实体需要先建一个类 ,头痛 3.通过SQL语句返回的实体也需要先建一个类 ,头痛 4.如果通过代码生成器要写模版,需要安装或者不想生成一堆不用的类 为了解决上面的不便之处,我封装了一个实体生成类,可以扔到程序里面任意调用 封装类: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

SQL Server 2005中设置Reporting Services发布web报表的匿名访问

原文:SQL Server 2005中设置Reporting Services发布web报表的匿名访问 一位朋友提出个问题:集成到SQL Server 2005中的Reporting Services已经将报表模板发布到IIS服务器,客户端通过浏览器访问时,默认会弹出Windows集成身份验证的对话框.如果在IIS配置里面把允许匿名(IUSR_**)访问的选项勾选,客户端再次访问的时候,会提示IUSR_** 访问权限不足.   对于这个问题,除了要设置IIS允许匿名访问外,还需要设置Report

Oracle_PL/SQL(1) 匿名块

1. PL/SQL 简介PL/SQL是一种比较复杂的程序设计语言, 用于从各种环境中访问Oracle数据库.为什么使用PL/SQL?Orade是一种关系型数据库, 用来访问关系型数据库的语言是 “结构化査询语言”SQL.SQL是一种第四代语言,只描述做什么,不描述如何做.一代语言:01二代语言:汇编三代语言:过程(条件判断.循环)四代语言:sql DELETE FROM emp where major='MANAGER';第四代语言相对简单,提供了较少的命令,它将用户与底层的基本数据结构和算法隔

mysql sql常用语句大全

SQL执行一次INSERT INTO查询,插入多行记录 insert into test.person(number,name,birthday) values(5,'cxx5',now()),(6,'cxx6',now()),(7,'cxx7',now()); 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 备份数据的 device USE mas

SQL(高级查询)

1.子查询在WHERE子句中 在SELECT查询中,在WHERE查询条件中的限制条件不是一个确定的值,而是来自于另外一个查询的结果 为了给查询提供数据而首先执行的查询语句叫做子查询 子查询嵌入在其它SQL语句中的SELECT语句,大部分出现在WHERE子句中 子查询嵌入的语句称作主查询或父查询 主查询可以是SELECT语句,也可以是其它类型的语句比如DML或DDL语句 根据返回结果的不同,子查询可分为单行子查询.多行子查询及多列子查询2.子查询在WHERE子句中(续1) 如果子查询返回多行,主查

linq to sql (Group By/Having/Count/Sum/Min/Max/Avg操作符) (转帖)

http://wenku.baidu.com/link?url=2RsCun4Mum1SLbh-LHYZpTmGFMiEukrWAoJGKGpkiHKHeafJcx2y-HVttNMb1BqJpNdwaOpCflaajFY6k36IoCH_D82bk2ccu468uzDRXvG 基于LINQ+to+Entity数据访问技术的应用研究 Group By/Having操作符 适用场景:分组数据,为我们查找数据缩小范围. 说明:分配并返回对传入参数进行分组操作后的可枚举对象.分组:延迟 1.简单形式: