Sql 离子是不同的。 Student_Id Student_Name Maths English History Physics 1 ABC 93 89 90 70 2
离子是不同的。Sql 离子是不同的。 Student_Id Student_Name Maths English History Physics 1 ABC 93 89 90 70 2 ,sql,oracle,select,procedure,callable-statement,Sql,Oracle,Select,Procedure,Callable Statement,离子是不同的。 Student_Id Student_Name Maths English History Physics 1 ABC 93 89 90 70 2 XYZ 88 98 88 80 3 DEF 79 78 87 90 SQL> selec
Student_Id Student_Name Maths English History Physics
1 ABC 93 89 90 70
2 XYZ 88 98 88 80
3 DEF 79 78 87 90
SQL> select * from student;
ID NAM MATHS ENGLISH
---------- --- ---------- ----------
1 ABC 93 89
2 XYZ 88 98
3 DEF 79 78
SQL> CREATE OR REPLACE FUNCTION f_sum (par_subject IN VARCHAR2)
2 RETURN NUMBER
3 IS
4 l_str VARCHAR2 (200);
5 retval NUMBER;
6 BEGIN
7 l_str :=
8 'select sum('
9 || DBMS_ASSERT.simple_sql_name (par_subject)
10 || ') from student';
11
12 EXECUTE IMMEDIATE l_str INTO retval;
13
14 RETURN retval;
15 END;
16 /
Function created.
SQL> SELECT f_sum ('maths') FROM DUAL;
F_SUM('MATHS')
--------------
260
SQL>
| SCORE |
| ----: |
| 93 |
| GETSCORE('ABC','MATHS') |
| ----------------------: |
| 93 |
select (case when :input = 'Maths' then Maths
when :input = 'English' then English
when :input = 'History' then History
when :input = 'Physics' then Physics
end)
from students
were Student_Name = 'ABC';
Student_Id Student_Name
1 ABC
. . .
Student_Id Subject Marks
1 Maths 93
1 English 89
1 History 90
1 Physics 70
. . .
select sm.marks
from studentmarks sm join
students s
on sm.student_id = s.student_id
where subject = :input;
SELECT
to_number(xmlquery('/ROWSET/ROW/C/text()'
passing xmltype(dbms_xmlgen.getxml(
'select '|| <subject_name> || ' as c '
|| 'from test_data WHERE student_name = '''
|| <student_name> || ''''))
returning content)) as marks
FROM dual;