postgresql函数中的赋值运算和postgresql函数存储过程实现数据批量插入

来源:互联网 发布:js实现灯泡点亮熄灭 编辑:程序博客网 时间:2024/06/05 08:30

 

今天检查大家写的postgresql函数时,发现有的家伙不遵守postgresql关于函数中的赋值运算表示方式:

variable := value

注意的是,是:=表示赋值运算,而不是单独一个等号。这一点和delphi相似?

另外,postgresql中关于两个变量的比较,是一个等号,比如 :

IF(variable1=variable2) THEN
END IF

这一点和C语言也是不同的,C语言是==表示等价比较。


postgresql函数存储过程实现数据批量插入

 

创建函数:

create function insert_page(text,char,char,

char,char,text,text,text,text,text,text,text,

text,text,text,text,text,text,text,real,real,

text,text,text,char,timestamp,text,int) returns bool as '

declare

   url alias for $1;

   touurl alias for $27;    

    i int;

    urll text;

    begin

    i :=0;

    urll := url;

    while i < $28 loop

       urll := touurl || i || urll;

       insert into page_t

       values(urll,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,

       $12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26);

       urll := url;

       i := i + 1;

   end loop;

   if i < $28 then

     return false;

   else

     return true;

   end if;

   end;

    'language 'plpgsql';删除函数:

drop function insert_page(text,char,char,

char,char,text,text,text,text,text,text,text,

text,text,text,text,text,text,text,real,real,

text,text,text,char,timestamp,text,int);

<script type="text/javascript"><!--google_ad_client = "pub-5873492303276472";/* 728x15, 创建于 08-7-29 */google_ad_slot = "7630759450";google_ad_width = 728;google_ad_height = 15;// --></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script><script type="text/javascript"><!--window.google_render_ad();// --></script>
原创粉丝点击