Thursday, November 29, 2007

make google dance~

found this link somewhere, it provides a block of javascript that makes images in google image search result dance in a queue, lol funny
http://www3.webng.com/redtophank/cit.html

Monday, October 29, 2007

ORA-00979: not a GROUP BY expression

problem query

select class_schedule.class_id, class_schedule.sum(class_schedule.enrolments) tot_enr, class.name from class_schedule inner join class on class_schedule.class_id = class.id group by class_schedule.class.id


solution
select class_schedule.class_id,
sum(class_schedule.enrolments) tot_enr, class.name
from class_schedule
inner join
class on class_schedule.class_id = class.id
group by class_schedule.class_id, class.name

Sunday, October 21, 2007

how to convert my query to stored procedure

I have this procedure below:

set serveroutput on
DECLARE
v_counter NUMBER(7) := 0;
v_tax NUMBER(11,2) := 0;
v_an_sal NUMBER(11,2) := 0;
CURSOR emp_cursor IS
SELECT id, last_name, first_name, salary
FROM scott.s_emp;
--r_emp scott.s_emp%ROWTYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE(rpad(‘ID’,5) || rpad(‘LAST_NAME’, 15) || rpad(‘FIRST_NAME’,15) || lpad(‘ANNUAL_SALARY’,11) || lpad(‘TAX’,11));
DBMS_OUTPUT.PUT_LINE(rpad(‘____ ’,5) || rpad(‘_______________’, 15) || rpad(‘_______________’,15) || lpad(‘___________’,11) || lpad(‘___________’,11));
FOR r_emp IN emp_cursor LOOP
v_counter := v_counter + 1;
v_tax := 0;
v_an_sal := r_emp.salary * 12;
IF v_an_sal > 150000 THEN
v_tax := 47850 + (v_an_sal -150000)*0.45;
ELSIF v_an_sal > 75000 THEN
v_tax := 17850 + (v_an_sal -75000)*0.40;
ELSIF v_an_sal > 25000 THEN
v_tax := 2850 + (v_an_sal -25000)*0.30;
ELSIF v_an_sal > 6000 THEN
v_tax := (v_an_sal -6000)*0.15;
ELSE
v_tax := 0;
END IF;
DBMS_OUTPUT.PUT_LINE(rpad(r_emp.id,5) || rpad(r_emp.last_name, 15) || rpad(r_emp.first_name,15) || lpad(v_an_sal,11) || lpad(v_tax,11));
IF v_counter mod 5 = 0 THEN
DBMS_OUTPUT.PUT_LINE('******************************************************');
END IF;
END LOOP;
END;
/


I need to convert it to a stored procedure (or create a sored procedure for this) so that i can call it from my psp pages.

solution:
remove 'DECLARE set serveroutput on'
replace with 'CREATE OR REPLACE PROCEDURE proc_emp_sum_analysis AS'

loop through query result and print each row in stored procedure

have this query which returns a set of rows, How can I loop through each row and display them using dbms.output.put_line? Please notice in the where clause there is a variable 'v_trainer_id', the variable value is known (retrieved from a column of a current row of another cursor)

select customer.id as customer_id, membership.join_date, membership.join_fee,round(months_between(sysdate, membership.join_date),0) as months_joined, membership_plan.monthly_price, membership.monthly_discount, (membership_plan.monthly_price- membership.monthly_discount) * round(months_between(sysdate, membership.join_date),0) as total_paidfrom membership,membership_plan,customerwhere membership.membership_plan_id = membership_plan.id andcustomer.id=membership.customer_id andmembership.trainer_id = v_trainer_idorder bycustomer.id;


solution:

v_cur_tid := r_trainer.trainer_id;FOR r_mem IN(select membership.customer_id as cust_id, membership.join_date, membership.join_fee,round(months_between(sysdate, membership.join_date),0) as months_joined, membership_plan.monthly_price, membership.monthly_discount, (membership_plan.monthly_price- membership.monthly_discount) * round(months_between(sysdate, membership.join_date),0) as total_paidfrom membership,membership_planwhere membership.membership_plan_id = membership_plan.id andmembership.trainer_id = v_cur_tidorder bymembership.customer_id)LOOP

