ͬһ¸ö½»²æ±íµÄ¶¯Ì¬SQLʵÏÖ
DECLARE
TYPE list IS TABLE OF t_stu.project%TYPE INDEX BY BINARY_INTEGER;
project_list list;
v_pro_num NUMBER;
sql_str VARCHAR(255);
t_stu
SID SUBJECT SCORE
1 Êýѧ 99
1 Ó¢Óï 68
1 ·¨ÂÉ 79
2 Êýѧ 92
2 Ó¢Óï 72
2 ·¨ÂÉ 96
ʵÏÖ======
SID
Êýѧ
Ó¢Óï
·¨ÂÉ
1
99
68
79
2
92
72
96
DECLARE
TYPE list IS TABLE OF t_stu.subject%TYPE INDEX BY BINARY_INTEGER;
subject_list list;
v_pro_num NUMBER;
sql_str VARCHAR(255);
BEGIN
SELECT COUNT(DISTINCT subject) INTO v_pro_num from t_stu;
sql_str := 'SELECT id ';
FOR v_idx in 1..v_pro_num LOOP
IF v_idx = 1 THEN
SELECT DISTINCT subject INTO subject_list(v_idx) from t_stu WHERE rownum = 1;
ELSE
SELECT subjectINTO subject_list(v_idx)
from (SELECT DISTINCT subject, rownum row_num from t_stu WHERE rownum < v_idx + 1)
WHERE row_num = v_idx;
END IF;
sql_str := sql_str || ', SUM(DECODE(subject,''' || subject_list(v_idx) || ''',score,0)) AS ' || subject_list(v_idx);
END LOOP;
sql_str := sql_str || ' from t_stu GROUP BY id';
DBMS_OUTPUT.PUT_LINE('sql--->' || sql_str);
EXEC IMMEDIATE sql_str;
&
Ïà¹ØÎĵµ£º
SQL ServerÊý¾Ý¿â²éѯËÙ¶ÈÂýµÄÔÒòÓкܶ࣬³£¼ûµÄÓÐÒÔϼ¸ÖÖ£º
1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£
4¡¢ÄÚ´æ²»×ã
5¡¢ÍøÂçËÙ¶ÈÂý
6¡¢²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó(¿ÉÒÔ²ÉÓöà´Î²éѯ£¬ÆäËûµÄ·½·¨½µµÍÊý¾ÝÁ¿)
7¡¢Ëø»òÕß ......
“¾¹ý²âÊÔÎÒÃÇ·¢ÏÖSQL Server 2008µ±Öеı¸·ÝѹËõ¹¦ÄÜ¿ÉÒÔ1-3±¶µÄѹËõ±È£¬´Ó¶ø¼«´óµÄ¼õÉÙ±¸·ÝËùÐèµÄ´ÅÅ̿ռ䡣”Alexey Yeltsov, ΢Èíϵͳ¹ÜÀíÔ±Ö÷¹Ü¡£
΢ÈíÔÚÈ«ÊÀ½ç¹²ÓÐ6Íò¶àÃûÔ±¹¤£¬ÔÚ2006ÄêµÄ²ÆÕþÊÕÈ볬¹ýÁË500ÒÚÃÀ½ð£¬Óë´ËͬʱҲ²úÉúÁË´óÁ¿ÄÚ²¿Êý¾Ý£¬¹«Ë¾Ï£Íû¶ÔÕâЩÊý¾Ý½øÐм¯ÖÐÒÔ±ãÌṩ¿Í»§µÄ¼¯³É»¯ÊÓͼ¡£ ......
/********************************
¹¦ÄÜ£º»ñÈ¡±íµÄ¿Õ¼ä·Ö²¼Çé¿ö
**********************************/
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tablespaceinfo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
create table tablespaceinfo   ......
1.½¨±íÓï¾ä£ºcreate table
Ó÷¨: create table ±íµÄÃû×Ö (×Ö¶Î1, ×Ö¶Î2,¡£¡£¡£¡£)
¾ÙÀý£ºÀýÈç´´½¨Ò»¸öѧÉú³É¼¨±í£¬°üº¬µÄ×Ö¶ÎÓУ¬Ñ§Éúid£¬ÐÕÃû£¬ÐԱ𣬰༶£¬³É¼¨create table score(
create table score(
sid nvarchar(10) primary key,
sname nvarchar(10) not null,
sex nvarchar(2),
sc ......
ºÍjava.lang.IllegalArgumentException: org.hibernate.QueryException: JPA-style positional param was not an integral ordinalÕ½¶·ÁË°ëÌ죬º¹°¡£¡
ʹÓÃjpa + strut+ hibernate ¾Í±¨org.hibernate.QueryException: JPA-style positional param was not an integral ordinal
Ò»°ã°ÑhqlÓï¾äдÔÚÒ»ÐУ¬»áºÜ³¤£¬ÔÚideÖÐÐèÒ ......