PL/SQL中DBMS_SQL的使用【转】

转自http://www.blogjava.net/wxqxs/archive/2009/01/24/260626.html
http://www.itpub.net/thread-9530-1-1.html

PL/SQL中使用动态SQL编程
    在PL/SQL程序设计过程中,会遇到很多必须使用动态sql的地方,oracle系统所提供的DMBS_SQL包可以帮助你解决问题。
(一)介绍
    DBMS_SQL系统包提供了很多函数及过程,现在简要阐述其中使用频率较高的几种:
    function open_cursor:打开一个动态游标,并返回一个整型;
    procedure close_cursor(c in out integer) :关闭一个动态游标,参数为open_cursor所打开的游标;
    procedure parse(c in integer, statement in varchar2, language_flag in integer):对动态游标所提供的sql语句进行解析,参数C表示游标,statement为sql语句,language-flag为解析sql语句所用oracle版本,一般有V6,V7跟native(在不明白所连database版本时,使用native);
    procedure define_column(c in integer, position in integer, column any datatype, [column_size in integer]):定义动态游标所能得到的对应值,其中c为动态游标,positon为对应动态sql中的位置(从1开始),column为该值所对应的变量,可以为任何类型,column_size只有在column为定义长度的类型中使用如VARCHAR2,CHAR等(该过程有很多种情况,此处只对一般使用到的类型进行表述);
    function execute(c in integer):执行游标,并返回处理一个整型,代表处理结果(对insert,delete,update才有意义,而对select语句而言可以忽略);
    function fetch_rows(c in integer):对游标进行循环取数据,并返回一个整数,为0时表示已经取到游标末端;
    procedure column_value(c in integer, position in integer, value):将所取得的游标数据赋值到相应的变量,c为游标,position为位置,value则为对应的变量;
    procedure bind_variable(c in integer, name in varchar2, value):定义动态sql语句(DML)中所对应字段的值,c为游标,name为字段名称,value为字段的值;
    以上是在程序中经常使用到的几个函数及过程,其他函数及过程请参照oracle所提供定义语句dbmssql.sql

(二)一般过程

    对于一般的select操作,如果使用动态的sql语句则需要进行以下几个步骤:
    open cursor--->parse--->define column--->excute--->fetch rows--->close cursor;
    而对于dml操作(insert,update)则需要进行以下几个步骤:
    open cursor--->parse--->bind variable--->execute--->close cursor;
    对于delete操作只需要进行以下几个步骤:
    open cursor--->parse--->execute--->close cursor;


(三)具体案例

    下面就本人所开发系统中某一程序做分析
    该过程为一股票技术曲线计算程序,将数据从即时数据表中取出,并按照计算曲线的公式,对这些数据进行计算,并将结果保存到技术曲线表中.
--**********************************
--procedure name:R_Ma_Main
--入口参数:PID股票代码,PEND时间,pinterval时间间隔,totab目标数据表
--调用函数:R_GetSql1,R_GetSql2
--功能:具体计算单支股票ma技术曲线
--时间:2001-06-20
--**********************************
create or replace procedure R_Ma_Main
  (
   pid varchar2,
   pend varchar2,
   pinterval varchar2,
   totab varchar2
  ) is                    
 
--定义数组
type Date_type is table of varchar2(12) index by binary_integer;
type Index_type is table of number index by binary_integer;

TempDate Date_Type;--时间数组
TempIndex Index_Type;--股票收盘价数组
TempMa Index_Type;--ma技术曲线数据

cursor1 integer;--游标
cursor2 integer;--游标
rows_processed integer;--执行游标返回

