我創建的序列
create sequence student_no
increment by 1
start with 1
maxvalue 9999
cycle;
函數:create or replace function getstudentno
return varchar2
is
student_no varchar2(8);
year varchar2(4);
no number;
begin
select to_char(sysdate,'yyyy') into year from dual;
dbms_output.put_line(year);
return year;
end getstudentno;
/
此時可以創建,但是在begin中加入dbms_output.putline(student_no.xextval);時,就報編譯錯誤。
我需要在函數中使用序列,應該怎樣用,需要授權嗎?
12 个解决方案
dbms_output.putline(student_no.xextval);代碼錯了吧nextval
不好意思,是buhaodbms_output.putline(student_no.nxextval);少打了一個字母。不是寫錯了。
序列.nextval ---》下一個值,
序列.currval ---》當前值
我再說明一下,不是序列的nextval有問題,那只是我打錯了。大家可以把那個錯誤地方改一下,創建函數試試。
求高手給一個明確的答復。
我再說明一下,不是序列的nextval有問題,那只是我打錯了。大家可以把那個錯誤地方改一下,創建函數試試。
求高手給一個明確的答復。
樓主的最終的需求是什么?我感覺你用函數的目的是為了返回序列號的當前值或是下一個值,而這種需求用序列號是可以直接的解決的。我的建議是,直接的引用序列的下一個值或當前值,放棄用函數
生成8位學號,要求前四位是年份數,后四位是從1開始,每次增1的數字
自己發現錯誤了,原來是定義的變量名和自己的序列名一樣,所以才會這樣,麻煩各位了。