Question: How do I determine if a table has a primary key and if it has one, how do I determine what columns are in the primary key?
Answer: You can retrieve primary key information with the following SQL statement:
SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
FROM all_constraints cons, all_cons_columns cols
WHERE cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.table_name, cols.position;
If you knew the table name that you were looking for, you could modify the SQL as follows:
SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
FROM all_constraints cons, all_cons_columns cols
WHERE cols.table_name = 'TABLE_NAME'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.table_name, cols.position;
2011年5月20日 星期五
2011年3月22日 星期二
CR9 該死的錯誤
Crystal report 在使用 Cross-tab 的時候, 裡面統計資料可以使用 % 方式做統計 ,但使用百分比方式做統計的時後, 萬一統計資料值加總= 0 會產生問題(沒任何錯誤訊息) 就直接卡在資料筆數都跑完後的白色畫面, 資料跑不出來,也結束不了 , 這是CRYSTAL REPORT 裏面本身的function 錯誤, 不是user 撰寫的fomula 錯誤, 所以不會有任何錯誤提示或警告....
解決方式 : 把被統計的資料比如說 Amount 則寫 IF (AMOUNT) = THEN 0.00001 ELSE AMOUNT ,用一個極小值代替避過 除 0公式問題
解決方式 : 把被統計的資料比如說 Amount 則寫 IF (AMOUNT) = THEN 0.00001 ELSE AMOUNT ,用一個極小值代替避過 除 0公式問題
2011年3月1日 星期二
日期元件只顯示"星"的問題
使DevExpress日期控件正确显示
TdxGridDatePopup是DevExpress组件中日期显示的一个组件,DevExperss是一个很强大的控件,但在中文Windows中,日期控件会出现一个问
题:无论星期几都只是显示“星”字。
原因:
出现这个问题并不是DevExpress公司的程序代码有问题,只是不同的语言版本中,系统提供的日期函数中返回的格式或文字有所不同。
DevExpress公司是用ShortDayNames数组取得星期几的。
ShortDayNames: array[1..7] of string;
ShortDayNames是一个String数组,共有七个元素,分别对应星期一到七的字符串,在英文Windows中,它的值为[‘Sunday’,‘Monday’...],在中
文Windows中,它的值为[‘星期一‘,‘星期二‘...]。
DevExpress是想返回英文的第一个字母,如Sunday,返回的是S,所以她用了S := {$IFDEF
DELPHI3}WideString{$ENDIF}(ShortDayNames[J])[1]来取得,但在中文Windows中,就会返回”星“,问题就出在这里。
修改方法:
打开{Programe Files}Developer Express IncExpressInplaceEditorsDelphi 5SourcedxGrDate.pas,查找
S := {$IFDEF DELPHI3}WideString{$ENDIF}(ShortDayNames[J])[1],
然后修改为
S := {$IFDEF DELPHI3}WideString{$ENDIF}(ShortDayNames[J])[3]。
重新编译dxGrDate.pas(你可以把dxGrDate.pas加到一个Project中,重新编译你的Project,dxGrDate.pas就会重新编译),然后把相关的dxGrDate.Dcu复制到..\LIB下。
问题就会解决了。
TdxGridDatePopup是DevExpress组件中日期显示的一个组件,DevExperss是一个很强大的控件,但在中文Windows中,日期控件会出现一个问
题:无论星期几都只是显示“星”字。
原因:
出现这个问题并不是DevExpress公司的程序代码有问题,只是不同的语言版本中,系统提供的日期函数中返回的格式或文字有所不同。
DevExpress公司是用ShortDayNames数组取得星期几的。
ShortDayNames: array[1..7] of string;
ShortDayNames是一个String数组,共有七个元素,分别对应星期一到七的字符串,在英文Windows中,它的值为[‘Sunday’,‘Monday’...],在中
文Windows中,它的值为[‘星期一‘,‘星期二‘...]。
DevExpress是想返回英文的第一个字母,如Sunday,返回的是S,所以她用了S := {$IFDEF
DELPHI3}WideString{$ENDIF}(ShortDayNames[J])[1]来取得,但在中文Windows中,就会返回”星“,问题就出在这里。
修改方法:
打开{Programe Files}Developer Express IncExpressInplaceEditorsDelphi 5SourcedxGrDate.pas,查找
S := {$IFDEF DELPHI3}WideString{$ENDIF}(ShortDayNames[J])[1],
然后修改为
S := {$IFDEF DELPHI3}WideString{$ENDIF}(ShortDayNames[J])[3]。
重新编译dxGrDate.pas(你可以把dxGrDate.pas加到一个Project中,重新编译你的Project,dxGrDate.pas就会重新编译),然后把相关的dxGrDate.Dcu复制到..\LIB下。
问题就会解决了。
2010年12月10日 星期五
oracle 語法 minus 和 over
minus Oracle 查詢差異的語法 , 比較兩個資料集的差異 例如 select * from table where rownum < 75 minus ( select * from table where rownum < 65) 就可以選出 65-75 之間的資料
over 可以求總合, 使用時機有點妙 (參考文章)
http://www.cnblogs.com/liguiqing/archive/2007/11/20/966003.html
select deptno,ename,sal,
2 sum(sal) over (order by ename) 连续求和,
3 sum(sal) over () 总和, -- 此处sum(sal) over () 等同于sum(sal)
4 100*round(sal/sum(sal) over (),4) "份额(%)"
5 from emp
6 /
DEPTNO ENAME SAL 连续求和 总和 份额(%)
---------- ---------- ---------- ---------- ---------- ----------
20 ADAMS 1100 1100 29025 3.79
30 ALLEN 1600 2700 29025 5.51
30 BLAKE 2850 5550 29025 9.82
10 CLARK 2450 8000 29025 8.44
20 FORD 3000 11000 29025 10.34
30 JAMES 950 11950 29025 3.27
20 JONES 2975 14925 29025 10.25
10 KING 5000 19925 29025 17.23
30 MARTIN 1250 21175 29025 4.31
10 MILLER 1300 22475 29025 4.48
20 SCOTT 3000 25475 29025 10.34
20 SMITH 800 26275 29025 2.76
30 TURNER 1500 27775 29025 5.17
30 WARD 1250 29025 29025 4.31
over 可以求總合, 使用時機有點妙 (參考文章)
http://www.cnblogs.com/liguiqing/archive/2007/11/20/966003.html
select deptno,ename,sal,
2 sum(sal) over (order by ename) 连续求和,
3 sum(sal) over () 总和, -- 此处sum(sal) over () 等同于sum(sal)
4 100*round(sal/sum(sal) over (),4) "份额(%)"
5 from emp
6 /
DEPTNO ENAME SAL 连续求和 总和 份额(%)
---------- ---------- ---------- ---------- ---------- ----------
20 ADAMS 1100 1100 29025 3.79
30 ALLEN 1600 2700 29025 5.51
30 BLAKE 2850 5550 29025 9.82
10 CLARK 2450 8000 29025 8.44
20 FORD 3000 11000 29025 10.34
30 JAMES 950 11950 29025 3.27
20 JONES 2975 14925 29025 10.25
10 KING 5000 19925 29025 17.23
30 MARTIN 1250 21175 29025 4.31
10 MILLER 1300 22475 29025 4.48
20 SCOTT 3000 25475 29025 10.34
20 SMITH 800 26275 29025 2.76
30 TURNER 1500 27775 29025 5.17
30 WARD 1250 29025 29025 4.31
2009年10月13日 星期二
java double buffer 作法
來源
http://www.realapplets.com/tutorial/DoubleBuffering.html
讚
/* Drawing in applets is almost always done with double-buffering.
This means that drawing is first done to an offscreen image, and when all
is done, the offscreen image is drawn on the screen.
This reduces the nasty flickering applets otherwise have.
Above you see:
No Double-buffering : It flickers because everything is draw straight to the screen.
Bad double-buffering: Same as this below but without the update() method
Double Buffering: Example of this source.
*/
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class DoubleBuffering extends Applet implements MouseMotionListener
{
// The object we will use to write with instead of the standard screen graphics
Graphics bufferGraphics;
// The image that will contain everything that has been drawn on
// bufferGraphics.
Image offscreen;
// To get the width and height of the applet.
Dimension dim;
int curX, curY;
public void init()
{
// We'll ask the width and height by this
dim = getSize();
// We'll redraw the applet eacht time the mouse has moved.
addMouseMotionListener(this);
setBackground(Color.black);
// Create an offscreen image to draw on
// Make it the size of the applet, this is just perfect larger
// size could slow it down unnecessary.
offscreen = createImage(dim.width,dim.height);
// by doing this everything that is drawn by bufferGraphics
// will be written on the offscreen image.
bufferGraphics = offscreen.getGraphics();
}
public void paint(Graphics g)
{
// Wipe off everything that has been drawn before
// Otherwise previous drawings would also be displayed.
bufferGraphics.clearRect(0,0,dim.width,dim.width);
bufferGraphics.setColor(Color.red);
bufferGraphics.drawString("Bad Double-buffered",10,10);
// draw the rect at the current mouse position
// to the offscreen image
bufferGraphics.fillRect(curX,curY,20,20);
// draw the offscreen image to the screen like a normal image.
// Since offscreen is the screen width we start at 0,0.
g.drawImage(offscreen,0,0,this);
}
// Always required for good double-buffering.
// This will cause the applet not to first wipe off
// previous drawings but to immediately repaint.
// the wiping off also causes flickering.
// Update is called automatically when repaint() is called.
public void update(Graphics g)
{
paint(g);
}
// Save the current mouse position to paint a rectangle there.
// and request a repaint()
public void mouseMoved(MouseEvent evt)
{
curX = evt.getX();
curY = evt.getY();
repaint();
}
// The necessary methods.
public void mouseDragged(MouseEvent evt)
{
}
}
/*
This is all about double-buffering. It's easy to use and recommended to use always.
There is one dangerous pitfall here, when you create an offscreen image that's very large
the applet might run slow because it takes a lot of resources and effort.
I would not recommend offscreen images larger than 500*500 when redrawn at 30FPS.
(see Threads)
*/
http://www.realapplets.com/tutorial/DoubleBuffering.html
讚
/* Drawing in applets is almost always done with double-buffering.
This means that drawing is first done to an offscreen image, and when all
is done, the offscreen image is drawn on the screen.
This reduces the nasty flickering applets otherwise have.
Above you see:
No Double-buffering : It flickers because everything is draw straight to the screen.
Bad double-buffering: Same as this below but without the update() method
Double Buffering: Example of this source.
*/
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class DoubleBuffering extends Applet implements MouseMotionListener
{
// The object we will use to write with instead of the standard screen graphics
Graphics bufferGraphics;
// The image that will contain everything that has been drawn on
// bufferGraphics.
Image offscreen;
// To get the width and height of the applet.
Dimension dim;
int curX, curY;
public void init()
{
// We'll ask the width and height by this
dim = getSize();
// We'll redraw the applet eacht time the mouse has moved.
addMouseMotionListener(this);
setBackground(Color.black);
// Create an offscreen image to draw on
// Make it the size of the applet, this is just perfect larger
// size could slow it down unnecessary.
offscreen = createImage(dim.width,dim.height);
// by doing this everything that is drawn by bufferGraphics
// will be written on the offscreen image.
bufferGraphics = offscreen.getGraphics();
}
public void paint(Graphics g)
{
// Wipe off everything that has been drawn before
// Otherwise previous drawings would also be displayed.
bufferGraphics.clearRect(0,0,dim.width,dim.width);
bufferGraphics.setColor(Color.red);
bufferGraphics.drawString("Bad Double-buffered",10,10);
// draw the rect at the current mouse position
// to the offscreen image
bufferGraphics.fillRect(curX,curY,20,20);
// draw the offscreen image to the screen like a normal image.
// Since offscreen is the screen width we start at 0,0.
g.drawImage(offscreen,0,0,this);
}
// Always required for good double-buffering.
// This will cause the applet not to first wipe off
// previous drawings but to immediately repaint.
// the wiping off also causes flickering.
// Update is called automatically when repaint() is called.
public void update(Graphics g)
{
paint(g);
}
// Save the current mouse position to paint a rectangle there.
// and request a repaint()
public void mouseMoved(MouseEvent evt)
{
curX = evt.getX();
curY = evt.getY();
repaint();
}
// The necessary methods.
public void mouseDragged(MouseEvent evt)
{
}
}
/*
This is all about double-buffering. It's easy to use and recommended to use always.
There is one dangerous pitfall here, when you create an offscreen image that's very large
the applet might run slow because it takes a lot of resources and effort.
I would not recommend offscreen images larger than 500*500 when redrawn at 30FPS.
(see Threads)
*/
2009年10月6日 星期二
java 載入圖檔方式
import java.awt.*;
import java.awt.event.*;
import java.awt.image.renderable.ParameterBlock;
import java.io.File;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.RenderedOp;
import javax.media.jai.widget.ScrollingImagePanel;
public class FileTest extends WindowContainer {
// Specify a default image in case the user fails to specify
// one at run time.
public static final String DEFAULT_FILE = "./images/glasses.jpg";
public static void main(String args[]) {
String fileName = null;
// Check for a filename in the argument.
if(args.length == 0) {
fileName = DEFAULT_FILE;
} else if(args.length == 1) {
fileName = args[0];
} else {
System.out.println("\nUsage: java " + (new FileTest()).getClass().getName() + " [file]\n");
System.exit(0);
}
new FileTest(fileName);
}
public FileTest() {}
public FileTest(String fileName) {
// Read the image from the designated path.
System.out.println("Creating operation to load image from '" + fileName + "'");
RenderedOp img = JAI.create("fileload", fileName);
// Set display name and layout.
setTitle(getClass().getName()+": "+fileName);
// Display the image.
System.out.println("Displaying image");
add(new ScrollingImagePanel(img, img.getWidth(), img.getHeight()));
pack();
show();
}
}
class WindowContainer extends Frame implements WindowListener {
public WindowContainer () {
this.addWindowListener(this);
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
}
jpeg 轉 bmp方法
procedure Bmp2Jpeg(const BmpFileName, JpgFileName: string);
var
Bmp: TBitmap;
Jpg: TJPEGImage;
begin
Bmp := TBitmap.Create;
Jpg := TJPEGImage.Create;
try
Bmp.LoadFromFile(BmpFileName);
Jpg.Assign(Bmp);
Jpg.SaveToFile(JpgFileName);
finally
Jpg.Free;
Bmp.Free;
end;
end;
procedure Jpeg2Bmp(const BmpFileName, JpgFileName: string);
var
Bmp: TBitmap;
Jpg: TJPEGImage;
begin
Bmp := TBitmap.Create;
Jpg := TJPEGImage.Create;
try
Jpg.LoadFromFile(JpgFileName);
Bmp.Assign(Jpg);
Bmp.SaveToFile(BmpFileName);
finally
Jpg.Free;
Bmp.Free;
end;
end;
var
Bmp: TBitmap;
Jpg: TJPEGImage;
begin
Bmp := TBitmap.Create;
Jpg := TJPEGImage.Create;
try
Bmp.LoadFromFile(BmpFileName);
Jpg.Assign(Bmp);
Jpg.SaveToFile(JpgFileName);
finally
Jpg.Free;
Bmp.Free;
end;
end;
procedure Jpeg2Bmp(const BmpFileName, JpgFileName: string);
var
Bmp: TBitmap;
Jpg: TJPEGImage;
begin
Bmp := TBitmap.Create;
Jpg := TJPEGImage.Create;
try
Jpg.LoadFromFile(JpgFileName);
Bmp.Assign(Jpg);
Bmp.SaveToFile(BmpFileName);
finally
Jpg.Free;
Bmp.Free;
end;
end;
訂閱:
文章 (Atom)