TempInter integer;--参与计算数值个数
TempVal integer;--计算时间类型
TempSql varchar2(500);--动态sql语句
MyTime varchar2(12);--时间
MyIndex number;--数值
MidIndex number;--中间变量
i integer := 999;
j integer;
begin
  TempInter := to_number(substr(pinterval,1,4));
  TempVal := to_number(substr(pinterval,5,2));
  TempSql := R_GetSql1(pid, pend, TempVal);--得到选择数据的sql语句

  --得到当天的即时数据,并依次保存到数组中
  cursor1 := dbms_sql.open_cursor;  --创建游标
  dbms_sql.parse(cursor1, TempSql, dbms_sql.native);  --解析动态sql语句,取两个字段,时间及价格,其中时间以14位的varchar2表示
  dbms_sql.define_column(cursor1, 1, MyTime, 12);  --分别定义sql语句中各字段所对应变量
  dbms_sql.define_column(cursor1, 2, MyIndex);
  rows_processed := dbms_sql.execute(cursor1);
  loop
    if dbms_sql.fetch_rows(cursor1) > 0 then
      begin
        dbms_sql.column_value(cursor1, 1, MyTime);
        dbms_sql.column_value(cursor1, 2, MyIndex);
        TempDate(i) := MyTime;
        TempIndex(i) := MyIndex;
        i := i - 1;--按倒序的方法填入数组
      end;
    else
      exit;
    end if;
  end loop;
  dbms_sql.close_cursor(cursor1);
 
  --如果取得的数据量不够计算个数,则跳出程序
  if i > 999-TempInter then
    goto JumpLess;
  end if;
 
  --初始化中间变量
  MidIndex := 0;
  TempIndex(i) := 0;
  for j in i..i+TempInter-1 loop
    MidIndex := MidIndex + TempIndex(j);
  end loop;

  --依次对当天数据计算ma值,并保存到ma数组中
  for j in i+TempInter..999 loop
    MidIndex := MidIndex - TempIndex(j-TempInter) + TempIndex(j);
    TempMa(j) := MidIndex/TempInter;
  end loop;  

  if TempVal < 6 then--如果计算的是分钟跟天的ma技术曲线
    begin
    cursor2 := dbms_sql.open_cursor;
    TempSql := 'insert into ' || totab || ' values(:r_no, :i_interval, :i_time, :i_index)';
    dbms_sql.parse(cursor2, TempSql, dbms_sql.native);
    for j in i+TempInter..999 loop
      dbms_sql.bind_variable(cursor2, 'r_no', pid);
      dbms_sql.bind_variable(cursor2, 'i_interval', pinterval);
      dbms_sql.bind_variable(cursor2, 'i_time', TempDate(j));
      dbms_sql.bind_variable(cursor2, 'i_index', TempMa(j));
      rows_processed := dbms_sql.execute(cursor2);--插入数据
    end loop;
    end;
  end if;
  commit;
  dbms_sql.close_cursor(cursor2);
  --数据量不足跳出
  <<JumpLess>>
  null;
 
  --exception处理,无关本话题
end;
/

(四)个人观点

    在使用dbms_sql系统包的过程中,其方法简单而又不失灵活,但还是需要注意一些问题:
    1、在整个程序的设计过程中,对游标的操作切不可有省略的部分,一旦省略其中某一步骤,则会程序编译过程既告失败,如在程序结尾处未对改游标进行关闭操作,则在再次调用过程时会出现错误.
    2、dbms_sql除了可以做一般的select,insert,update,delete等静态的sql做能在过程中所做工作外,还能执行create等DDL操作,不过在执行该类操作时应首先显式赋予执行用户相应的系统权限,比如create table等.该类操作只需open cursor--->prase--->close cursor即能完成.

    以上为本人在工作中对dbms_sql的一点点看法,不到之处,请予指正.
    对于想更深了解dbms_sql的朋友,请阅读dbmssql.sql文件.


