sqlapplyfor
㈠ mac中workbench中怎么用sql语句创建表格
先建数据库mydatabase,然后再燃简创建表,不然会出错,右键点击Tables 然后点击数耐Create new tables ,填写表名,以及表列的信息,之后点击 apply ,一张表就建完了
薯段春PK: primary key (column is part of a pk)主键
NN: not null (column is nullable)是否为空
-UQ: unique (column is part of a unique key) 外键
AI: auto increment (the column is auto incremented when rows are inserted) 自动增加
BIN: binary (if dt is a blob or similar, this indicates that is binary data, rather than text) 二进制
UN: unsigned (for integer types, see docs: “10.2. Numeric Types”)
- ZF: zero fill (rather a display related flag, see docs: “10.2. Numeric Types”)
出现如下页面
㈡ mybatis 数组array参数报错org.apache.ibatis.exceptions.PersistenceException: ### Error querying dat
mybatis 数组array参数报错,是设置错误造成的,解决方法如下:
1、首先使用数组前首先需要创建一个数组出来,并且初始化,对数组赋值。创建一个mybooks的数辩春组,对数组进行赋值。
㈢ SQL SERVER中纵向的数据横向显示出来
create TABLE Table1 (Name varchar(50),Subject varchar(50))
INSERT INTO TABLE1 VALUES('A','a1')
INSERT INTO TABLE1 VALUES('A','a2')
INSERT INTO TABLE1 VALUES('A','a3')
INSERT INTO TABLE1 VALUES('A','a4')
INSERT INTO TABLE1 VALUES('A','a5')
INSERT INTO TABLE1 VALUES('A','a6')
INSERT INTO TABLE1 VALUES('A','a7')
INSERT INTO TABLE1 VALUES('B','b1')
INSERT INTO TABLE1 VALUES('B','b2')
INSERT INTO TABLE1 VALUES('B','b3')
INSERT INTO TABLE1 VALUES('B','b4')
INSERT INTO TABLE1 VALUES('B','b5')
INSERT INTO TABLE1 VALUES('B','b11')
INSERT INTO TABLE1 VALUES('B','b23')
INSERT INTO TABLE1 VALUES('B','b34')
INSERT INTO TABLE1 VALUES('B','b8')
INSERT INTO TABLE1 VALUES('B','b9')
INSERT INTO TABLE1 VALUES('B','b15')
就生成了表单TABLE1,如果把公司名称A,B横向输出,Subject的话,比较简单的是把Subject显示在1列,里面元素用","隔开,如果分列显示,就要找到Subject最长的列,否则影响效率;
因为不知道你的参数最多是多少,所以就在1列中显示.
可以写一个函数F_str
create function F_str(@name varchar)
returns nvarchar(100)
as
begin
declare @S nvarchar(100)
select @S=isnull(@S+',','')+Subject from table1 where Name=@name
return @S
end
生成函数后在调用即可:
select distinct Name,Subject=dbo.F_str(Name) from Table1
自己用的话注意每次实验删除函数,不然创建2次重名的函数是不可以的
因为我的Name是动态读取的,不管多少公司,都是没问题的,唯一的不同就是
产品显示出来是在一列当中,而不是分列显示,不知道满足你的需求吗.
Name Subject
A a1,a2,a3.....
B b1,b2,b3.....
C c1,c2,c3.....
... .....
这种格式的,Subject是不分列的,在一列.
要是需要分列的话,实现比较麻烦,需要的话,和我说.
declare @c int,@sql varchar(5000)
set @c=(select max(a) from (select count(*)a from table1 group by name)b)
declare @i int
set @i=1
select x=@c,y='列'+cast(@c as varchar) into #temp
while @i<@c
begin
insert into #temp values(@i,'列'+cast(@i as varchar))
set @i=@i+1
end
select y,name,subject into #temp2 from #temp t left join (select ROW_NUMBER() over(PARTITION BY name order by name) as id,name,subject from table1 ) tb on tb.id=t.x
set @sql = 'select name'
select @sql = @sql + ' , max(case y when ''' + y + ''' then subject else null end )[' + y + ']'
from (select distinct y from #temp2 ) as a
set @sql = @sql + ' from #temp2 group by name'
exec(@sql)
drop table #temp
drop table #temp2
SQL2005可以用,2000估计不能用,2000函数不全
㈣ SQL 怎么将一列中的数据按一个分隔符分成多列显示
withHrmResource(id,lastname)as(
select拍搭167,'段秋月'unionall
select誉李170,'杨子军'
)
,formtable_main_78(Requestid,WTCW,XMCY)as(
select722,'xxxxx公司庆贺迟','167,170'
)
selecta.*,stuff(c.[col],1,1,'')[项目名称]
fromformtable_main_78a
crossapply
(select','+lastnamefromHrmResourceb
wherecharindex(','+convert(varchar,b.id)+',',','+a.XMCY+',')>0
forxmlpath(''))c([col])
结果:
㈤ 安装PSU后一定要运行catbundle.sql psu apply脚本吗
首先分析一下catbundle.sql脚本,其中有段这样的话:
catbundle.sql will look in $ORACLE_HOME/rdbms/admin for an input XML
file named bundledata_.xml (i.e. bundledata_CPU.xml)
for information about which patches in the bundle contain which SQL
files.
即根据$ORACLE_HOME/rdbms/admin/bundledata_PSU.xml文件中的内容来决定该PSU中需要执行哪些SQL文件,bundledata_PSU.xml文件中的部分内容:
?/rdbms/admin/prvtjob.plb
?/rdbms/admin/dbmsaqds.plb
?/rdbms/admin/prvtaqds.plb
?/rdbms/admin/prvtlmd.plb
?/rdbms/admin/prvtlmc.plb
?/rdbms/admin/prvtbpp.plb
?/rdbms/admin/prvtlsby.plb
?/rdbms/admin/dbmssum.sql
?/rdbms/admin/prvtsum.plb
?/rdbms/admin/prvtsms.plb
?/rdbms/admin/prvtdefr.plb
?/rdbms/admin/prvtbstr.plb
?/rdbms/admin/prvtbcap.plb
?/rdbms/admin/initqsma.sql
应该是根据数据库安装不同的组件需要执行不同的SQL,继续分析catbundle.sql脚本,文件的最后有如下几行:
COLUMN script_file NEW_VALUE sf NOPRINT;
SELECT :scriptFile AS script_file FROM al;
@&sf
即script_file为需要执行的脚本,将catbundle.sql拷贝一份,最后几行内容修改为:
BEGIN
DBMS_OUTPUT.PUT_LINE('script. file: ' || :scriptFile);
END;
看看打出来需要执行的脚本叫什么。
SQL>@catbundle_test.sql psu applay
输出script. file: /u01/app/oracle/proct/10.2.0/db_1/rdbms/admin/catbundle_PSU_OTEST_APPLY.sql
原来执行的SQL文件是catbundle_PSU_OTEST_APPLY.sql,查看该文件内容,如下内容和bundledata_PSU.xml文件中的内容相符合:
PROMPT Processing Oracle Database Packages and Types...
ALTER SESSION SET current_schema = sys;
@?/rdbms/admin/prvtjob.plb
@?/rdbms/admin/dbmsaqds.plb
@?/rdbms/admin/prvtaqds.plb
@?/rdbms/admin/prvtlmd.plb
@?/rdbms/admin/prvtlmc.plb
@?/rdbms/admin/prvtbpp.plb
@?/rdbms/admin/prvtlsby.plb
@?/rdbms/admin/dbmssum.sql
@?/rdbms/admin/prvtsum.plb
@?/rdbms/admin/prvtsms.plb
@?/rdbms/admin/prvtdefr.plb
@?/rdbms/admin/prvtbstr.plb
@?/rdbms/admin/prvtbcap.plb
@?/rdbms/admin/prvtaqiu.plb
PROMPT Processing Oracle java Supplied Packages...
ALTER SESSION SET current_schema = sys;
@?/rdbms/admin/initqsma.sql
@?/rdbms/admin/initcdc.sql
即根据数据库安装的组件,需要执行上述SQL脚本,这里只有CATPROC和CATJAVA组件,之后执行完后往registry$history表中插入记录:
PROMPT Updating registry...
INSERT INTO registry$history
(action_time, action,
namespace, version, id,
bundle_series, comments)
VALUES
(SYSTIMESTAMP, 'APPLY',
SYS_CONTEXT('REGISTRY$CTX','NAMESPACE'),
'10.2.0.2',
2,
'PSU',
'PSU 10.2.0.4.2');
COMMIT;
这里就重点分析那些plb文件在使用custome方式建库的时候是否调用了,为此写了一个SHELL脚本:
mygrep()
{
fn=$1 #保存传入的文件名
shift
msg=$* #保存传入的消息
fnt=`echo $fn | cut -d . -f 1` #由于SQL文件中有的是写成@@dbmssum模式,有的是写成@@prvtjob.plb模式,
ff=`grep "@@$fn" *.sql || grep "@@$fnt" *.sql` #即带扩展名和不带扩展名,因此可能需要截断一下
if [ "$ff" != "" ]; then #对于catjava.sql中的调用是不带@@的,所以可以进入到下面循环的是catproc.sql的
fn1=`echo $ff | awk -F:@@ '{print $1}'`
if [ "$fn1" = "catproc.sql" ]; then
if [ "$msg" = "" ]; then
echo "$fn found in $fn1"
else
echo "$msg$fn found in $fn1"
fi
else
msg="$msg$fn found in $fn1 \t"
mygrep $fn1 $msg
fi
else
grep -q $fn catjava.sql
if [ "$?" = "0" ]; then
echo "$fn found in catjava.sql"
else
echo "$fn not found"
fi
fi
}
for f in `cat << EOF #需要查询的SQL文件名
prvtjob.plb
dbmsaqds.plb
prvtaqds.plb
prvtlmd.plb
prvtlmc.plb
prvtbpp.plb
prvtlsby.plb
prvtsum.plb
prvtsms.plb
dbmssum.sql
prvtdefr.plb
prvtbstr.plb
prvtbcap.plb
prvtaqiu.plb
initqsma.sql
initcdc.sql
EOF`
do
msg=""
mygrep $f $msg
done
执行输出如下:
prvtjob.plb found in catproc.sql
dbmsaqds.plb found in catqueue.sql catqueue.sql found in catproc.sql
prvtaqds.plb found in catqueue.sql catqueue.sql found in catproc.sql
prvtlmd.plb found in catproc.sql
prvtlmc.plb found in catproc.sql
prvtbpp.plb found in catdpb.sql catdpb.sql found in catproc.sql
prvtlsby.plb found in catproc.sql
prvtsum.plb found in catproc.sql
prvtsms.plb found in catproc.sql
dbmssum.sql found in catproc.sql
prvtdefr.plb found in catreps.sql catreps.sql found in catrep.sql catrep.sql found in catproc.sql
prvtbstr.plb found in catpstr.sql catpstr.sql found in catproc.sql
prvtbcap.plb found in catpstr.sql catpstr.sql found in catproc.sql
prvtaqiu.plb found in catqueue.sql catqueue.sql found in catproc.sql
initqsma.sql found in catjava.sql
initcdc.sql found in catjava.sql
虽然存在递归调用,但最终都是在catproc.sql和catjava.sql脚本里调用了,熟悉custome方式建库的应该都知道这两个脚本在建库阶段必须调用的,
因此不需要运行catbundle.sql psu apply啦,神马都是浮云啦。
另外对于readme里的view_recompile_jan2008cpu.sql也是不需要执行的,脚本中的一小段:
CURSOR alter1(objectno number) IS
SELECT o.obj#,
'ALTER VIEW' || ' "' || u.name || '"."' || o.name || '" '
|| 'COMPILE '
FROM obj$ o, user$ u WHERE o.type#=4 AND
u.user# = o.owner# AND o.obj# in (select unique d_obj# from access$ where types=9)
AND o.obj# > objectno order by obj#;
该脚本只是把所有符合条件的视图COMPILE了一遍,这个在建库的过程中都执行了
其实在readme里也说了,需要run脚本的只有以下几种情况:
?Using DBCA (Database Configuration Assistant) to select a sample database (General, Data Warehouse, Transaction Processing)
?Using a script. that was created by DBCA that creates a database from a sample database
?Cloning a database that was created by either of the two preceding methods, and if Section 2.3.3.1, "Loading Modified .sql Files into the Database" and Section 2.3.3.2, "Recompiling Views in the Database" were not executed after PSU 10.2.0.4.2 was applied
对于view_recompile_jan2008cpu.sql则是:
Upgraded databases require that you perform. the steps in Section 2.3.3.2, "Recompiling Views in the Database" if these steps have not previously been performed; otherwise, no post-installation steps need to be performed.
即如果升级数据库前没有run过则需要跑一遍,如果以前曾经run过就不需要了,仅需一次而已。
当然如果你的库是在安装好PSU前就已经建立的了,则catbundle.sql psu apply必须run,view_recompile_jan2008cpu.sql则曾经run过就不需要了
另外有metalink账户的可以看下Introction To Oracle Database catbundle.sql [ID 605795.1]这篇文章,其中有段:
Starting with Database 11.2.0.2.0, a mmy catbundle.sql is run at database upgrade and creation time, which creates a dba_registry_history entry with bundle series "PSU" and ID = "0". Reports that query on this view for the PSU series returns a row for every upgraded and newly created database.
即从11.2.0.2.0开始,建立一个新库或者升级时会运行一个mmy catbundle.sql,这样registry$history表中就有记录了,也不会引起困惑了。
㈥ 编译错误:PL/SQL: ORA-00942: 表或视图不存在 行:41 文本:INSERT into TEMPPROCESS SELECT CODE,ITEM
这问题,有意思啊。你最好给我加分
INSERT into TEMPPROCESS
这张表还没有,所以过程编译不用过的啦,因为编译不会执行create 命令的。!!!!
可以做如下修改
方案一
1.create 命令前面加上drop table 命令
2.创建procere 之前运行一次 create table TEMPPROCESS
方案二
1.execute immediate 'CREATE TABLE TEMPPROCESS 命令改成delete from TEMPPROCESS
2.创建procere 之前运行一次 create table TEMPPROCESS
㈦ 我想将下面的查询结果保存到一个数据库表里面,怎么做,求高手指点啊~
select *
into [DataTable] --[DataTable]为你想要储存数据的表名稿吵郑。直接插入就可以了,自动碰戚创建这个表的
from (select distinct [SellID] FROM Query) A OUTER
APPLY(
SELECT [ID]=STUFF(REPLACE(REPLACE(
(
SELECT [BookID] FROM Query N
where SellID=A.SellID
FOR XML AUTO
),'<N BookID="','键颂,'),'"/>',''),1,1,'')
)N
ORDER by [SellID]
㈧ 请教SQL触发器插入时判断是否记录已存在的问题
你是执行普通的
INSERT INTO reqdet VALUES (...);
一次插入一行?
还是执行
INSERT INTO reqdet SELECT ... FROM ...
一次插入多行?
如果是一次插入一行的。
/*在此请问如何判断如果衫慧drawapplydet表中此姿已经存在sysno='DA'+right(@sreqno,10)+'0'或扒答 ,先删除这些记录 再执行下方的插入记录呢?*/
简单, 根本就不需要额外去判断。
直接
DELETE FROM drawapplydet
WHERE
sysno='DA'+right(@sreqno,10)+'0' ;
那么满足条件的, 自然会删除,
没有满足条件的, 就删除 0 行, 相当于没删除。
㈨ mysql 中使用图形化界面 apply之后怎么没有出现sql语句
登陆mysql 终端:
mysql -uxxxxx -p dbname
check table tabTest;
如果出现的结果说Status是OK,则不用修复,如果有Error,可以用:
repair table tabTest;
进行修复,修复之后可以在用check table命令来进行检查。在新版本的phpMyAdmin里面也可以使用check/repair的功能。
㈩ pl/sql出现ora-01882错误,job不能正常编辑,报错“未找到时区区域”!请高手速度解决!
Please make sure you have the error using the sqlplus found in the oracle_home on the server (!!! this is important !!!). IF and ONLY IF that is the case run the fix script found below directly on the server.
If you do NOT have a ORA-01882 when using the sqlplus found in the oracle_home on the server but you DO have it when connecting from a remote client then it means the remote client has not been updated to V3 or higher. In that case running the script will NOT solve the issue, you then need to update the client's DST version.
For windows clients see Note 417893.1 How To Apply The V4 DST Patches To Windows Clients or Servers
你的oracle需让销要打如滑拦补丁。渣胡