PL/SQL: ORA-01744: inappropriate INTO

I have this part of the stored procedure, trying to use one select query to fill in 2 variables, got error 'PL/SQL: ORA-01744: inappropriate INTO'

--print summary of subsection

select t.* from (select count(membership.id) into v_tot_mem_by_trainer,sum((membership_plan.monthly_price- membership.monthly_discount) * round(months_between(sysdate, membership.join_date),0)) into v_tot_rev_by_trainerfrom membership, membership_planwhere membership.trainer_id = r_trainer.trainer_id andmembership.membership_plan_id = membership_plan.id) t;


this is the original select query that has no problem
select t.* from (select count(membership.id) as total_number_of_members,sum((membership_plan.monthly_price- membership.monthly_discount) * round(months_between(sysdate, membership.join_date),0)) as total_membership_paymentfrom membership, membership_planwhere membership.membership_plan_id = membership_plan.id) t;


the solution:

select t.* into v_tot_mem_by_trainer, v_tot_rev_by_trainer from (select count(membership.id),sum((membership_plan.monthly_price- membership.monthly_discount) * round(months_between(sysdate, membership.join_date),0))from membership, membership_planwhere membership.trainer_id = r_trainer.trainer_id andmembership.membership_plan_id = membership_plan.id) t;

Saturday, October 20, 2007

ORA-00937: not a single-group group function

I want to select some data from table membership and membership_plan, these 2 have some relationships with each other. In the same query, I also want to 'select count(*) from customers' where customers table has no relationship with the other 2 tables, I just want to find out the total number of customers and display with the rest of the query results.

select (select count(id) from customer), count(membership.id) as total_number_of_members, sum((membership_plan.monthly_price- membership.monthly_discount) * round(months_between(sysdate, membership.join_date),0)) as total_all_members from membership,membership_planwhere membership.membership_plan_id = membership_plan.id;


I got an error message as below:
ERROR at line 1:ORA-00937: not a single-group group function

solution:
select (select count(id) from customer), t.* from (select count(membership.id) as total_number_of_members,
sum((membership_plan.monthly_price- membership.monthly_discount) * round(months_between(sysdate, membership.join_date),0)) as total_all_members
from membership, membership_plan
where membership.membership_plan_id = membership_plan.id) t;

Tuesday, October 16, 2007

oracle sqlldr datetime value problem

this is my loader ctl file

LOAD DATAINFILE 'trainer.data' BADFILE 'trainer.bad'DISCARDFILE 'trainer.dsc'REPLACEINTO TABLE trainerFIELDS TERMINATED BY ','TRAILING NULLCOLS(ID TERMINATED BY ',' ENCLOSED BY '"',FN TERMINATED BY ',' ENCLOSED BY '"',LN TERMINATED BY ',' ENCLOSED BY '"',GENDER TERMINATED BY ',' ENCLOSED BY '"',PHONE TERMINATED BY ',' ENCLOSED BY '"',MOBILE TERMINATED BY ',' ENCLOSED BY '"',EMAIL TERMINATED BY ',' ENCLOSED BY '"',CERTIFICATE_LEVEL TERMINATED BY ',' ENCLOSED BY '"',IS_PERSONAL_TRAINER TERMINATED BY ',' ENCLOSED BY '"',HIRE_DATE TERMINATED BY ',' ENCLOSED BY '"',IS_ACTIVE ENCLOSED BY '"')



the field 'hire_date' is a datetime field. e.g. '15-JUN-2005 13:30' in the format of 'DD-MON-YYYY HH24:Mi'. please see the first 3 rows of my datafile below:

"1","Cara","Surename","m","06623355","0446002359","lorem.ut.aliquam@dictum.edu","a","y","06-JUN-2006 00:00","y""2","Noble","Surename","m","28435168","0451498500","Mauris.magna.Duis@id.com","a","n","06-JUN-2006 00:00","y""3","Coby","Surename","f","79907443","0460112510","Mauris@accumsan.ca","d","n","06-JUN-2006 00:00","y"


then when i executed the ctl file, i got this error below in the log file