附个Oracle自带的流程说明(强大啊):

  --  The flow of procedure calls will typically look like this:
  --
  --                      -----------
  --                    | open_cursor |
  --                      -----------
  --                           |
  --                           |
  --                           v
  --                         -----
  --          ------------>| parse |
  --         |               -----
  --         |                 |
  --         |                 |---------
  --         |                 v         |
  --         |           --------------  |
  --         |-------->| bind_variable | |
  --         |     ^     -------------   |
  --         |     |           |         |
  --         |      -----------|         |
  --         |                 |<--------
  --         |                 v
  --         |               query?---------- yes ---------
  --         |                 |                           |
  --         |                no                           |
  --         |                 |                           |
  --         |                 v                           v
  --         |              -------                  -------------
  --         |----------->| execute |            ->| define_column |
  --         |              -------             |    -------------
  --         |                 |------------    |          |
  --         |                 |            |    ----------|
  --         |                 v            |              v
  --         |           --------------     |           -------
  --         |       ->| variable_value |   |  ------>| execute |
  --         |      |    --------------     | |         -------
  --         |      |          |            | |            |
  --         |       ----------|            | |            |
  --         |                 |            | |            v
  --         |                 |            | |        ----------
  --         |                 |<-----------  |----->| fetch_rows |
  --         |                 |              |        ----------
  --         |                 |              |            |
  --         |                 |              |            v
  --         |                 |              |    --------------------
  --         |                 |              |  | column_value         |
  --         |                 |              |  | variable_value       |
  --         |                 |              |    ---------------------
  --         |                 |              |            |
  --         |                 |<--------------------------
  --         |                 |
  --          -----------------|
  --                           |
  --                           v
  --                      ------------
  --                    | close_cursor |
  --                      ------------
  --
  ---------------

 

基于HIS空间Retinex算法的夜间图像增强实践 图像增强技术是计算机视觉中的基础课题,通过改善图像质量来提升视觉感知效果。Retinex理论作为经典算法,通过分离光照和反射分量实现自适应增强。在HIS/HSV颜色空间中,亮度通道的独立处理能有效避免颜色失真,结合双边滤波技术可同时实现降噪和边缘保留。这种方案特别适用于监控摄像头、行车记录仪等低照度场景,MATLAB实现展示了从颜色空间转换到参数调优的全流程。实际应用中需注意噪声放大和光晕效应等问题,通过多尺度处理和GPU加速可进一步提升效果。 阅读详情

相关推荐

DBMS_SQL的使用

DBMS_SQL包提供的函数 DBMS_SQL包提供的过程 示例 CREATE OR REPLACE PROCEDURE DBMS_SQL_TEST ( TABLE_NAME IN VARCHAR2 ) AS v_cur integer;--定义游标 v_sql varchar2(200);--定义SQL语句 BEGIN -- 使用DBMS_SQL包执行DDL语句 -- 执...

huangbaokang的博客 2253

Oracle dbms_sql 的用法

DBMS_SQL 是 Oracle 数据库中的一个包,用于动态执行 SQL 语句。请注意,使用 DBMS_SQL 时需要谨慎处理错误和异常,并确保在执行完成后正确关闭游标。打开游标: 使用 DBMS_SQL.OPEN_CURSOR 打开一个游标。定义动态 SQL: 使用 DBMS_SQL.PARSE 解析动态 SQL。关闭游标: 使用 DBMS_SQL.CLOSE_CURSOR 关闭游标。

weixin_42095178的博客 1067

Oracle中DBMS SQL解析SQL语句的流程

在Oracle数据库中,DBMS SQL是一个强大的包,用于解析和执行SQL语句。下面将详细介绍Oracle中DBMS SQL解析SQL语句的流程。这样,我们就完成了Oracle中DBMS SQL解析SQL语句的流程。通过使用DBMS SQL包,我们可以轻松地解析SQL语句并获取解析状态。这些变量将用于存储解析后的SQL语句和相关的信息。首先,我们需要创建一个SQL语句,用于演示DBMS SQL的解析过程。在完成SQL语句的解析后,我们需要关闭游标,释放相关的资源。参数是要解析的SQL语句,

