Skip to main content

Jul 21, 15

"Groovy Goodness: Create Class Instance Dynamically

The Class method in Groovy has a newInstance() to dynamically create a new instance of a given class. We can use an Object array or Map as argument if we want to invoke the non-default constructor of the class.

view sourceprint?
00.
class Blog {
01.
String name
02.
String subject
03.
 
04.
Blog() {}
05.
 
06.
Blog(String name, String subject) {
07.
this.name = name
08.
this.subject = subject
09.
}
10.
}
11.
 
12.
def blog = Blog.newInstance()
13.
assert !blog.name, 'Name has no value'
14.
assert !blog.subject, 'Subject has no value'
15.
 
16.
def blog2 = Blog.newInstance(['mrhaki', 'Groovy'] as Object[])
17.
assert 'mrhaki' == blog2.name
18.
assert 'Groovy' == blog2.subject
19.
 
20.
def blog3 = Blog.newInstance([name:'mrhaki', subject: 'Groovy'])
21.
assert 'mrhaki' == blog3.name
22.
assert 'Groovy' == blog3.subject
"

Jul 20, 15

"shell调用sqlplus查询oracle

[oracle@hb shell_test]$ cat echo_time 
#!/bin/sh

一.最简单的调用sqlplus
sqlplus -S "sys/unimas as sysdba" << !
select to_char(sysdate,'yyyy-mm-dd') today from dual;
exit;
!

[oracle@hb shell_test]$ ./echo_time 

TODAY
----------
2011-03-21

-S 是silent mode,不输出类似“SQL>”,连接数据库,关闭数据库之类的信息。


eof可以是任何字符串 比如"laldf"那么当你输入单独一行laldf时"shell认为输入结束,但是必须表示块开始必须使用<<;
开始和结束要匹配这个符号“<<”后面的内容
举例子:

[oracle@hb shell_test]$ sqlplus -s "sys/unimas as sysdba" << abc
> select to_char(sysdate,'yyyy-mm-dd') today from dual;
> exit;
> abc

TODAY
----------
2011-03-21

二.sqlplus的结果传递给shell的方法一

[oracle@hb shell_test]$ cat test2.sh 
#!/bin/bash
VALUE=`sqlplus -S "test/unimas" << !
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
select to_char(sysdate,'yyyy-mm-dd') today from dual;
exit
!`
echo $VALUE
if [ -n "$VALUE" ]; then
echo "The rows is $VALUE"
exit 0
else
echo "There is no row"
fi

三.sqlplus的结果传递给shell的方法二

[oracle@hb shell_test]$ cat test1.sh 
#!/bin/bash
sqlplus -S "test/unimas" << !
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
col coun new_value v_coun
select count(*) coun from lesson;
exit v_coun
!
VALUE="$?"
echo "show row:$VALUE"

col coun new_value v_coun v_coun为number类型。因为exit 只能返回数值类型。

四.把shell参数传递给sqlplus

#!/bin/bash
t_id="$1"
sqlplus -S "test/unimas" << !
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
select teachername from teacher where id=$t_id;
exit
!

五.sqlplus的结果存储在文件中

#!/bin/sh
sqlplus -S "test/unimas"<<EOF
set heading off
set feedback off
set pagesize 0
set verify off
set echo off
spool spool_file
SELECT * from teacher;
spool off
exit;
EOF
"

Jul 20, 15

"ORACLE/PLSQL: EXECUTE A SQL SCRIPT FILE IN SQLPLUS
Question: How do I execute a SQL script file in SQLPlus?

Answer: To execute a script file in SQLPlus, type @ and then the file name.

SQL > @{file}
For example, if your file was called script.sql, you'd type the following command at the SQL prompt:

SQL > @script.sql
The above command assumes that the file is in the current directory. (ie: the current directory is usually the directory that you were located in before you launched SQLPlus.)

If you need to execute a script file that is not in the current directory, you would type:

SQL > @{path}{file}
For example:

SQL > @/oracle/scripts/script.sql
This command would run a script file called script.sql that was located in the /oracle/scripts directory."

Jul 14, 15

" <artifactInstaller>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-distribution</artifactId>
<version>${jetty.version}</version>
</artifactInstaller>"

1 - 20 of 3567 Next › Last »
20 items/page

Diigo is about better ways to research, share and collaborate on information. Learn more »

Join Diigo