English 中文(简体)
or pl
原标题:oracle plsql concanting a variable to a string

below is the program written in oracle plsql when this program is run by giving P_LOC value as DALLAS it gives error as -904 ORA-00904: "DALLAS": invalid identifier please provide a solution

create or replace
PROCEDURE PR_EMP_LST1 
( P_LOC IN VARCHAR2 
, P_MIN_SAL IN NUMBER
, P_MAX_SAL IN NUMBER 
, P_REF_CUR OUT  SYS_REFCURSOR
) AS

  TYPE TY_LST_REFCURSOR IS REF CURSOR ; 
  cur_emp_lst  TY_LST_REFCURSOR;
  v_inv_query  VARCHAR2(2000);
  V_USG_CL    VARCHAR2(200);


BEGIN

  IF P_LOC IS NULL AND p_min_sal IS  NULL AND p_max_sal IS NULL  THEN  
      v_inv_query := SELECT ENAME 
                     FROM EMP  ;
  ELSE               
      v_inv_query := SELECT ENAME 
                     FROM EMP WHERE  ;


    IF P_LOC IS NULL AND p_min_sal IS NOT NULL AND p_max_sal IS  NOT NULL  THEN                

      v_inv_query :=v_inv_query ||  SAL BETWEEN  
                                  ||p_min_sal 
                                  ||  AND   
                                  || p_max_sal; 
       --  v_inv_query :=v_inv_query ||  SAL BETWEEN :1 AND :2  ;

           dbms_output.put_line( 2 );
     --  V_USG_CL:=    USING  ||p_min_sal||  ,  || p_max_sal;   
    ELSIF P_LOC IS NOT NULL AND p_min_sal IS NOT NULL AND p_max_sal IS  NOT NULL THEN
     dbms_output.put_line( 1 );
      v_inv_query :=v_inv_query||  SAL BETWEEN  
                                  ||p_min_sal ||   AND  ||  p_max_sal
                                  ||   AND DEPTNO IN (SELECT DEPTNO 
                                                 FROM DEPT
                                                 WHERE LOC=  
                                                 || p_loc  
                                                 ||  ) ; 
           dbms_output.put_line( 2 );                                       
    ELSIF P_LOC IS NOT NULL AND p_min_sal IS NULL AND p_max_sal IS  NOT NULL THEN    
       v_inv_query :=v_inv_query||  SAL <=  
                                   ||p_max_sal
                                   ||  AND DEPTNO IN (SELECT DEPTNO 
                                                 FROM DEPT
                                                 WHERE LOC=  
                                                  || p_loc 
                                                  ||  ) ; 
      ELSIF P_LOC IS NOT NULL AND p_min_sal IS NOT NULL AND p_max_sal IS NULL THEN  
       v_inv_query :=v_inv_query||  SAL >=  
                                    ||p_min_sal
                                    ||  AND DEPTNO IN (SELECT DEPTNO 
                                                  FROM DEPT
                                                  WHERE LOC=  
                                                  ||p_loc
                                                  ||  ) ; 
     ELSIF P_LOC IS  NULL AND p_min_sal IS  NULL AND p_max_sal IS NOT NULL THEN 
       v_inv_query :=v_inv_query||   SAL <=  
                                              ||p_max_sal;

     ELSIF P_LOC IS  NULL AND p_min_sal IS NOT NULL AND p_max_sal IS NULL THEN 
       v_inv_query :=v_inv_query||  SAL >=  
                                     || p_min_sal;  

     ELSIF P_LOC IS NOT NULL AND p_min_sal IS  NULL AND p_max_sal IS NULL THEN 
       v_inv_query :=v_inv_query||  DEPTNO IN (SELECT DEPTNO 
                                                  FROM DEPT
                                                  WHERE LOC=  
                                                  ||p_loc
                                                  ||  ) ;                               
     END IF;
  END IF;  
  dbms_output.put_line( 3 );   
   dbms_output.put_line(v_inv_query );
  OPEN cur_emp_lst  FOR v_inv_query ;

  dbms_output.put_line( 4 );   
  P_REF_CUR:=cur_emp_lst;                               

END PR_EMP_LST1;
问题回答

SELECT DEPTNO/ E W WRE LOC= < < < / / / / ) ) L L L L L L L L L L L L L L L L L L L L ong ong ong ong ong ong ong ong < < < / / ) ) ) ) ) ) ) ) ) )

由于达拉斯正在扼杀,你需要把它作为扼杀手段处理:达拉阿联,而不是作为达拉阿联盟。 在座各位必须使用

P_LOC parameter is string type, the parameter value should be enclosed within single quotes. In existing dynamic SQL condition, the single quotes are not present.

Please replace below condition with new condition.

Existing Condition: || AND DEPTNO IN (SELECT DEPTNO FROM DEPT WHERE LOC= || p_loc || ) ;

New Condition: || q [ AND DEPTNO IN (SELECT DEPTNO FROM DEPT WHERE LOC= ] || p_loc || q [ )] ;

感谢......





相关问题
Oracle10g XE: Why PLS_INTEGER cannot be a column type

An invalid datatype is returned when I issue following command: CREATE TABLE msg_info ( msgcode PLS_INTEGER, msgtype VARCHAR2(30), msgtext VARCHAR2(2000), msgname VARCHAR2(30), ...

DMBS_SQL.to_refcursor equivalent in Oracle 10g

I have a coworker who came across DBMS_SQL.to_refcursor which would be a great solution for him to pass back the refcursor he needs, however we are running Oracle 10g and this feature is only ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

Oracle: LONG RAW to?

I am writing a program in java where I need to create a copy of a table (without data). for that I am using the following query CREATE TABLE NEW_TABLE AS SELECT * FROM OLD_TABLE I have come across a ...

Oracle REPLACE function - unsure how to use for my scenario

I have a column called THE_VALUE in a table TABLE_A, that holds data similar to the following, i.e a few sample rows might be: tom:harry, sally, jeff state(vic,nsw), england, qwerty(aaa,bbb, cccc):...

热门标签