> SET @Exists = 0; > IF EXISTS (SELECT 1 FROM table WHERE PK = > @PK) > BEGIN > SET @Exists = 1; > END > RETURN; > END
Derby supports stored procedures in written Java only (not SQL/PSM), so the above in not valid Derby SQL. Have a look at http://wiki.apache.org/db-derby/DerbySQLroutines and http://db.apache.org/derby/docs/10.3/ref/rrefcreatefunctionstatement.html http://db.apache.org/derby/docs/10.3/ref/rrefcreateprocedurestatement.html Dag rico16135 <[EMAIL PROTECTED]> writes: > Help with use of exists > with java-netbeans > MIME-Version: 1.0 > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > X-Nabble-From: [EMAIL PROTECTED] > > > I am trying to write a sql query that checks for the existence of a call_num > in my table rico.calls so i can either enter it there if it doesn't exist or > another table. > > so, in netbeans I try and execute something like this: > I found this example > > BEGIN > SET @Exists = 0; > IF EXISTS (SELECT * FROM rico.calls WHERE call_num = 8) > BEGIN > SET @Exists = 1; > END > RETURN; > END > GO > > > > > it complains about finding BEGIN at line 1 column 1 ok, so what > am I doing wrong? > > > > > > Error code -1, SQL state 42X01: Syntax error: Encountered "BEGIN" at line 1, > column 1. > Line 1, column 1 > > Error code -1, SQL state 42X01: Syntax error: Encountered "IF" at line 1, > column 1. > Line 3, column 1 > > Error code -1, SQL state 42X01: Syntax error: Encountered "END" at line 1, > column 1. > Line 6, column 1 > > Error code -1, SQL state 42X01: Syntax error: Encountered "END" at line 1, > column 1. > Line 8, column 1 > > Execution finished after 0 s, 4 error(s) occurred. > -- > View this message in context: > http://www.nabble.com/BEGIN%0D%0ASET-%40Exists-%3D-0-%0D%0AIF-EXISTS-%28SELECT-1-FROM-table-WHERE-PK-%3D-%40PK%29%0D%0ABEGIN%0D%0ASET-%40Exists-%3D-1-%0D%0AEND%0D%0ARETURN-%0D%0AEND%0D%0AHelp-with-use-of-exists-with-java-netbeans-tp16512198p16512198.html > Sent from the Apache Derby Users mailing list archive at Nabble.com. > > > -- Dag H. Wanvik Sun Microsystems, Database Technology Group (DBTG) Haakon VII gt. 7b, N-7485 Trondheim, Norway Tel: x43496/+47 73842196, Fax: +47 73842101