MbfrDeveloper的博客 252

Oracle之DBMS_SQL包用法详解

通常运用DBMS_SQL包一般分为如下几步: 1. open cursor:打开cursor 2. parse cursor:解析你要执行的SQL语句 3. bind variable:如果要执行的SQL语句中包含变量,在此就需要绑定变量 4. execute:执行SQL语句 5. close cursor:在执行后关闭此cursor. 如果你还需要返回执行SQL的结果集,还需要使用...

月下狼~图腾~ 1732

信号完整性基础04:串扰(1)

我们理解了“单个”传输线(传输线是信号路径+回流路径,切记~),但大多数情况下单独“传输线”的情况并不多见(理想情况下的同轴线缆可以算一个),大多数我们PCB板上有成百上千条走线,它们组成了一个“大社会”,就如当年的TVB神剧《创世纪》一样,到处充满着恩怨情仇;稍处理不慎,单板这个“社会”就会崩溃。那么我们要从哪里入手去理解它呢?最基本的就是从两条PCB走线(传输线)之间的串扰开始。好,年前倒数第二章:《为什么会有串扰》。 ps:我们了解了x射线是啥,那么今天开始讲“放射线”,这两种东西是否就是同一种呢~

WKEZHENG的博客 6056

Django Cookie/Session

Cookie是一种小型的文本文件,通常由Web服务器发送到用户浏览器,并存储在用户的本地计算机上。当用户再次访问该网站时,浏览器会将Cookie发送回服务器,从而实现用户身份验证、个性化设置等功能。Session是一种在服务器端存储用户会话信息的方式。与Cookie不同,Session数据存储在服务器上,而不是客户端。Django框架通过在客户端存储一个Session ID来实现Session的跟踪。Django框架的Cookie/Session机制为开发者提供了方便的数据存储和会话管理功能。

froginwe11的博客 471

使用DBMS_TRACE对PL/SQL进行跟踪

