是否可以通过在Oracle 12c中的sys表上执行SELECT来执行ALTER INDEX。请看下面的
我试图通过下面的select子句找到我已经为其准备了alter语句的未使用的索引 -
SELECT 'alter index ' || owner || '.' || index_name || ' monitoring usage;'
FROM dba_indexes
WHERE owner NOT in (
'SYSTEM',
'SYS');
接下来,我将手动将此SQL的输出复制到新的SQL命令选项卡并执行它们。而是可以直接执行这些语句而不是显示它们?
我试图在SQL中实现这一点,作为来自任何SQL实用程序(如DBViz或SQL +,而不是IN PL / SQL或Unix)的单个语句可执行文件。
答案 0 :(得分:6)
你可以这两种方式:
1-将结果欺骗到文件并运行文件。
BEGIN
FOR rec in (select owner, index_name FROM dba_indexes WHERE owner NOT in ('SYSTEM','SYS'))
LOOP
query := 'alter index ' || rec.owner || '.' || rec.index_name || ' monitoring usage'
execute immediate query;
END LOOP;
end;
/
1-或通过PL / SQL
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ContactViewHolder> {
static final String myTag = "DocsUpload";
ArrayList<RecyclerItem> listItems = new ArrayList<>();
RecyclerView.ViewHolder holder;
int clickcount = 0;
private Context mContext;
List list = new ArrayList();
Boolean signUpModeActive = true;
public MyAdapter(ArrayList<RecyclerItem> listItems, Context mContext) {
this.listItems = listItems;
this.mContext = mContext;
}
@Override
public ContactViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_2, parent, false);
ContactViewHolder contactViewHolder = new ContactViewHolder(view, mContext, listItems);
return contactViewHolder;
}
@Override
public void onBindViewHolder(final ContactViewHolder holder, final int position) {
RecyclerItem itemList = listItems.get(position);
holder.txtTitle.setText(itemList.getTitle());
}
@Override
public int getItemCount() {
return listItems.size();
}
public class ContactViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView txtTitle;
public CheckBox checkBox;
public TextView txtDescription;
public ImageView txtOptionDigit;
ArrayList<RecyclerItem> listitems = new ArrayList<RecyclerItem>();
Context ctx;
public ContactViewHolder(View view, Context ctx, ArrayList<RecyclerItem> listitems) {
super(view);
this.listitems = listitems;
this.ctx = ctx;
view.setOnClickListener(this);
txtTitle = (TextView) itemView.findViewById(R.id.txtTitle);
checkBox = (CheckBox) itemView.findViewById(R.id.checkBoxxml);
}
boolean m = false;
@Override
public void onClick(View v) {
clickcount = clickcount + 1;
Log.e("count", String.valueOf(clickcount));
int position = getAdapterPosition();
final RecyclerItem listitems = this.listitems.get(position);
final String getname = listitems.getTitle().replace(" absent" , "").replace(" present" , "");
if (signUpModeActive ) {
signUpModeActive = false;
listItems.get(position).setTitle(getname + " " + "absent");
} else {
signUpModeActive = true;
listItems.get(position).setTitle(getname + " " + "present");
}
notifyDataSetChanged();
}
}
public void getsetadapt(String pos) {
list.add(pos);
Log.e("listdata", String.valueOf(list));
for (int i = 0; i < list.size(); i++) {
Log.i("Value " + i, String.valueOf(list.get(i)));
i++;
}
}
答案 1 :(得分:0)
SELECT * FROM(SELECT 'alter index ' || owner || '.' || index_name || ' monitoring usage;'
FROM dba_indexes
WHERE owner NOT in (
'SYSTEM',
'SYS');)