立即SQL - 命令未正确结束

时间:2014-04-24 15:53:57

标签: sql oracle11g

我在Oracle中运行此功能时遇到了麻烦。我似乎无法弄清楚发生了什么。我一直得到“SQL命令没有正确结束18行”。我认为这与我的Immediate SQL有关,但我并不完全正面。有什么想法吗?

create or replace 
FUNCTION COMPARE_USER(
indexNumber IN varchar,
firstName IN varchar,
lastName IN varchar,
email IN varchar,
department IN varchar,
userLocation IN varchar,
userType IN varchar,
active IN varchar
)
RETURN CHAR 
IS
  tableName varchar(50) := 'TEST_USER';
  boolCheck char;
  rowCount int;

BEGIN
    EXECUTE IMMEDIATE 
  'SELECT COUNT(*) FROM ' || tableName ||
  ' WHERE INDEX_NUMBER  = ' || indexNumber ||
  ' AND FIRST_NAME  = ' || firstName ||
  ' AND LAST_NAME  = ' || lastName ||
  ' AND EMAIL  = ' || email ||
  ' AND DEPARTMENT  = ' || department ||
  ' AND USER_LOCATION  = ' || userLocation ||
  ' AND USER_TYPE  = ' || userType ||
  ' AND ACTIVE  = ' || active
  INTO rowCount;

  IF rowCount = 0 Then
    boolCheck := 'N';
  Else
    boolCheck := 'Y';
  End If;
RETURN boolCheck;
END COMPARE_USER;

1 个答案:

答案 0 :(得分:0)

是的,尝试重写EXECUTE IMMEDIATE语句,如下所示:

  EXECUTE IMMEDIATE 
  'SELECT COUNT(*) FROM ' || tableName ||
  ' INTO rowCount'
  ' WHERE INDEX_NUMBER  = ' || indexNumber ||
  ' AND FIRST_NAME  = ' || firstName ||
  ' AND LAST_NAME  = ' || lastName ||
  ' AND EMAIL  = ' || email ||
  ' AND DEPARTMENT  = ' || department ||
  ' AND USER_LOCATION  = ' || userLocation ||
  ' AND USER_TYPE  = ' || userType ||
  ' AND ACTIVE  = ' || active