可以使用DBMS_TRACE对PL/SQL进行跟踪,典型的跟踪过程如下:*开始PL/SQL跟踪(DBMS_TRACE.SET_PLSQL_TRACE)*运行PL/SQL*停止PL/SQL跟踪(DBMS_TRACE.CLEAR_P...

888

别再为数据发愁:5分钟理解事件相机原理,并自己动手生成事件图像

本文深入浅出地解析了事件相机的工作原理,并提供了从静态图像生成事件数据的实用方法。通过Python代码示例,读者可以快速掌握如何模拟事件相机的输出,应用于机器人导航、自动驾驶等领域,解决数据获取难题。

weixin_31458015的博客 306

关于DBMS_SQL的使用

PL/SQL中使用动态SQL编程     在PL/SQL程序设计过程中,会遇到很多必须使用动态sql的地方,oracle系统所提供的DMBS_SQL包可以帮助你解决问题。 (一)介绍     DBMS_SQL系统包提供了很多函数及过程,现在简要阐述其中使用频率较高的几种:     function open_cursor:打开一个动态游标,并返回一个整型;

rudy gao 1340

Attention优化|2w字原理&图解: 从Online-Softmax到FlashAttention V1/V2/V3

本文通过原理分析和图解的方式,通俗易懂地FlashAttention系列算法。FlashAttention V1/V2在LLM领域的应用已经非常广泛,相关的论文也反复读了几遍。FA1和FA2论文非常经典,都推荐读一下(不过FA2论文中公式错误不少本文大约1.8w字,包括以下内容:0x07 分布式训推使用FlashAttention0x09 FlashAttention中MQA/GQA以及Causal Mask处理。

具身机器人和通用AI 5243

将Windbg附加到软件进程上排查异常闪退的问题

使用Windbg和Process Explorer排查因为内存泄漏导致的软件异常闪退问题。

dvlinker的技术专栏 1万+

DBMS_SQL使用

一、简介 DBMS_SQL包提供一个接口,用于执行动态SQL(包括DDL 和DML)。 DBMS_SQL定义了一个实体叫游标ID,游标ID是一个PL/SQL整型数,通过游标ID,可以对游标进行操作。 DBMS_SQL包和本地动态SQL在功能上有许多重叠的地方,但是有的功能只能通过本地动态SQL实现,而有些功能只能通过DBMS_SQL实现。 二、主要函数 DBMS_SQL封装过程中的主要函数: 1、OPEN_CURSOR:返回新游标的ID值 2、PARSE:解析要执行的语句 3、BIND_VARIABLE:将

刚木的博客 2555

使用MATLAB实现PAC2002轮胎模型的TIR文件解析和模型计算详解

PAC2002轮胎模型是由荷兰TNO公司开发的一种半经验的轮胎模型,用于描述轮胎在不同工况下的力学特性。该模型基于一系列物理和经验参数,通过复杂的数学表达式来模拟轮胎的力学行为,包括纵向力、侧向力、回正力矩等。

qq_38334677的博客 2435

【转】 dbms_sql的使用

dbms_sql的使用http://space.itpub.net/13129975/viewspace-624522 通常运用DBMS_SQL包一般分为几步:1. open cursor: 打开cursor2. parse cursor:解析你要执行的SQL语句3. bind variable:如果要执行的SQL语句中包含变量,在此就需要绑定变量4. execute:执行SQL语句5

strawbingo的专栏 1989

人工智能训练师三级考试备考全攻略|报名条件+真题+补贴申领一站式通关(2026版)

本专栏是人工智能训练师三级考证最完整的备考指南,共77篇文章,覆盖从职业认知、报名实操、AI基础知识、数据标注、模型训练测试部署、考前冲刺到考后进阶的全链路。本导读按模块整理了全部文章链接,帮你快速定位所需内容。人工智能训练师是国家认定的正式职业,证书可在osta.mohrss.gov.cn查询,三级证书可申领最高3120元技能补贴。

白话机器学习 1914

Google Earth Engine(GEE)——使用归一化燃烧指数 (NBR) 绘制地表烧伤严重程度图

归一化燃烧指数(Normalized Burn Ratio, NBR)是一种遥感指标,用于评估野火或烧伤地面后的植被恢复情况。NBR能增强较大范围的火灾区域,如大于200公顷。它是通过比较远红外波段 (SWIR) 和近红外波段 (NIR) 的反射率来计算的。SWIR波段测量烧伤地面的反射率,NIR波段测量没有受到烧伤影响的植被的反射率。NBR的计算公式为:NBR =(NIR-SWIR)/(NIR + SWIR)。其中,NIR为近红外波段,SWIR为短波红外波段。

此星光明博客 3488

PL/SQL Profiler - DBMS_PROFILER

之前写过EBS下的PL/SQL Profiling 调试的文章,PL/SQL Profiling用于调试EBS下PL/SQL(如:Procedure,Function)的性能情况。今天抛开EBS这个特定的产品,写一下如何使用DBMS_PROFILER这个Package,如何获取PL/SQL中各段代码的执行时间。DBMS_PROFILER的官方介绍:http://docs.oracle.com/cd

田攀的日志 4818

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

全面学习DBMS包之DBMS_SQL

在PL/SQL编程当中,经常会遇到一些需要动态处理数据或表结构的问题,比如对一批表里的数据进行处理,或者批量创建表,索引,触发器等等,这个时候就可以通过DBMS_SQL包进行操作。你可能会有疑问,ORACLE不是提供了EXECUTE IMMEDIATE了嘛?干嘛还要DBMS_SQL包来处理?嘿嘿,不错,很多人都习惯用EXECUTE IMMEDIATE来动态处理此类需求。下面根据我的理解,...

dfgppwzkb17977379的博客 502

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

mysql dbms output_PL/SQL DBMS输出

在本章中,我们将讨论PL/SQL中的DBMS输出。 DBMS_OUTPUT是一个内置的包,使我们能够显示输出,调试信息以及从PL/SQL块,子程序,包和触发器发送消息。 我们已经在前前教程文章中多次使用了这个包。下面看看一个小的代码片段,它将显示数据库中的所有用户表。列出数据库中所有的表名 -SET SERVEROUTPUT ON SIZE 99999;BEGINdbms_output.put_l...

weixin_42345731的博客 1032

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

关于dbms_sql的使用

PL/SQL中使用动态SQL编程在PL/SQL程序设计过程中,会遇到很多必须使用动态sql的地方,oracle系统所提供的DMBS_SQL包可以帮助你解决问题。(一)介绍DBMS_SQL系统包提供了很多函数及过程,现在简要阐述其...

262

pl/sql dbms_DBMS中PL / SQL的块结构

pl/sql dbmsPL/SQL is Block Structured. What is Block? PL/SQL programs are built on the basic units. These basic units are the blocks. Blocks can be named as Functions and Procedures or Anonymous Block...

cumtv80668的专栏 277

Oracle PL/SQL高级编程(第六弹:性能优化:使用DBMS_TRACE包)

如果写了一个大而复杂的PL/SQL应用程序,想要跟踪对子程序的调用,比如看到子程序的执行顺序,则可以使用DBMS_TRACE包,该包的使用过程与DBMS_PROFILER类似,一个主要区别在于DBMS_TRACE可以设定需要跟踪的事件:调用、异常、SQL甚至每一个PL/SQL代码的可运行。 DBMS_TRACE默认已经被安装在Oracle系统中,在包中主要的函数有如下两个: - set_pls...

艺术就是爆炸的专栏 1473

PL/SQL中使用动态SQL编程

 PL/SQL中使用动态SQL编程在PL/SQL程序设计过程中,会遇到很多必须使用动态sql的地方,oracle系统所提供的DMBS_SQL包可以帮助你解决问题。(一)介绍DBMS_SQL系统包提供了很多函数及过程,现在简要阐述其中使用频率较高的几种:function open_cursor:打开一个动态游标,并返回一个整型;procedure close_cursor(c in ou

luojun198610的专栏 652

使用dbms_profiler 调试PL/SQL 性能

目的: 调查PL/SQL(8.1级以上)的性能 参考文档: Performance of New PL/SQL Features (Doc ID 104377.1) Using DBMS_PROFILER (Doc ID 97270.1) https://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_profil.htm#ARPLS67481 -- 安装 在sys账号下执行 $ORACLE_HOME/rdbms/admin/profload.sql...

文档搬运工 638

PL/SQL中使用动态SQL编程[转贴]

在PL/SQL程序设计过程中,会遇到很多必须使用动态sql的地方,oracle系统所提供的DMBS_SQL包可以帮助你解决问题。(一)介绍DBMS_SQL系统包提供了很多函数及过程,现在简要阐述其中使用频率较高的几种:function open_cursor:打开一个动态游标,并返回一个整型;procedure close_cursor(c in out integer);关闭一个动态游标,参数为

yhb72的专栏 2637

动态魔术使用DBMS_SQL

动态SQL / PLSQL被认为是Oracle PL / SQL中最高级的主题之一。尽管它根本不是一个新主题,但它仍然是消化和掌握最具挑战性的概念之一。 动态SQL只是SQL代码的任何部分,在编译之前未明确写入。因此,例如,如果您不知道SQL查询中的“WHERE”谓词,则必须使用动态SQL。Oracle为我们提供了两种不同的方法来构建动态SQL / plsql代码,第一种是NativeDynam...

Tybyqi的博客 413
上一篇: PL/SQL游标
下一篇: PL/SQL执行动态SQL(一)
wang77777
博客等级 码龄19年 4粉丝 105原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值