declare p_table_name varchar2(30);p_column_name varchar2(30);p_data_type varchar2(30);p_cnt number;p_sql varchar2(4000);begin p_table_name:=''; p_column_name:=''; select count(1) into p_cnt from user_tab_cols where a.table_name=p_table_name and a.column_name=p_column_name; if p_cnt=0 then p_sql:='alter table '||p_table_name||' add '||p_column_name||' '||p_data_type; execute immediate p_sql; end if;end;没测试,不过基本应该可以
SQLiteDatabase db = openOrCreateDatabase(test.db, Context.MODE_PRIVATE, null); //实例化一个Cursor 为c做查询
Cursor c=db.rawQuery(select * from person where id=1,null); int re = c.getCount();//定义一个int型变量re接收查询行数的返回值 //对re(数据行数)进行判断,为0执行下面insert,非0执行update if(re==0){ db.execSQL(insert into person(id,name,password) values(1,2,3)); }else{ db.execSQL(update person set name=? ,password=? where id=1,new Object[]{name,password}); } 基本每一行都有注释,纯手打。SQL语句改一下即可套用