-1

クエリがあります。phpmyadminで実行したいものです。

しかし、実行するたびに、declareでエラーが発生しました。私はこれのエラーが何であるかを見つけることができませんか?

このコードブロックをPHPからのクエリとして実行したいですか?

-- Declare a cursor to hold the section information for a specified product
DECLARE section_cursor CURSOR FOR
SELECT DISTINCT cds_especee.sectid, cds_evocee.text, min
(displayorder) displayorder
FROM cds_especee
JOIN cds_evocee ON (cds_especee.sectid = cds_evocee.id)
-- Replace the prodid below with a valid prodid from your data set
WHERE cds_especee.prodid = 'S1522339'
GROUP BY cds_especee.sectid, cds_evocee.text
ORDER BY displayorder ASC
OPEN section_cursor
-- Fetching the first section into variable
FETCH NEXT FROM section_cursor
INTO @section, @sectionname, @order
WHILE @@FETCH_STATUS = 0
BEGIN
-- Print current section to the screen
PRINT '******'+@sectionname+'******'
-- Declare a cursor to hold the header and body information for the
specified product
-- Note that the WHERE statement limits the results to the headers and body falling under the current section
DECLARE espec_cursor CURSOR FOR
SELECT evoc1.text, evoc2.text, displayorder
FROM cds_especee
JOIN cds_evocee evoc1 ON (cds_especee.hdrid = evoc1.id)
JOIN cds_evocee evoc2 ON (cds_especee.bodyid = evoc2.id)
-- Replace the prodid below with a valid prodid from your data set
WHERE cds_especee.prodid = 'S1522339' AND
cds_especee.sectid = @section
ORDER BY displayorder ASC
OPEN espec_cursor
-- Fetching the first header and body into variable
FETCH NEXT FROM espec_cursor
INTO @hdr, @body, @order1
WHILE @@FETCH_STATUS = 0
-- Below is a loop that prints all the headers and bodies for the
current section
BEGIN
PRINT @hdr +': '+@body
FETCH NEXT FROM espec_cursor
INTO @hdr, @body, @order1
END
-- Clear out the espec_cursor as it will be repopulated with data for
the next section as the procedure loops
CLOSE espec_cursor
DEALLOCATE espec_cursor
-- Fetches the next section and returns to the top of the loop
FETCH NEXT FROM section_cursor
INTO @section, @sectionname, @order
PRINT ' '
PRINT ' '
END
-- Clear out the section_cursor as the procedure is over
CLOSE section_cursor
DEALLOCATE section_cursor
4

2 に答える 2

0

たぶん、mysql区切り文字についての何かです。次のように実行してみてください。

DELIMITER $$
-- Declare a cursor to hold the section information for a specified product 
DECLARE section_cursor CURSOR FOR 
SELECT DISTINCT cds_especee.sectid, cds_evocee.text, min 
(displayorder) displayorder 
FROM cds_especee 
JOIN cds_evocee ON (cds_especee.sectid = cds_evocee.id) 
-- Replace the prodid below with a valid prodid from your data set 
WHERE cds_especee.prodid = 'S1522339' 
GROUP BY cds_especee.sectid, cds_evocee.text 
ORDER BY displayorder ASC 
OPEN section_cursor 
-- Fetching the first section into variable 
FETCH NEXT FROM section_cursor 
INTO @section, @sectionname, @order 
WHILE @@FETCH_STATUS = 0 
BEGIN 
-- Print current section to the screen 
PRINT '******'+@sectionname+'******' 
-- Declare a cursor to hold the header and body information for the 
specified product 
-- Note that the WHERE statement limits the results to the headers and body falling under the current section 
DECLARE espec_cursor CURSOR FOR 
SELECT evoc1.text, evoc2.text, displayorder 
FROM cds_especee 
JOIN cds_evocee evoc1 ON (cds_especee.hdrid = evoc1.id) 
JOIN cds_evocee evoc2 ON (cds_especee.bodyid = evoc2.id) 
-- Replace the prodid below with a valid prodid from your data set 
WHERE cds_especee.prodid = 'S1522339' AND 
cds_especee.sectid = @section 
ORDER BY displayorder ASC 
OPEN espec_cursor 
-- Fetching the first header and body into variable 
FETCH NEXT FROM espec_cursor 
INTO @hdr, @body, @order1 
WHILE @@FETCH_STATUS = 0 
-- Below is a loop that prints all the headers and bodies for the 
current section 
BEGIN 
PRINT @hdr +': '+@body 
FETCH NEXT FROM espec_cursor 
INTO @hdr, @body, @order1 
END 
-- Clear out the espec_cursor as it will be repopulated with data for 
the next section as the procedure loops 
CLOSE espec_cursor 
DEALLOCATE espec_cursor 
-- Fetches the next section and returns to the top of the loop 
FETCH NEXT FROM section_cursor 
INTO @section, @sectionname, @order 
PRINT ' ' 
PRINT ' ' 
END 
-- Clear out the section_cursor as the procedure is over 
CLOSE section_cursor 
DEALLOCATE section_cursor$$ 
DELIMITER ;
于 2012-09-21T06:48:02.977 に答える
0

シンプルな MySQL スクリプトでは、DECLARE、OPEN、FETCH、CLOSE などのステートメントの多くを使用できません。この目的のために、ソース オブジェクトを作成する必要があります。たとえば、ストアド プロシージャを使用して実行できます。ドキュメントに良い例があります - Cursors

また、PRINT は MySQL ステートメントではありません。

于 2012-09-21T07:11:41.140 に答える