由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 请帮忙读懂这个sql script
相关主题
请问sql server里面怎么输出变量到文本文件?ORA-01002: fetch out of sequence问题
SQL run a stored procedure by fetching from a cursor row by row请教SQL
请教set和select 的区别A question of filling in missing value in SQL
[转载] Hehe,不好意思,another question:)SQL query 一问
请问sql 有条件性的select columnsinterview question (SQL)
select 跟 set 的区别?谁能帮我看看这个oracle function有什么错?
SQL Server 如何把日期自动加入文件名中?Need help on finding dependency objects
can I create a recordset with cursor?How to merge tables in SQL Server 2000?
相关话题的讨论汇总
话题: val话题: dq话题: tab话题: validate话题: bigint
进入Database版参与讨论
1 (共1页)
y********o
发帖数: 61
1
请问这个procedure干什么用的?sql 蝌蚪,读不懂啊~~求高人指点
USE [CFH_ODS]
GO
/****** Object: StoredProcedure [dbo].[DQ_VALIDATE] Script Date: 07/13/
2015 15:08:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DQ_VALIDATE](@tableID bigint = null, @fldID bigint =
null)
AS
BEGIN
SET NOCOUNT ON
declare @VAL_ID bigint;
--
INSERT INTO DQ_VAL(VAL_START_DT) values(GETDATE());
SELECT @VAL_ID = @@IDENTITY;
DECLARE c CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY
FOR SELECT TAB_ID FROM DQ_TAB WHERE ISNULL(@tableID, TAB_ID) = TAB_
ID and VAL_FL = 1;
DECLARE @id BIGINT;
OPEN c;
FETCH NEXT FROM c INTO @id;
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC DQ_VALIDATE_TABLE @VAL_ID, @ID;
EXEC DQ_VALIDATE_FIELD @VAL_ID, @ID

FETCH NEXT FROM c INTO @id;
END
CLOSE c;
DEALLOCATE c;
UPDATE DQ_VAL SET VAL_END_DT = GETDATE() WHERE VAL_ID = @VAL_ID;
END
GO
m******u
发帖数: 12400
2
stored procedure. it is a kind of object of database.
r**********d
发帖数: 510
3
you arent clear about the syntax or logic.
if former, better to start with something simple.
if latter, ask co worker.
my understanding is that
it DQ_VALIDATE TABLE and fields of the table when table id is passed in,
or all the tables returned from the cursor.
then
it updates start end time to track the DQ process in DQ_VAL(id, VAL_
START_DT, VAL_END_DT )
@fldID is not used.
read DQ_VALIDATE_TABLE may help you understand it better
x****e
发帖数: 1773
4
USE [CFH_ODS]
GO
/****** Object: StoredProcedure [dbo].[DQ_VALIDATE] Script Date: 07/13/
2015 15:08:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DQ_VALIDATE](@tableID bigint = null, @fldID bigint =
null) -- This proc takes @tablID and @fldID arguments.
-- No idea what this proc does without knowing about the procs it calls, and
all the tables that are involved in the whole process.
AS
BEGIN
SET NOCOUNT ON
declare @VAL_ID bigint; -- Declare an @VAL_ID as bigint
--
INSERT INTO DQ_VAL(VAL_START_DT) values(GETDATE()); -- This table should
have an IDENTITY column.
-- This statement inserts a row with the VAL_START_DT value as the
current timestamp.
SELECT @VAL_ID = @@IDENTITY; -- Get the value for @VAL_ID as the @@
IDENTITY.
DECLARE c CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY
FOR SELECT TAB_ID FROM DQ_TAB WHERE ISNULL(@tableID, TAB_ID) = TAB_
ID and VAL_FL = 1; -- Declare a cursor for the TAB_ID values from the DQ_TAB
table.
-- You could run this query and find out what values are to
be included. Can improve the performance by modifying the ISNULL.
DECLARE @id BIGINT; -- Declare an @id for looping over the cursor
OPEN c;
FETCH NEXT FROM c INTO @id;
WHILE @@FETCH_STATUS = 0 -- While loop.
BEGIN
EXEC DQ_VALIDATE_TABLE @VAL_ID, @ID; -- Calls two procedures, need to
check what these two would do. Presumably these two procs may also do sth
against the DQ_CAL table.
EXEC DQ_VALIDATE_FIELD @VAL_ID, @ID

FETCH NEXT FROM c INTO @id; -- Repeat with the next @id from the
cursor.
END
-- Loop ends.
CLOSE c;
DEALLOCATE c;
UPDATE DQ_VAL SET VAL_END_DT = GETDATE() WHERE VAL_ID = @VAL_ID; --
Updates the VAL_END_DT value with the current timestamp for the previously
inserted row.
END
GO

=

【在 y********o 的大作中提到】
: 请问这个procedure干什么用的?sql 蝌蚪,读不懂啊~~求高人指点
: USE [CFH_ODS]
: GO
: /****** Object: StoredProcedure [dbo].[DQ_VALIDATE] Script Date: 07/13/
: 2015 15:08:33 ******/
: SET ANSI_NULLS ON
: GO
: SET QUOTED_IDENTIFIER ON
: GO
: CREATE PROCEDURE [dbo].[DQ_VALIDATE](@tableID bigint = null, @fldID bigint =

1 (共1页)
进入Database版参与讨论
相关主题
How to merge tables in SQL Server 2000?请问sql 有条件性的select columns
T-SQL Row Concatenate with a Twist??select 跟 set 的区别?
求救,这个更新如何写?SQL Server 如何把日期自动加入文件名中?
一个sql问题:怎样实现 (((a1*10)+a2)*10+a3)*10 ... (转载)can I create a recordset with cursor?
请问sql server里面怎么输出变量到文本文件?ORA-01002: fetch out of sequence问题
SQL run a stored procedure by fetching from a cursor row by row请教SQL
请教set和select 的区别A question of filling in missing value in SQL
[转载] Hehe,不好意思,another question:)SQL query 一问
相关话题的讨论汇总
话题: val话题: dq话题: tab话题: validate话题: bigint