oracle 不能是用变量来作为列名和表名 ,但使用动态sql可以;

时间:2024-11-02 16:33:25

ORACLE 不能使用变量来作为列名 和表名 一下是个人的一些验证:

 DECLARE
ename1 emp.ename%TYPE ;
TYPE index_emp_type IS TABLE OF VARCHAR2(100) INDEX BY PLS_INTEGER ;
index_emp index_emp_type ;
BEGIN
index_emp(1) := 'e.ename';
SELECT index_emp(1) INTO ename1 FROM emp e WHERE e.empno=7369;
EXECUTE IMMEDIATE 'select ' || index_emp(1) || ' from emp e where e.empno=7369' into ename1 ;
dbms_output.put_line(index_emp(1));
dbms_output.put_line(ename1);
END; DECLARE
x VARCHAR2(100) := 'ename';
y VARCHAR2(100) ;
BEGIN
SELECT x INTO y FROM emp WHERE empno=7369;
dbms_output.put_Line(y);
END; DECLARE
x VARCHAR2(100) := 'ename';
y VARCHAR2(100) ;
BEGIN
EXECUTE IMMEDIATE 'select ' || x || ' from emp where empno=7369' into y ;
dbms_output.put_line(y);
END; SELECT CHR(&1+67) FROM dual ; SELECT &1 FROM emp ; CREATE TABLE test_coloumn (
A NUMBER ,
B NUMBER ,
C NUMBER ,
D NUMBER ,
E NUMBER ,
F NUMBER
); TRUNCATE TABLE test_coloumn ;
SELECT * FROM test_coloumn ;
SELECT CHR(1+67) FROM test_coloumn WHERE a=1 ;
SELECT D FROM test_coloumn WHERE a=1 DECLARE
X NUMBER ;
BEGIN
-- SELECT CHR(1+67) INTO X FROM test_coloumn WHERE a=1 ;
-- DBMS_OUTPUT.put_line(X);
dbms_output.put_line(CHR(1+67));
END;