问题标签 [cursors]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
61 浏览

sql - 可以在游标中使用存储过程吗?

游标通常是使用 SQL 代码创建的,例如:

DECLARE MyCursor CURSOR FOR SELECT SIN(A),COS(A) FGR_db_Database..tb_Angles WHERE A BETWEEN 0 AND 360`

如果代码已经作为过程存在,或者更可能是更复杂的代码,是否可以使用该过程来代替?例如:

DECLARE MyCursor CURSOR FOR EXEC sp_PR_ProcedureName @l_Angle

我已经尝试过,但到目前为止没有成功,也不知道这是否可能。

提前致谢!

0 投票
1 回答
44 浏览

oracle - 重写查询

总体任务:- 我需要从系统 A 中的 45 个字段中检索数据,并将该数据转储到一个临时表中,然后由一个 unix 进程拾取该临时表,该进程生成一个要导入系统 B 的 xml 数据文件。

具体问题:检索要写入 45 个字段的数据的最佳方法是什么。大多数数据是独立的,无法使用单个语句检索。我目前检索此数据的方式如下(示例如下)

我的临时表包含我需要为其提取数据的受影响的属性 ID。即 PROP_LIST_TEMP 和 ASSOC_PROP_TEMP。

0 投票
3 回答
212 浏览

sql - SQL Server 游标循环替代方案

我有员工工作时间日志数据。现在我必须标记员工在连续工作日(周六/周日周末)为相同任务记录相同时间的所有记录。

让我用下面的例子解释我的问题

我有员工小时日志表说 EMP_HOUR_LOG:

在上面的示例数据集中,我必须将第 1、2、3、10 和 11 行的 FLAG 更新为 1,因为这些记录是同一员工连续几天为同一任务输入的小时数相同的条目。

我已经使用游标实现了这一点,因为我想不出任何替代方法来逐条循环遍历数据记录。

请让我知道这里是否有人可以建议任何更好的方法来通过避免游标循环或一般循环来实现相同的方法。

谢谢

0 投票
1 回答
319 浏览

mysql - 卡在存储过程和游标上

我正在尝试创建一个存储过程,该过程将接受 TYPEID 和用户编号作为参数,然后搜索尚未获取/已返回的可用条目(显示比较和查看表 1 和 2),然后插入一个新的贷款表中的行。在此之前检查用户是否被禁止(表 3,使用 SIGNAL 进行思考)。

数据:

我已经尝试使用 CURSOR,这是我认为我需要使用的,但是我遇到了我无法解决的错误,这是我到目前为止所做的

任何想法?谢谢

0 投票
2 回答
1269 浏览

oracle - Oracle SQL Developer PL/SQL 返回一个数组

开发人员,

我到处搜索,但我找不到这个简单问题的解决方案。

情况:

我需要编写一个过程,它将列名作为输入,并返回该列中存在的所有不同值作为输出。然后我必须在一些 c# 代码中使用这个过程。

在 MS 服务器中,这很容易,因为它会直接给出结果集,这与 PL/SQL 不同。

我可以写的脚本(这没有给我我需要的结果):

;

当我尝试使用此代码检查记录集中的数据时:

有人可以帮我处理这段代码吗?

0 投票
1 回答
72 浏览

sql - 为什么这个游标声明上没有括号?

我在这里有一个游标声明:

但是如果我添加一个order by子句,我会得到一个错误:

错误:Incorrect syntax near the keyword 'order'.

但是如果我去掉括号,错误就会消失:

也许我有点不清楚括号在 SQL Server 中的作用。是什么赋予了?为什么order by子句会以这种方式与括号交互?

0 投票
0 回答
451 浏览

python - 无法从 ndb 查询中获取游标

我需要使用游标查询数据存储(我需要游标,因为任务可能不会在 10 分钟内完成)。到目前为止,我无法使用 fetch_page 或 Query.iter() 获得有效的游标。在这两种情况下,当我使用生成的光标时,我都会得到一个

BadRequestError:光标位置超出原始查询的范围

这是查询

请注意,我正在使用 ndb.OR 进行过滤,并且我还在对模型键上的查询进行排序,如在线文档中所述。

运行查询的代码非常简单

第一个循环工作正常(光标为无)。在第二个循环(光标已初始化)上,我得到了错误。我也试过用迭代器来做这个:

我看到了同样的行为。我目前正在努力将 ndb.OR 分解为两个单独的查询。然而我想知道我是在滥用 ndb API 还是其他什么?

-- 更新 -- 这是错误的痕迹

0 投票
1 回答
1756 浏览

mysql - Mysql cursor alternative / Optimization - each row updates are too slow

I'm looking to optimize my cursor based update or actually replacing it...

Situation

We're carrying out promotional campaigns and I'd like to track user activity per campaign.

Logic

Each campaign is pushed to a specific batch - Segment of our customer base

The tracking_start_date is the date of the campaign while tracking_end_date is the date tracking should end.

Each campaign has it's own "Call to Action (cta)" which is the transaction type we're pushing and hoping customers will start using after the campaign.

By default the tracking_end_date in the segments table is set to last day of the month but I've created a procedure to check and update this field. (Campaign_id's are issued sequentially according to the campaign date and so the earliest campaign has the least campaign_id value and vise versa) Tracking is done on a calender month on month basis.

Update scenario

For each record in the segments table check whether the same customer_id appears in a future campaign and if that campaign with a greater tracking_start_date has the same CTA.

If TRUE: change the tracking_end_date for that record to a day before the new campaign.

If FALSE: retain last day of tracking_start_date month as the tracking_end_date.

If the update is not done, then we would be double/tripple... counting transactions for customers who appear in several campaigns and had the same CTA.

Below is the procedure I'm currently using but the problem is that it's too slow.

These procedure is housed in another one that loops through the campaign_id's for the month then calls this procedure while supplying the relevant campaign_id

PS: Before initiating the procedure, I make a copy of the segments table in another one called segments_temp and do the comparison from there (this is because MySQL cannot do updates from a self referencing query)

Hope I'm clear & thanks in advance for your ideas

0 投票
1 回答
436 浏览

sublimetext3 - How do I automatically have multiple cursors in a Sublime Text 3 snippet?

I have a console log snippet for Sublime Text 3.

I would like for there to be multiple cursors, so that, when I call the key for this snippet, the cursor is at both the $1 and the $2 locations, as I often just want to log the variable name and the variable value in the console. How do I manage this?

0 投票
1 回答
240 浏览

android - 向前移动android sql lite光标

我的应用程序中有一个 Sql lite 表。

我想添加一个游标来解析表格,使其从当前位置向前移动。
主要思想是更新所有下一行而不是前一行。

如果需要,任何人都可以给我一个示例光标来使用任何循环吗?