博文
ORACLE 列转行(2008-01-08 10:16:00)
摘要:--note:利用分析函数功能
SELECT t1.table_name, substr(MAX(sys_connect_by_path(t1.column_name, ';')), 2) column_name --分号分隔FROM (SELECT a.table_name,a.column_name,row_number() over(PARTITION BY a.table_name ORDER BY a.column_id) rn--column_id rnFROM user_tab_cols a--order by table_name,column_idwhere a.table_name='TABLE_NAME') t1START WITH t1.rn = 1CONNECT BY t1.table_name = PRIOR t1.table_nameAND t1.rn - 1 = PRIOR t1.rnGROUP BY t1.table_name;......
oracle 数组使用(2008-01-08 10:06:00)
摘要:--------------------一维数组--------------------------DECLARETYPE emp_ssn_array IS TABLE OF NUMBER --NUMBER为所存数据类型INDEX BY BINARY_INTEGER; --索引下标类型
best_employees emp_ssn_array;worst_employees emp_ssn_array;
BEGINbest_employees(1) := '123456';best_employees(2) := '888888';
worst_employees(1) := '222222';worst_employees(2) := '666666';
FOR i IN 1..best_employees.count LOOPDBMS_OUTPUT.PUT_LINE('i='|| i || ', best_employees= ' ||best_employees(i)|| ', worst_employees= ' ||worst_employees(i));END LOOP;
END;
---------------------- 多维数组 ------------------------ DECLARE
TYPE emp_type IS RECORD --首先申明类型,相当于C++结构体( emp_id employee_table.emp_id%TYPE,emp_name employee_table.emp_name%TYPE,emp_gender employee_table.emp_gender%TYPE );
TYPE emp_type_array......
SQL select实例(2006-12-28 09:31:00)
摘要:
-1、查找员工的编号、姓名、部门和出生日期,如果出生日期为空值,--显示日期不详,并按部门排序输出,日期格式为yyyy-mm-dd。select emp_no ,emp_name ,dept ,isnull(convert(char(10),birthday,120),'日期不详') birthdayfrom employeeorder by dept
--2、查找与喻自强在同一个单位的员工姓名、性别、部门和职称select emp_no,emp_name,dept,titlefrom employeewhere emp_name<>'喻自强' and dept in(select dept from employeewhere emp_name='喻自强')
--3、按部门进行汇总,统计每个部门的总工资select dept,sum(salary)from employeegroup by dept
--4、查找商品名称为14寸显示器商品的销售情况,--显示该商品的编号、销售数量、单价和金额select a.prod_id,qty,unit_price,unit_price*qty totpricefrom sale_item a,product bwhere a.prod_id=b.prod_id and prod_name='14寸显示器'
--5、在销售明细表中按产品编号进行汇总,统计每种产品的销售数量和金额select prod_id,sum(qty) totqty,sum(qty*unit_price) totpricefrom sale_itemgroup by prod_id
--6、使用convert函数按客户编号统计每个客户1996年的订单总金额select cust_id,sum(tot_amt) totpricefrom saleswhere convert(char(4),order_date,120)='1996'group by cust_id
--7、查找有销售记录的客户编号、名称和订单总额select a.cust_id,cust_name,sum(tot_amt) totpricefrom customer a,sales bwhere a.cust_id=b.cust_idgroup by a.cu......