Record 1: Rejected - Error on table TRAINER, column HIRE_DATE.ORA-01830: date format picture ends before converting entire input stringRecord 2: Rejected - Error on table TRAINER, column HIRE_DATE.ORA-01830: date format picture ends before converting entire input stringRecord 3: Rejected - Error on table TRAINER, column HIRE_DATE.ORA-01830: date format picture ends before converting entire input string



solution:
HIRE_DATE DATE "DD-MON-YYYY HH24:Mi" TERMINATED BY ',' ENCLOSED BY '"',

Monday, October 15, 2007

An old joke about project manager

A tourist walked into a pet shop and was looking at the animals on display. While he was there,another customer walked in and said to the shopkeeper, "I'll have a C monkey please." Theshopkeeper nodded, went over to a cage at the side of the shop and took out a monkey. Hefitted a collar and leash, handed it to the customer, saying, "That'll be £5,000."

The customer paid and walked out with his monkey.

Startled, the tourist went over to the shopkeeper and said, "That was a very expensive monkey. Most of them are only a few hundred pounds. Why did it cost so much?" The shopkeeperanswered, "Ah, that monkey can program in C - very fast, tight code, no bugs, well worth themoney."

The tourist looked at a monkey in another cage. "Hey, that one's even more expensive! £10,000! What does it do?"

"Oh, that one's a C++ monkey; it can manage object-oriented programming, Visual C++, even some Java. All the really useful stuff," said the shopkeeper.

The tourist looked around for a little longer and saw a third monkey in a cage of its own. The price tag around its neck read £50,000. The tourist gasped to the shopkeeper, "That one costs more than all the others put together! What on earth does it do?"

The shopkeeper replied, "Well, I haven't actually seen it do anything, but it says it's a project manager".

Sunday, October 14, 2007

oracle how to random select a value out of 2 letters

select chr(121 - 11 * (round(dbms_random.value))) is_successful from dual
or

select case when dbms_random.value(0,1) < 0.5 then 'y' else 'n' end is_successful from dual

