我想在oracle db中创建一个大写所有列名称的函数。 我不是每天都使用oracle,所以我需要帮助。
我想这样,但是对于Oracle:
CREATE OR REPLACE FUNCTION uppercase_fields(schemaname text) RETURNS void AS $$
DECLARE
r RECORD;
full_table text;
geom_type_count integer;
BEGIN
FOR r IN
EXECUTE 'SELECT table_name, table_schema, column_name FROM information_schema.columns WHERE table_schema = $1 AND column_name <> upper(column_name)'
USING schemaname
LOOP
EXECUTE 'ALTER TABLE "' || r.table_schema || '"."' || r.table_name || '" RENAME "' || r.column_name || '" to "' || upper(r.column_name) || '"';
END LOOP;
END;
$$ LANGUAGE plpgsql;
由于
答案 0 :(得分:2)
Oracle作为默认功能,将所有未引用的表/列标识符转换为大写 - 因此您不需要使用UPPER
函数;只是将标识符保留为不加引号。
要查找所需数据,您需要数据字典中的ALL_TAB_COLUMNS
或USER_TAB_COLUMNS
表:
BEGIN
FOR r IN ( SELECT owner, table_name, column_name
FROM ALL_TAB_COLUMNS
WHERE owner IN ( 'your', 'list' , 'of', 'tablespaces' )
AND column_name <> UPPER( column_name )
)
LOOP
EXECUTE 'ALTER TABLE "' || r.owner || '"."' || r.table_name
|| '" RENAME COLUMN "' || r.column_name || '" TO ' || r.column_name;
END LOOP;
END;
/
答案 1 :(得分:1)
要更改Oracle中所有列名称的大写形式,请使用以下解决方案:
<activity
android:name=".activity.MainActivity"
android:configChanges="layoutDirection|keyboardHidden|orientation|screenSize"
android:label="@string/app_name"></activity>
只需用DECLARE
TARGET_TABLE_NAME VARCHAR2(31) := 'ENTER_YOUR_TARGET_TABLE_NAME_HERE';
BEGIN
FOR I IN (
SELECT
COLUMN_NAME
FROM
ALL_TAB_COLUMNS
WHERE
TABLE_NAME = TARGET_TABLE_NAME
AND
COLUMN_NAME <> UPPER(COLUMN_NAME)
)
LOOP
EXECUTE IMMEDIATE 'ALTER TABLE ' ||
TARGET_TABLE_NAME ||
' RENAME COLUMN "' ||
I.COLUMN_NAME ||
'" TO ' ||
UPPER(I.COLUMN_NAME);
END LOOP;
END;
/
替换目标表的名称