Stored Procedures
am 16.01.2006 09:33:48 von minalacThis is a multi-part message in MIME format.
------=_NextPart_000_00E7_01C61AA5.ABF05C20
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I am trying to pass values through a jsp page wherein I am accessing =
this stored procedures by the following select ststemet
SELECT sp_build_course('ETLCRC0001:ETLCRC0010:', =
'CRCSUB0001:CRCSUB0001:', 'ABC', 'minal' )
the function is as below:
CREATE OR REPLACE FUNCTION sp_build_course("varchar", "varchar", =
"varchar", "varchar")
RETURNS text AS
'
Declare=20
COURSEIDS VARCHAR(1000) ;
TOPICIDS VARCHAR(1000);
COURSENAME VARCHAR(150);
USERNAME VARCHAR(20);
COURSEIDS1 VARCHAR(1000);=20
TOPICIDS1 VARCHAR(1000);=20
COURSEID1 VARCHAR(20);
TOPICID1 VARCHAR(20);
NEWCOURSEID VARCHAR(20);
NEWTOPICID VARCHAR(20);
COLUMN1 VARCHAR(50);
COLUMN2 VARCHAR(50);
COLUMN3 VARCHAR(50);
COLUMN4 VARCHAR(50);
QCODE1 VARCHAR(10);
QDATE1 VARCHAR(10);
QSNO INTEGER;
WEIGHTAGE INTEGER;
QSTYPE VARCHAR(50);
QUESTION VARCHAR(1000);
MARKS VARCHAR(50);
QFLAG BOOL;
PFLAG BIT;
PAPER_TYPE VARCHAR(20);
CINDEX INTEGER;
TINDEX INTEGER;
INDEX INTEGER;
QINDEX INTEGER;
QUESTIONID INTEGER;
NEWQUESTIONID INTEGER;
LESSON_FLOW_TITLE VARCHAR(50);
TREE_NODE_TYPE VARCHAR(50);
VIDEO_SIZE INTEGER;
ROOT_NODE_ID INTEGER;
SLIDE_ORDER INTEGER;
row1 record;
row2 record;
row3 record;
COURSENAME1 varchar(150);
USERNAME1 varchar(50);
BEGIN
SET COURSEIDS1:=3DCOURSEIDS;
SET TOPICIDS1:=3DTOPICIDS;
SET COURSENAME1:=3DCOURSENAME;
SET USERNAME1:=3DUSERNAME;
--PRINT \'INSIDE THE STORED PROCEDURE\'
COLUMN1 :=3D DATE_PART(\'Day\',current_date);
COLUMN2 :=3D DATE_PART(\'Month\',current_date);
COLUMN3 :=3D DATE_PART(\'Year\',current_date);
IF LENGTH(COLUMN1) =3D 1 THEN
COLUMN1 :=3D \'0\' || COLUMN1;
END IF;
IF LENGTH(COLUMN2) =3D 1 THEN
COLUMN2 :=3D \'0\' || COLUMN2;
END IF;
QDATE1 :=3D COLUMN1 || COLUMN2 || COLUMN3;
SELECT trim(to_char(max(to_number(QCODE,\'999999\'))+1,\'000009\')) INTO =
QCODE1 FROM QUESTION WHERE QDATE =3D QDATE1;
WHILE (LENGTH(QCODE1) < 6) LOOP
QCODE1 :=3D \'0\' || QCODE1;
END LOOP;
SELECT MAX(SUBSTR(COURSEID,7,LENGTH(COURSEID))) INTO NEWCOURSEID FROM =
COURSEMASTER;
WHILE (LENGTH(NEWCOURSEID) < 4) LOOP
NEWCOURSEID :=3D \'0\' || NEWCOURSEID;
END LOOP;
NEWCOURSEID :=3D \'ETLCRC\' || NEWCOURSEID;
INSERT INTO COURSEMASTER(COURSEID, COURSENAME) VALUES ( =
NEWCOURSEID,COURSENAME1);
CINDEX :=3D POSITION(\':\' IN COURSEIDS1);
TINDEX :=3D POSITION(\':\' IN TOPICIDS1);
INDEX :=3D 1;
WHILE (CINDEX > 0) LOOP
COURSEID1 :=3D SUBSTR(COURSEIDS1,1,(CINDEX-1));
TOPICID :=3D SUBSTR(TOPICIDS1,1,(TINDEX-1));
-- TRANSACTION STARTS HERE
NEWTOPICID :=3D INDEX;
WHILE (LENGTH(NEWTOPICID) < 4) LOOP
NEWTOPICID :=3D \'0\' || NEWTOPICID;
END LOOP;
NEWTOPICID :=3D \'CRCSUB\' || NEWTOPICID;
INSERT INTO MYTABLE6 VALUES(COURSEID1, TOPICID, NEWCOURSEID, =
NEWTOPICID);
INSERT INTO TOPICS SELECT NEWCOURSEID, NEWTOPICID, TOPICNAME FROM =
TOPICS WHERE COURSEID=3DCOURSEID AND TOPICID=3DTOPICID;
SELECT NULLIF(0,COUNT(*)) INTO COLUMN3 FROM LESSON_FLOW WHERE =
COURSEID=3DCOURSEID AND TOPICID=3DTOPICID;
COLUMN1 :=3D COURSEID1 || \'_\' || TOPICID || \'_\';
COLUMN2 :=3D NEWCOURSEID || \'_\' || NEWTOPICID || \'_\';
IF (COLUMN3 >0) THEN
SELECT MAX(ATTACHMENT_ID) + 1 INTO COLUMN3 FROM COURSE_LESSON;
INSERT INTO COURSE_LESSON(COURSEID1, TOPICID, RECORD_STATUS, =
ATTACHMENT_ID) VALUES (NEWCOURSEID, NEWTOPICID,0, CONVERT(INT, =
COLUMN3));
INSERT INTO ATTACHMENT SELECT COLUMN3, COLUMN2 + =
SUBSTR(URL,23,LENGTH(URL)), SEQUENCE FROM ATTACHMENT WHERE =
SUBSTR(URL,0,23) =3D COLUMN1;
SELECT MAX(LF_ID) + 1 INTO COLUMN4 FROM LESSON_FLOW;
FOR row1 IN SELECT LESSON_FLOW_TITLE, TREE_NODE_TYPE, VIDEO_SIZE, =
ROOT_NODE_ID, SLIDE_ORDER FROM LESSON_FLOW WHERE COURSEID=3DCOURSEID AND =
TOPICID =3D TOPICID
LOOP
LESSON_FLOW_TITLE:=3Drow1.LESSON_FLOW_TITLE;
TREE_NODE_TYPE:=3Drow1.TREE_NODE_TYPE;
VIDEO_SIZE:=3Drow1.VIDEO_SIZE;
ROOT_NODE_ID:=3Drow1.ROOT_NODE_ID;
SLIDE_ORDER:=3Drow1.SLIDE_ORDER;
INSERT INTO LESSON_FLOW VALUES (COLUMN4, NEWCOURSEID, NEWTOPICID, =
LESSON_FLOW_TITLE, TREE_NODE_TYPE, VIDEO_SIZE, COLUMN3, ROOT_NODE_ID, =
SLIDE_ORDER);
COLUMN4 :=3D COLUMN4 + 1;
=20
END LOOP;
INSERT INTO SELECTEDSESSION SELECT NEWCOURSEID, NEWTOPICID, COLUMN2 =
+ SUBSTR(URL,23,LENGTH(URL)) FROM SELECTEDSESSION WHERE COURSEID=3D =
COURSEID1 AND TOPICID=3D TOPICID;
END IF;
QINDEX :=3D 1;
=20
FOR row2 IN SELECT QUESTION_ID, QSNO, WEIGHTAGE, QSTYPE, QUESTION, =
MARKS, FLAG, PAPER_TYPE FROM QUESTION WHERE COURSEID=3DCOURSEID AND =
TOPICID =3D TOPICID
LOOP
QUESTIONID:=3Drow2.QUESTION_ID;
QSNO:=3Drow2.QSNO;
WEIGHTAGE:=3Drow2.WEIGHTAGE;
QSTYPE:=3Drow2.QSTYPE;
QUESTION:=3Drow2.QUESTION;
MARKS:=3Drow2.MARKS;
QFLAG:=3Drow2.FLAG;
PAPER_TYPE:=3Drow2.PAPER_TYPE;
=20
INSERT INTO QUESTION (COURSEID1, TOPICID, QSNO, WEIGHTAGE, QSTYPE, =
QUESTION, MARKS, QDATE, QCODE,FLAG, USERNAME, PAPER_TYPE) VALUES =
(NEWCOURSEID, NEWTOPICID, QINDEX, WEIGHTAGE, QSTYPE, QUESTION, MARKS, =
QDATE1, QCODE,QFLAG, USERNAME1, PAPER_TYPE);
NEWQUESTIONID :=3D IDENTITY;
INSERT INTO OPTIONS SELECT NEWQUESTIONID, OPTIONS, CORRECTOPTION FROM =
OPTIONS WHERE QUESTION_ID=3DQUESTIONID;
QCODE1 :=3DQCODE1 + 1;
WHILE (LENGTH(QCODE1) < 6) LOOP
QCODE1 :=3D \'0\' || QCODE1;
END LOOP;
QINDEX :=3D QINDEX + 1; =20
END LOOP; =20
QINDEX :=3D 1;
FOR row3 IN SELECT QUESTION_ID, QSNO, QSTYPE, QUESTION, FLAG FROM =
POLL_QUESTION WHERE COURSEID=3DCOURSEID AND TOPICID =3D TOPICID
LOOP
QUESTIONID:=3Drow3.QUESTIONID;
QSNO:=3Drow3.QSNO;
QSTYPE:=3Drow3.QSTYPE;
QUESTION:=3Drow3.QUESTION;
PFLAG:=3Drow3.FLAG; =20
INSERT INTO POLL_QUESTION (COURSEID1, TOPICID, QSNO, QSTYPE, =
QUESTION, QDATE, QCODE,FLAG, USERNAME) VALUES (NEWCOURSEID, NEWTOPICID, =
QINDEX, QSTYPE, QUESTION, QDATE1, QCODE1,PFLAG, USERNAME1);
NEWQUESTIONID :=3D IDENTITY;
INSERT INTO POLL_OPTIONS SELECT NEWQUESTIONID, OPTIONS, SUB_OPTIONS, =
TYPE,DISPLAY FROM POLL_OPTIONS WHERE QUESTION_ID=3DQUESTIONID;
QCODE1 :=3D QCODE1 + 1;
WHILE (LENGTH(QCODE1) < 6) loop
QCODE1 :=3D \'0\' || QCODE1;
END LOOP;
QINDEX :=3D QINDEX + 1;
END LOOP;
COURSEIDS1 :=3D SUBSTR(COURSEIDS1,(CINDEX+1),LENGTH(COURSEIDS1));
TOPICIDS1 :=3D SUBSTR(TOPICIDS1,(TINDEX+1),LENGTH(TOPICIDS1));
CINDEX :=3D POSITION(\':\' IN COURSEIDS1);
TINDEX :=3D POSITION(\':\' IN TOPICIDS1);
INDEX :=3D INDEX + 1;
END LOOP;
RETURN \'1\';
END;
'
LANGUAGE 'plpgsql' VOLATILE;
when I run it I get the following error:
ERROR: syntax error at or near "$1" at character 6
CONTEXT: PL/pgSQL function "sp_build_course" line 45 at SQL statement.
Can someone please look into the procedure and tell me where I have gone =
wrong.
------=_NextPart_000_00E7_01C61AA5.ABF05C20
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
charset=3Diso-8859-1">
through a jsp page=20
wherein I am accessing this stored procedures by the following select=20
ststemet
sp_build_course('ETLCRC0001:ETLCRC0010:',=20
'CRCSUB0001:CRCSUB0001:', 'ABC', 'minal' )
sp_build_course("varchar", "varchar", "varchar", "varchar")
=
RETURNS=20
text AS
'
Declare
COURSEIDS VARCHAR(1000) ;
TOPICIDS=20
VARCHAR(1000);
COURSENAME VARCHAR(150);
USERNAME =
VARCHAR(20);
TOPICIDS1 =
VARCHAR(1000);
COURSEID1 VARCHAR(20);
TOPICID1=20
VARCHAR(20);
NEWCOURSEID VARCHAR(20);
NEWTOPICID =
VARCHAR(20);
COLUMN1=20
VARCHAR(50);
COLUMN2 VARCHAR(50);
COLUMN3 VARCHAR(50);
COLUMN4=20
VARCHAR(50);
QCODE1 VARCHAR(10);
QDATE1 VARCHAR(10);
QSNO=20
INTEGER;
WEIGHTAGE INTEGER;
QSTYPE VARCHAR(50);
QUESTION=20
VARCHAR(1000);
MARKS VARCHAR(50);
QFLAG BOOL;
PFLAG =
BIT;
PAPER_TYPE=20
VARCHAR(20);
CINDEX INTEGER;
TINDEX INTEGER;
INDEX =
INTEGER;
QINDEX=20
INTEGER;
QUESTIONID INTEGER;
NEWQUESTIONID =
INTEGER;
LESSON_FLOW_TITLE=20
VARCHAR(50);
TREE_NODE_TYPE VARCHAR(50);
VIDEO_SIZE=20
INTEGER;
ROOT_NODE_ID INTEGER;
SLIDE_ORDER INTEGER;
row1=20
record;
row2 record;
row3 record;
COURSENAME1=20
varchar(150);
USERNAME1 varchar(50);
SET =
COURSEIDS1:=3DCOURSEIDS;
SET=20
TOPICIDS1:=3DTOPICIDS;
SET COURSENAME1:=3DCOURSENAME;
SET=20
USERNAME1:=3DUSERNAME;
PROCEDURE\'
DATE_PART(\'Day\',current_date);
COLUMN2 :=
DATE_PART(\'Month\',current_date);
COLUMN3 :=
DATE_PART(\'Year\',current_date);
THEN
COLUMN1 :=
\'0\' || COLUMN1;
END IF;
IF LENGTH(COLUMN2) =3D 1 =
THEN
COLUMN2 :=
\'0\' || COLUMN2;
END IF;
COLUMN3;
trim(to_char(max(to_number(QCODE,\'999999\'))+1,\'000009\')) INTO QCODE1 =
FROM=20
QUESTION WHERE QDATE =3D QDATE1;
6)=20
LOOP
QCODE1 :=3D \'0\' || QCODE1;
END =
LOOP;
MAX(SUBSTR(COURSEID,7,LENGTH(COURSEID)))=20
INTO NEWCOURSEID FROM COURSEMASTER;
< 4)=20
LOOP
NEWCOURSEID :=3D \'0\' || NEWCOURSEID;
END=20
LOOP;
NEWCOURSEID :=3D \'ETLCRC\' ||=20
NEWCOURSEID;
INSERT INTO COURSEMASTER(COURSEID, =
COURSENAME)=20
VALUES ( NEWCOURSEID,COURSENAME1);
CINDEX :=3D =
POSITION(\':\' IN=20
COURSEIDS1);
TINDEX :=3D POSITION(\':\' IN=20
TOPICIDS1);
INDEX :=3D 1;
WHILE (CINDEX =
> 0)=20
LOOP
COURSEID1 :=
SUBSTR(COURSEIDS1,1,(CINDEX-1));
TOPICID :=
SUBSTR(TOPICIDS1,1,(TINDEX-1));
HERE
NEWTOPICID :=3D =
INDEX;
WHILE =20
(LENGTH(NEWTOPICID) < 4) LOOP
NEWTOPICID =
:=3D \'0\'=20
|| NEWTOPICID;
END =
LOOP;
NEWTOPICID :=
\'CRCSUB\' || NEWTOPICID;
INSERT INTO MYTABLE6=20
VALUES(COURSEID1, TOPICID, NEWCOURSEID, =
NEWTOPICID);
INSERT=20
INTO TOPICS SELECT NEWCOURSEID, NEWTOPICID, TOPICNAME FROM TOPICS =
WHERE=20
COURSEID=3DCOURSEID AND TOPICID=3DTOPICID;
SELECT=20
NULLIF(0,COUNT(*)) INTO COLUMN3 FROM LESSON_FLOW WHERE =
COURSEID=3DCOURSEID AND=20
TOPICID=3DTOPICID;
COLUMN1 :=3D COURSEID1 || \'_\' =
|| TOPICID=20
|| \'_\';
COLUMN2 :=3D NEWCOURSEID || \'_\' || =
NEWTOPICID ||=20
\'_\';
IF (COLUMN3 >0)=20
THEN
SELECT MAX(ATTACHMENT_ID) + 1 INTO =
COLUMN3 FROM=20
COURSE_LESSON;
INSERT INTO =
COURSE_LESSON(COURSEID1,=20
TOPICID, RECORD_STATUS, ATTACHMENT_ID) VALUES (NEWCOURSEID, =
NEWTOPICID,0,=20
CONVERT(INT, COLUMN3));
INSERT INTO =
ATTACHMENT SELECT=20
COLUMN3, COLUMN2 + SUBSTR(URL,23,LENGTH(URL)), SEQUENCE FROM ATTACHMENT =
WHERE=20
SUBSTR(URL,0,23) =3D COLUMN1;
SELECT =
MAX(LF_ID) + 1=20
INTO COLUMN4 FROM LESSON_FLOW;
SELECT =20
LESSON_FLOW_TITLE, TREE_NODE_TYPE, VIDEO_SIZE, ROOT_NODE_ID, SLIDE_ORDER =
FROM=20
LESSON_FLOW WHERE COURSEID=3DCOURSEID AND TOPICID =
TOPICID
LOOP
=
LESSON_FLOW_TITLE:=3Drow1.LESSON_FLOW_TITLE;
&=
nbsp;TREE_NODE_TYPE:=3Drow1.TREE_NODE_TYPE;
&n=
bsp;VIDEO_SIZE:=3Drow1.VIDEO_SIZE;
ROOT_=
NODE_ID:=3Drow1.ROOT_NODE_ID;
SLIDE_ORDE=
R:=3Drow1.SLIDE_ORDER;
INTO=20
LESSON_FLOW VALUES (COLUMN4, NEWCOURSEID, NEWTOPICID, =
LESSON_FLOW_TITLE,=20
TREE_NODE_TYPE, VIDEO_SIZE, COLUMN3, ROOT_NODE_ID,=20
SLIDE_ORDER);
COLUMN4 :=3D COLUMN4 +=20
1;
END=20
LOOP;
INSERT INTO SELECTEDSESSION SELECT =
NEWCOURSEID,=20
NEWTOPICID, COLUMN2 + SUBSTR(URL,23,LENGTH(URL)) FROM SELECTEDSESSION =
WHERE=20
COURSEID=3D COURSEID1 AND TOPICID=3D TOPICID;
END=20
IF;
QINDEX :=3D =
1;
FOR=20
row2 IN SELECT QUESTION_ID, QSNO, WEIGHTAGE, QSTYPE, QUESTION, MARKS,=20
FLAG, PAPER_TYPE FROM QUESTION WHERE COURSEID=3DCOURSEID AND =
TOPICID =
TOPICID
LOOP
QUESTIONID:=3Drow2.QUEST=
ION_ID;
QSNO:=3Drow2.QSNO;
WEIG=
HTAGE:=3Drow2.WEIGHTAGE;
QSTYPE:=3Drow2.QSTYPE;
&=
nbsp; QUESTION:=3Drow2.QUESTION;
MARKS:=3D=
row2.MARKS;
QFLAG:=3Drow2.FLAG;
 =
;PAPER_TYPE:=3Drow2.PAPER_TYPE;
&nbs=
p;INSERT=20
INTO QUESTION (COURSEID1, TOPICID, QSNO, WEIGHTAGE, QSTYPE, QUESTION, =
MARKS,=20
QDATE, QCODE,FLAG, USERNAME, PAPER_TYPE) VALUES (NEWCOURSEID, =
NEWTOPICID,=20
QINDEX, WEIGHTAGE, QSTYPE, QUESTION, MARKS, QDATE1, QCODE,QFLAG, =
USERNAME1,=20
PAPER_TYPE);
NEWQUESTIONID :=
IDENTITY;
INSERT INTO OPTIONS SELECT NEWQUESTIONID, =
OPTIONS, CORRECTOPTION FROM OPTIONS WHERE=20
QUESTION_ID=3DQUESTIONID;
QCODE1 :=3DQCODE1 +=20
1;
WHILE (LENGTH(QCODE1) < 6)=20
LOOP
QCODE1 :=3D \'0\' ||=20
QCODE1;
END LOOP;
QINDEX :=3D =
QINDEX +=20
1;
END =
LOOP;
QINDEX=20
:=3D 1;
QUESTION_ID,=20
QSNO, QSTYPE, QUESTION, FLAG FROM POLL_QUESTION WHERE =
COURSEID=3DCOURSEID=20
AND TOPICID =
TOPICID
LOOP
QUESTIONID:=3Drow3.QUEST=
IONID;
QSNO:=3Drow3.QSNO;
QSTYP=
E:=3Drow3.QSTYPE;
QUESTION:=3Drow3.QUESTION;
&nbs=
p; PFLAG:=3Drow3.FLAG;
=
INSERT=20
INTO POLL_QUESTION (COURSEID1, TOPICID, QSNO, QSTYPE, QUESTION, QDATE,=20
QCODE,FLAG, USERNAME) VALUES (NEWCOURSEID, NEWTOPICID, QINDEX, QSTYPE, =
QUESTION,=20
QDATE1, QCODE1,PFLAG, =
USERNAME1);
NEWQUESTIONID :=
IDENTITY;
INSERT INTO POLL_OPTIONS SELECT=20
NEWQUESTIONID, OPTIONS, SUB_OPTIONS, TYPE,DISPLAY FROM POLL_OPTIONS =
WHERE=20
QUESTION_ID=3DQUESTIONID;
QCODE1 :=3D QCODE1 =
+=20
1;
WHILE (LENGTH(QCODE1) < 6)=20
loop
QCODE1 :=3D \'0\' ||=20
QCODE1;
END =
LOOP;
QINDEX=20
:=3D QINDEX + 1;
END LOOP;
SUBSTR(COURSEIDS1,(CINDEX+1),LENGTH(COURSEIDS1));
TOPICIDS1 :=
SUBSTR(TOPICIDS1,(TINDEX+1),LENGTH(TOPICIDS1));
CINDEX :=3D =
POSITION(\':\' IN=20
COURSEIDS1);
TINDEX :=3D POSITION(\':\' IN TOPICIDS1);
INDEX :=3D =
INDEX +=20
1;
END;
LANGUAGE 'plpgsql'=20
VOLATILE;
error:
near "$1"=20
at character 6
CONTEXT: PL/pgSQL function "sp_build_course" =
line 45 at=20
SQL statement.
procedure and tell=20
me where I have gone wrong.
------=_NextPart_000_00E7_01C61AA5.ABF05C20--