or
select translate(dbms_random.string('U',1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','ynynynynynynynynynynynynyn') from dual

or
select distinct First_Value(is_successful) over(order by dbms_random.value) as is_successfulfrom (select 'n' as is_successful from dual union all select 'y' from dual);

or
substr('yn', dbms_random.value(1,3), 1)

Friday, October 12, 2007

oracle add a day

select sysdate+1 from dual

oracle add a day

select sysdate+1 from dual

Thursday, October 11, 2007

oracle get a rendom set of string value with length in between 0 and 100

select dbms_random.string('l',dbms_random.value(0,100)) from dual

oracle return a range of integer

select level num from dual connect by level <= 5;


NUM
1
2
3
4
5

oracle get a random value out of a query result

I have a query:

select id from class_schedule where id not in (select distinct(event_id) from trainer_schedule)



I want to pick up a random value from this query result and assign it to a varible e.g. randomID.

solution:


randomID :=
select id from
(
select id from class_schedule
where id not in (select distinct(event_id) from trainer_schedule)
order by dbms_random.value
)
where rownum = 1

Wednesday, October 10, 2007

oracle update one table with values from another table

e.g.

update membership
set membership.join_fee = (select membership_plan.join_fee
from membership_plan
where membership.membership_plan_id = membership_plan.id)
where exists (select 1
from membership_plan
where membership.membership_plan_id = membership_plan.id)

ORA-06550 problem in script

Tried to execute the script below got error The query:

DECLARE
CURSOR sol_cursor IS select * from membership;
months NUMBER(5,0) :=0;
BEGIN
FOR r_sol IN sol_cursor LOOP
months := (select min_months from membership_plan where id = r_sol.membership_plan_id);
UPDATE membership
SET end_date = add_months(r_sol.end_date,months)
WHERE id = r_sol.id
END LOOP;
END;

ERROR:
ORA-06550: line 6, column 12: PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date pipe


SOLUTION:
changing:
months := (select min_months from membership_plan where id = r_sol.membership_plan_id);

to:
select min_months INTO months from membership_plan where id = r_sol.membership_plan_id;

Tuesday, October 09, 2007

oracle add an hour

select to_char(to_date('15-08-2006 21:30','DD-MM-YYYY HH24:Mi')+1/24,'DD-MM-YYYY HH24:Mi') from dual
or
select sysdate, sysdate + 5/24 from dual;

I created this, do you know what it does?

update class_schedule set start_time= add_months(start_time, -12*

(select to_number(to_char(start_time,'yyyy')-2006) from dual)) where

to_char(start_time,'yyyy')> to_char(2006)


GOOD LUCK!

oracle add a year

update class_schedule set start_time = (select add_months(start_time,12*2003)from dual)

or

add_months(trunc(start_time),12*35)

oracle update and display datetime in Date datatype fields

update class_schedule set start_time = to_date('2003-06-13 15:18','YYYY-MM-DD HH24:MI') where id=17

select to_char(start_time,'YYYY-MM-DD HH24:MI') from class_schedule where id=17;

Monday, October 08, 2007

oracle generate a random date using julian dates

SELECT TO_CHAR(TO_DATE('2006-06-06', 'YYYY-MM-DD'), 'J') FROM DUAL;
--> 2453893

SELECT TO_CHAR(TO_DATE('2007-10-01', 'YYYY-MM-DD'), 'J') FROM DUAL;
--> 2454375


SELECT TO_DATE(TRUNC(DBMS_RANDOM.VALUE(2453893, 2454375)), 'J') FROM DUAL;

--> 19/SEP/06

Sunday, October 07, 2007

using pl/sql dbms_random function for generating random values

UPDATE purchase_order_line
SET discount_total = (select round(dbms_random.value(0, 9999.22),2) from dual)
WHERE purchase_order_id = r_po.purchase_order_id;

Wednesday, September 26, 2007

using general expression when creating check constraint in pl/sql

CONSTRAINT "CUSTOMER_CK_PHONE" CHECK (REGEXP_LIKE ( phone, '^([0-9]*?\ ?\/?[0-9]{4}[0-9]{4})$ ' ) ) ENABLE

Monday, September 24, 2007

Oracle Database 10g Express Edition forgot password after installation

symptom:
I installed 10g ex a while ago, now try to login, but forgot what the password was for the default username "system", can any one please help to retrieve the password?

fix:
SQL> conn / as sysdba
Connected.
SQL> alter user system identified by ;

Sunday, September 23, 2007

PL/SQL DBMS_OUTPUT.PUT_LINE formating experience

for the header row, do this:
DBMS_OUTPUT.PUT_LINE(rpad(‘ID’,5) || rpad(‘LAST_NAME’, 15) || rpad(‘FIRST_NAME’,15) || lpad(‘ANNUAL_SALARY’,11) || lpad(‘TAX’,11) || lpad(‘COMMISSION_PCT’, 16));
DBMS_OUTPUT.PUT_LINE(rpad(‘____ ’,5) || rpad(‘_______________’, 15) || rpad(‘_______________’,15) || lpad(‘___________’,11) || lpad(‘___________’,11) || lpad(‘______________’, 16));

then in the loop I did:
DBMS_OUTPUT.PUT_LINE(rpad(r_emp.id,5) || rpad(r_emp.last_name, 15) || rpad(r_emp.first_name,15) || lpad(v_an_sal,11) || lpad(v_tax,11) || lpad(v_com_pct, 16));

not very enjoyable way of formating, but it worked......

Sunday, September 09, 2007

sqlplus view existing indexes

select * from user_indexes
where table_owner like 'xxxxxx' and table_name like 'ABC';

Friday, September 07, 2007

modify linewidth in sqlplus

set line 200;

Wednesday, August 29, 2007

upload sql database to the host environment

found this tool that makes it easier to upload sql database to the host environment
http://www.codeplex.com/sqlhost

Friday, August 24, 2007

oracle sqlplus

select TABLE_NAME, CONSTRAINT_NAME, STATUS
from USER_CONSTRAINTS
where TABLE_NAME like 'INVOICE';

the word after 'like' must be in capital, otherwise you won't get any result

make your DNN site home page style different to other pages

create a homepage skin with the LogoPane instead of the Logo skin token

all other pages will use a skin that has standard Logo skin token

yellow color flash when open a new page on DNN site

the background color of my site is mainly dark-red and black, the text is in white color. When i click on a link to open another page, the background always flash in yellow color and return back to normal. what happened?

answer:
there is a background color set to be yellow in the css, check it

how to remove DNN version number on the tab

update DNN site from version 3.1 to 3.3.7, now when i open the site in IE7, the version number is displayed together with the page title on the IE7 tab:

My Site > Home (DNN 3.3.7)

in order to get rid of the stuff in '()', Log in as superuser ("host"), go to host settings in host menu and uncheck "show copyright credits".

Thursday, August 09, 2007

Oracle DB 10g EX SQL - case sensitivity

Only the text with quotes is case sensitive.

Wednesday, August 08, 2007

Oracle DB 10g EX SQL - create table - syntax to add Check

CREATE TABLE student(
student_no NUMBER(3) NOT NULL,
age NUMBER(2) CHECK(age>18),
gender CHAR(1) CHECK(gender='m' or gender='f') NOT NULL
);

Tuesday, August 07, 2007

Oracle DB 10g EX SQL - query the list of all columns in curent table

SELECT * FROM tab;

MS SQL - query the list of all columns in curent table

select column_name from information_schema.columns where table_name ='authors'

MS SQL - query the list of all tables in curent schema

select * from sysobjects where type = 'U' and uid=user_id('dbo')

Sunday, August 05, 2007

Thursday, May 10, 2007

filter a GridView column based on another column, ASP.NET

< asp:Button runat="server" ID="GoButton" Text="Go" CommandName="Select" Visible='<%# ((System.Data.DataRowView)Container.DataItem)["ABC"] != DBNull.Value %/>' />

Wednesday, May 09, 2007

Only String Type accpts null value in mssql db

if you want to do assign a NULL value to a integer type column, u will get error, I had to try to give a -1 value to work around, is there a better/real solution?

Thursday, April 12, 2007

VS2005 ASP.NET Gridview Date Format

tried to format date boundfield to {0:dd/MM/YYYY}, it won't work, in order to solve the problem, you need to set the "HtmlEncode" of the column to "false"

Wednesday, March 28, 2007

ASP.NET 2005 issues with creating object data adapter in design view

normally when i create a table adapter in design view, i will have this list on the last step
Generated SELECT statement.
Generated INSERT statement.
Generated UPDATE statement.
Generated DELETE statement.
Generated table mappings.
Generated Get method.
Generated Update methods.
How come when i use Authors Table in Pubs sample database to create a table adapter, the line "Generated DELETE statement." is missing? (which means that the delete statement wasnt generated)

It is because:
there was no PK set in the author table when i took it out of the Pub database
now with a defined PK (the AuthorID), all the statements were generated correctly.
The designer just didn't provide enough information explaning why some of the statements havn't been generated. maybe it's something need to be improved....

Friday, March 16, 2007

how to install AJAX Control Toolkit

I went on to the http://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=1425 downloaded the toolkit, but no idea how to installed.

this is the place where i found the solution, hope it can help you too http://ajax.asp.net/ajaxtoolkit/Walkthrough/Setup.aspx

Thursday, March 15, 2007

ASP.NET AJAX, not let autopostback items cause page reload when the postback occurs

e.g. on my form, clicking on the navigation items (or a dropdownlist control) on the left of screen will filter/refresh the gridview on the right hand side, how can i achieve this using Ajax and not let the navigation items (or a dropdownlist control) to reload themselves? (only the gridview refreshes) the dropdownlist has already been placed outside of UpdatePanel. the whole page reloads because the dropdownlist is "autopostback". I found 3 lines of code that helped me to stop the whole page reload:




This can also be achieved by setting "Triggers" property of the UpdatePanel in design view


Monday, March 12, 2007

any ideas?

i need to write up a research proposal this semester, what are the hot topics related to information systems at the moment? hope someone can help me out~

Thursday, March 01, 2007

I am back!

happy chinese new year! now i am back to work & study, wish myself great achievement in 2007!