加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

简单的Oracle变量SQL赋值

发布时间:2021-05-16 12:36:38 所属栏目:站长百科 来源:网络整理
导读:尽量花了一个小时研究我好像无法弄清晰怎样正确界说变量然后在SQL中行使它. 这是我到今朝为止所做的: DECLARE startDate DATE:= to_date(’03 / 11/2011′,’dd / mm / yyyy’); 个中我获得了复原: ORA-06550: line 1,column 63: PLS-00103: Encountered

尽量花了一个小时研究我好像无法弄清晰怎样正确界说变量然后在SQL中行使它.

这是我到今朝为止所做的:

DECLARE startDate DATE:= to_date(’03 / 11/2011′,’dd / mm / yyyy’);

个中我获得了复原:

ORA-06550: line 1,column 63: PLS-00103: Encountered the symbol
“end-of-file” when expecting one of the following:

begin function package pragma procedure subtype type use form current
cursor

Details: DECLARE startDate DATE := to_date(’03/11/2011′,
‘dd/mm/yyyy’); Error at line 1 ORA-06550: line 1,column 63:
PLS-00103: Encountered the symbol “end-of-file” when expecting one of
the following:

begin function package pragma procedure subtype type use form current
cursor

我很想知道怎样做这么简朴的使命!

您的变量声明是正确的.

DECLARE要害字用于界说PL / SQL块中的变量(其主体由BEGIN和END脱离;).你想怎样行使这个变量?

以下PL / SQL对我来说很好:

DECLARE 
    startDate DATE := to_date('03/11/2011','dd/mm/yyyy');
    reccount INTEGER;
BEGIN
    SELECT count(*) INTO reccount 
        FROM my_table tab 
        WHERE tab.somedate < startDate;
    dbms_output.put_line(reccount);
END;

您还可以行使DEFINE语句来行使简朴的字符串替代变量.它们合用于SQL / PLUS或TOAD等客户端.

DEFINE start_date = "to_date('03/11/2011','dd/mm/yyyy')"
SELECT COUNT(*) from my_table tab where tab.some_date < &start_date;

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读