Monday, April 17, 2006
Thursday, April 06, 2006
A interest query
we have a table items which miss some price for some weeks
we want to have a query to replace the missed price with last available price
SELECT i_item,
i_week,
i_price,
SUM(i_price) over(PARTITION BY new_price) new_price2
FROM (
SELECT i.item AS i_item,
i.week AS i_week,
i.price AS i_price,
SUM(i.price) over(ORDER BY i.item, i.week) new_price
FROM items i)
ORDER BY 1,
2
Week | Item | Price |
1 | 1 | 8 |
2 | 1 | null |
3 | 1 | null |
4 | 1 | 7 |
1 | 2 | 6 |
2 | 2 | 3 |
3 | 2 | null |
1 | 3 | 2 |
2 | 3 | null |
3 | 3 | 4 |
4 | 3 | 2 |
5 | 3 | null |
we want to have a query to replace the missed price with last available price
SELECT i_item,
i_week,
i_price,
SUM(i_price) over(PARTITION BY new_price) new_price2
FROM (
SELECT i.item AS i_item,
i.week AS i_week,
i.price AS i_price,
SUM(i.price) over(ORDER BY i.item, i.week) new_price
FROM items i)
ORDER BY 1,
2
Monday, January 23, 2006
adopts dbms_rls to restrict the table access
oracle provides a powerful feature that allows developer to audit the table access with user_customized function, here is the sample
create or replace function GEORGEY_SECURITY_FUNCTION return boolean is
Result boolean;
begin
raise_application_error(-20101, 'illegal access');
return(Result);
end GEORGEY_SECURITY_FUNCTION;
BEGIN
dbms_rls.add_policy(object_schema => 'GEORGEY',
object_name => 'PEOPLE',
policy_name => 'GEORGEY_POLICY',
function_schema => 'GEORGEY',
policy_function => 'GEORGEY_SECURITY_FUNCTION',
statement_types => 'SELECT,UPDATE,INSERT,DELETE',
update_check => TRUE,
enable => TRUE,
static_policy => FALSE);
END;
create or replace function GEORGEY_SECURITY_FUNCTION return boolean is
Result boolean;
begin
raise_application_error(-20101, 'illegal access');
return(Result);
end GEORGEY_SECURITY_FUNCTION;
BEGIN
dbms_rls.add_policy(object_schema => 'GEORGEY',
object_name => 'PEOPLE',
policy_name => 'GEORGEY_POLICY',
function_schema => 'GEORGEY',
policy_function => 'GEORGEY_SECURITY_FUNCTION',
statement_types => 'SELECT,UPDATE,INSERT,DELETE',
update_check => TRUE,
enable => TRUE,
static_policy => FALSE);
END;
Wednesday, November 23, 2005
Wednesday, November 09, 2005
Wednesday, October 12, 2005
Tuesday, October 11, 2005
Monday, October 10, 2005
Friday, October 07, 2005
Wednesday, September 21, 2005
Saturday, September 17, 2005
Tuesday, September 13, 2005
Monday, September 12, 2005
Friday, September 09, 2005
Tuesday, September 06, 2005
Monday, September 05, 2005
Saturday, September 03, 2005
clone object in dotnet
private static void TestClone()
{
Person p1 = new Person();
p1.Age = 26;
p1.UserName = "yyanghhong";
Person p2 = (Person)CloneObjectEx(p1);
p2.UserName = "unruledboy";
Console.WriteLine(p1.UserName);
Console.WriteLine(p2.UserName);
}
public static Person CloneObject(Person ObjectInstance)
{
BinaryFormatter bFormatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
bFormatter.Serialize(stream, ObjectInstance);
stream.Seek(0, SeekOrigin.Begin);
Person newObject = (Person)bFormatter.Deserialize(stream);
return newObject;
}
public static object CloneObjectEx(object ObjectInstance)
{
BinaryFormatter bFormatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
bFormatter.Serialize(stream, ObjectInstance);
stream.Seek(0, SeekOrigin.Begin);
return bFormatter.Deserialize(stream);
}
[Serializable]
public class Person
{
private int age;
private string userName;
public Person()
{
}
public int Age
{
get{return age;}
set{age = value;}
}
public string UserName
{
get{return userName;}
set{userName = value;}
}
}
{
Person p1 = new Person();
p1.Age = 26;
p1.UserName = "yyanghhong";
Person p2 = (Person)CloneObjectEx(p1);
p2.UserName = "unruledboy";
Console.WriteLine(p1.UserName);
Console.WriteLine(p2.UserName);
}
public static Person CloneObject(Person ObjectInstance)
{
BinaryFormatter bFormatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
bFormatter.Serialize(stream, ObjectInstance);
stream.Seek(0, SeekOrigin.Begin);
Person newObject = (Person)bFormatter.Deserialize(stream);
return newObject;
}
public static object CloneObjectEx(object ObjectInstance)
{
BinaryFormatter bFormatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
bFormatter.Serialize(stream, ObjectInstance);
stream.Seek(0, SeekOrigin.Begin);
return bFormatter.Deserialize(stream);
}
[Serializable]
public class Person
{
private int age;
private string userName;
public Person()
{
}
public int Age
{
get{return age;}
set{age = value;}
}
public string UserName
{
get{return userName;}
set{userName = value;}
}
}
Subscribe to:
Posts (Atom)