易语言 执行SQL不完全,但是不报错。麻烦帮忙看一下

.版本2.支持库eDBSQL存储过程=“IFEXISTS(SELECT*FROMsys.objectsWHEREobject_id=OBJECT_ID(N'[dbo].[... .版本 2
.支持库 eDB

SQL存储过程 = “IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[KCABC]') AND type in (N'U')) DROP TABLE [dbo].[KCABC] DECLARE @QTY DECIMAL(8,0),@ITEM VARCHAR(20),@PER DECIMAL(8,4),@T_PER DECIMAL(8,4),@T_AMOUNT DECIMAL(16,4),@AMOUNT DECIMAL(16,4),@TOTAL_AMOUNT DECIMAL(16,4) CREATE TABLE KCABC(ITEM VARCHAR(20),QTY DECIMAL(16,4),AMOUNT DECIMAL(16,4),PER DECIMAL(8,4),TOTAL_PER DECIMAL(8,4),ABC VARCHAR(1));SELECT @TOTAL_AMOUNT=SUM(LA013) FROM INVLA WHERE LA014 IN ('2','3') AND LA011<>0 AND LA004 LIKE '2014%' INSERT INTO KCABC(ITEM,QTY,AMOUNT,PER,TOTAL_PER,ABC) SELECT LA001,SUM(LA011) AS QTY,SUM(LA013) AS AMOUNT,SUM(LA013)/@TOTAL_AMOUNT,'0','' FROM INVLA WHERE LA014 IN ('2','3') AND LA011<>0 AND LA004 LIKE '2014%' GROUP BY LA001 SET @T_AMOUNT=0 DECLARE CC CURSOR FOR SELECT ITEM,AMOUNT FROM KCABC ORDER BY AMOUNT DESC OPEN CC FETCH NEXT FROM CC INTO @ITEM,@AMOUNT WHILE @@FETCH_STATUS = 0 BEGIN SET @T_AMOUNT=@T_AMOUNT+@AMOUNT SET @T_PER=@T_AMOUNT/@TOTAL_AMOUNT IF (@T_PER) <=0.8 UPDATE KCABC SET TOTAL_PER=@T_PER,ABC='A' WHERE ITEM=@ITEM ELSE IF (@T_PER) <=0.9 UPDATE KCABC SET TOTAL_PER=@T_PER,ABC='B' WHERE ITEM=@ITEM ELSE UPDATE KCABC SET TOTAL_PER=@T_PER,ABC='C' WHERE ITEM=@ITEM PRINT @T_PER FETCH NEXT FROM CC INTO @ITEM,@AMOUNT END CLOSE CC DEALLOCATE CC”

_启动窗口.数据库连接.执行SQL (SQL存储过程)

语句本身没有错误,但是放在易语言里面执行,游标没有执行完全,执行到70多条数据之后就不动了。但是这个语句放在SQL里面执行执行是没问题的。麻烦懂易语言的告诉一下,这个是什么原因造成的,谢谢!
展开
 我来答
枫叶朴璐
2015-02-04 · TA获得超过2606个赞
知道大有可为答主
回答量:7573
采纳率:0%
帮助的人:5931万
展开全部
oracle 10g的DBMS_XPLAN包中display_cursor函数不同于display函数,display_cursor用于显示SQL语句的真实的执行计划,在大多数情况下,
显示真实的执行计划有助于更好的分析SQL语句的全过程,尤其是运行此SQL语句实时的I/O开销。通过对比预估的I/O与真实的I/O开销来判断
SQL语句所存在问题,如缺少统计信息,SQL语句执行的次数,根据实际中间结果集的大小来选择合适的连接方式等。本文仅仅讲述
display_cursor函数的使用。

一、display_cursor函数用法
1、display_cursor函数语法

DBMS_XPLAN.DISPLAY_CURSOR(
sql_id IN VARCHAR2 DEFAULT NULL,
cursor_child_no IN NUMBER DEFAULT NULL,
format IN VARCHAR2 DEFAULT 'TYPICAL');

2、display_cursor函数参数描述
sql_id
指定位于库缓存执行计划中SQL语句的父游标。默认值为null。当使用默认值时当前会话的最后一条SQL语句的执行计划将被返回
可以通过查询V$SQL 或V$SQLAREA的SQL_ID列来获得SQL语句的SQL_ID。
cursor_child_no
指定父游标下子游标的序号。即指定被返回执行计划的SQL语句的子游标。默认值为0。如果为null,则sql_id所指父游标下所有子游标
的执行计划都将被返回。
format
控制SQL语句执行计划的输出部分,即哪些可以显示哪些不显示。使用与display函数的format参数与修饰符在这里同样适用。
除此之外当在开启statistics_level=all时或使用gather_plan_statistics提示可以获得执行计划中实时的统计信息
有关详细的format格式描述请参考:dbms_xplan之display函数的使用 中format参数的描述

下面给出启用统计信息时format新增的修饰符
iostats 控制I/O统计的显示
last 默认,显示所有执行计算过的统计。如果指定该值,则只显示最后一次执行的统计信息
memstats 控制pga相关统计的显示
allstats 此为iostats memstats的快捷方式,即allstats包含了iostats和memstats
run_stats_last 等同于iostats last。只能用于oracle 10g R1
run_stats_tot 等同于iostats。只能用于oracle 10g R1

抓一个最近一小时最消耗IO的SQL:
SELECT sql_id, COUNT(*)
FROM gv$active_session_history ash, gv$event_name evt
WHERE ash.sample_time > SYSDATE - 1 / 24
AND ash.session_state = 'WAITING'
AND ash.event_id = evt.event_id
AND evt.wait_class = 'User I/O'
GROUP BY sql_id
ORDER BY COUNT(*) DESC;

执行上面的SQL:
SQL> SELECT sql_id, COUNT(*)
FROM gv$active_session_history ash, gv$event_name evt
2 3 WHERE ash.sample_time > SYSDATE - 1 / 24
4 AND ash.session_state = 'WAITING'
5 AND ash.event_id = evt.event_id
6 AND evt.wait_class = 'User I/O'
7 GROUP BY sql_id
8 ORDER BY COUNT(*) DESC;

SQL_ID COUNT(*)
------------- ----------
g7fu6qba82m6b 668
63r47zyphdk06 526
9f5m4wd88nc1h 514
593p47drw5fhk 232
br91w16jzy4fu 120
4fvwyjpnh6tp7 78
gm0nrbfuj8kzr 70
2184k363hw4xd 68
gc4dajs7g5myy 46
8vrk9sfuwfdgq 42
ccpnb4dwdmq21 40

查看SQL的执行计划:
SELECT * FROM TABLE(dbms_xplan.display_cursor('g7fu6qba82m6b'));

在SQLPLUS中执行:
SQL> set pagesize 2000
SQL> SELECT * FROM TABLE(dbms_xplan.display_cursor('g7fu6qba82m6b'));

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
SQL_ID g7fu6qba82m6b, child number 0
-------------------------------------
UPDATE "CPDDS_PDATA"."CDM_LEDGER" SET "CSTM_NAME" = :a1,"CSTM_NO" =
:a2,"PAPER_TYPE" = :a3,"PAPER_NO" = :a4,"CURR_TYPE" = :a5,"SVT_NO" =
:a6,"BAL_DIR" = :a7,"BAL" = :a8,"AVAL_BAL" = :a9,"NORM_FRATIO" =
:a10,"PK_BAL" = :a11,"DR_ACCU" = :a12,"CR_ACCU" = :a13,"LAST_TRAN_DATE" =
:a14,"LAST_TRAN_TIME" = :a15,"PRT_LINE_NUM" = :a16,"NOREG_PK_REC_NUM" =
:a17,"PK_NO" = :a18,"PWD" = :a19,"FLAG" = :a20,"FRZ_FLAG" =
:a21,"CARD_HOLD_FLAG" = :a22,"PK_HOLD_FLAG" = :a23,"BGN_INT_DATE" =
:a24,"OPEN_DATE" = :a25,"ACC_HOLD_FLAG" = :a26,"CLS_DATE" =
:a27,"OPEN_TLR" = :a28,"CLS_TLR" = :a29,"CLS_INT" = :a30,"OPEN_INST" =
:a31,"ADD_NUM" = :a32,"DAC" = :a33,"FRZ_TIMES1" = :a34,"FRZ_TIMES2" =
:a35,"HOST_SEQNO" = :a36,"D_UPDATE_DATE" = :a37 WHERE "ACC" = :b0

Plan hash value: 319441092

-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | UPDATE STATEMENT | | | | 3 (100)| |
| 1 | UPDATE | CDM_LEDGER | | | | |
|* 2 | INDEX UNIQUE SCAN| I_CDM_LEDGER | 1 | 269 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("ACC"=:B0)

29 rows selected.

总结
1、与display函数不同,display_cursor显示的为真实的执行计划
2、对于format参数,使用与display函数的各个值,同样适用于display_cursor函数
3、当statistics_level为all或使用gather_plan_statistics提示可以获得执行时的统计信息
4、根据真实与预估的统计信息可以初步判断SQL效率低下的原因,如统计信息的准确性、主要的开销位于那些步骤等
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式