mysql存储过程中as_mysql - 存储过程mySQL语法错误意外“ AS” - 堆栈内存溢出

博客内容涉及在创建和使用存储过程时遇到的错误,包括'发布者'标识符错误和AS关键字错误。作者尝试获取出版社的统计信息,如作者数量、书籍数量等,并找出库存最高的书籍。错误出现在对变量的声明和使用上。解决方案可能涉及检查变量命名和语句语法。同时,博客还包含了获取所有出版社统计信息的函数。
摘要由CSDN通过智能技术生成

我正在编写一个存储过程,如下所示

我得到的错误是在第3行和第4行,这两个错误是第3行是“意外的'发布者'标识符”,第4行是“意外的AS(as)”,但我不知道我是怎么得到这些错误或如何解决的他们。 有人可以解释一下为什么我收到这些错误以及可能的解决方法吗

DELIMITER //

CREATE FUNCTION uspGetPubStatsMEP (pcode publisher.publishercode%TYPE)

RETURNS text AS $$

DECLARE

eachrecord text; -- Variable to hold all the records retrieve

booktitle book.title%TYPE;

bcode book.bookcode%TYPE;

maxonhand text;

testtext text:='N/A';

totonhand text;

BEGIN

-- Retrieve the name of thepublisher

SELECT publishername INTO eachrecord

FROM PUBLISHER

WHERE publishercode = pcode;

IF (eachrecordISnull)

THEN

RAISE NOTICE 'No publisher exists for the given code(%)',pcode;

RETURN (-1);

END IF;

-- The number of distinct authors who have written book(s)forthispublisher.

SELECT eachrecord||' No.Authors:'||COUNT(DISTINCTauthornum)INTO

eachrecord

FROM BOOK B, WROTE W

WHERE publishercode=pcodeANDB.bookcode=W.bookcode;

-- The number of different books published by this publisher.

SELECT eachrecord||' No.Books:'||COUNT(*)INTOeachrecord

FROM BOOK

WHERE publishercode=pcode;

-- The title of the book published by this publisher,that has the highest

number

-- of onHand (Inventory) values from all branchesof Henry Books.

CREATE TABLE book_onhandAS

SELECT bookcode,SUM(onhand)ASsum_onhand

FROM INVENTORYI,BRANCHB

WHERE I.branchnum=B.branchnum

GROUP BY bookcode;

CREATE TABLE pubbook_onhand AS

SELECT bookcode, sum_onhand

FROM book_onhand

WHERE bookcodeIN

( SELECT bookcode

FROM BOOK

WHERE publishercode = pcode

)

GROUP BY bookcode,sum_onhand;

SELECT bookcode INTO bcode

FROM pubbook_onhand

WHERE sum_onhand = (SELECT MAX(sum_onhand)

FROM pubbook_onhand

);

SELECT title INTO booktitle

FROM BOOK

WHERE bookcode=bcode;

-- The number of on Hand values for the above book.

SELECT sum_onhand INTO maxonhand

FROM pubbook_onhand

WHERE bookcodeIN ( SELECT bookcode

FROM BOOK

WHERE title = booktitle

);

-- The cumulative sum of on Hand values from all branches for all books

published by thispublisher.

-- use table book_onhand

SELECT sum_onhand INTO totonhand

FROM book_onhand bh, BOOK B

WHERE publishercode = pcode AND

bh.bookcode = B.bookcode;

IF (booktitle IS NULL)

THEN SELECT testtext INTO booktitle;

SELECT testtext INTO maxonhand;

SELECT testtext INTO totonhand;

END IF;

SELECT eachrecord || ' onhandVal:' ||maxonhand ||'

Totalonhand:'|| totonhand ||' onHandBook:'||booktitle INTO eachrecord;

DROP TABLE book_onhand;

DROP TABLE pubbook_onhand;

RETURN eachrecord;

END;

$$ language plpgsql;

-- Various statistics for all publishers in the database

CREATE OR REPLACE FUNCTION uspGetAllPubStatsMEP()

RETURNS SETOF text as $$

DECLARE

pcode publisher%rowtype;

pubstat text;

BEGIN

FOR pcode IN SELECT * FROM PUBLISHER

LOOP

SELECT pcode.publishercode||': '|| uspGetPubStatsMEP

(pcode.publishercode)

INTO pubstat;

RETURN NEXT pubstat;

END LOOP;

RETURN;

END;

$$ language plpgsql;

SELECT uspGetAllPubStatsMEP ();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值