@@ -135,3 +135,84 @@ func (od OracleDialect) CreateSelect(sel string, where string, limit string, col
135135func (od OracleDialect ) selectPresence (column string ) string {
136136 return fmt .Sprintf ("CASE WHEN %s IS NOT NULL THEN 'TRUE' ELSE NULL END AS %s" , od .Quote (column ), od .Quote (column ))
137137}
138+
139+ // BlankTest generate a SQL test to check if a column is blank (spaces only)
140+ func (od OracleDialect ) BlankTest (column string ) string {
141+ return fmt .Sprintf ("TRIM(%s) IS NULL" , od .Quote (column ))
142+ }
143+
144+ // EmptyTest generate a SQL test to check if a column is empty (zero length)
145+ func (od OracleDialect ) EmptyTest (column string ) string {
146+ return fmt .Sprintf ("%s IS NULL" , od .Quote (column ))
147+ }
148+
149+ // EnableConstraintsStatement generate statments to activate constraintes
150+ func (od OracleDialect ) EnableConstraintsStatement (tableName string ) string {
151+ schemaAndTable := strings .Split (tableName , "." )
152+ sql := & strings.Builder {}
153+ sql .WriteString (
154+ `BEGIN
155+ FOR c IN(
156+ SELECT c.owner, c.table_name, c.constraint_name
157+ FROM user_constraints c
158+ CONNECT BY PRIOR c.constraint_name = c.r_constraint_name
159+ START WITH c.constraint_name IN (
160+ SELECT c.constraint_name
161+ FROM user_constraints c
162+ WHERE c.status = 'DISABLED' AND c.table_name = '` )
163+ if len (schemaAndTable ) == 2 {
164+ sql .WriteString (schemaAndTable [1 ])
165+ sql .WriteString ("' AND c.owner = '" )
166+ sql .WriteString (schemaAndTable [0 ])
167+ sql .WriteString ("'" )
168+ } else {
169+ sql .WriteString (schemaAndTable [0 ])
170+ sql .WriteString ("' AND c.owner = sys_context( 'userenv', 'current_schema' )" )
171+ }
172+ sql .WriteString (`)
173+ LOOP
174+ dbms_utility.exec_ddl_statement('alter table "' || c.owner || '"."' || c.table_name || '" disable constraint ' || c.constraint_name);
175+ END LOOP;
176+ END;` )
177+ return sql .String ()
178+ }
179+
180+ // DisableConstraintsStatement generate statments to deactivate constraintes
181+ func (od OracleDialect ) DisableConstraintsStatement (tableName string ) string {
182+ schemaAndTable := strings .Split (tableName , "." )
183+ sql := & strings.Builder {}
184+ sql .WriteString (
185+ `BEGIN
186+ FOR c IN(
187+ SELECT c.owner, c.table_name, c.constraint_name
188+ FROM user_constraints c
189+ CONNECT BY PRIOR c.constraint_name = c.r_constraint_name
190+ START WITH c.constraint_name IN (
191+ SELECT c.constraint_name
192+ FROM user_constraints c
193+ WHERE c.status = 'ENABLED' AND c.table_name = '` )
194+ if len (schemaAndTable ) == 2 {
195+ sql .WriteString (schemaAndTable [1 ])
196+ sql .WriteString ("' AND c.owner = '" )
197+ sql .WriteString (schemaAndTable [0 ])
198+ sql .WriteString ("'" )
199+ } else {
200+ sql .WriteString (schemaAndTable [0 ])
201+ sql .WriteString ("' AND c.owner = sys_context( 'userenv', 'current_schema' )" )
202+ }
203+ sql .WriteString (`)
204+ LOOP
205+ dbms_utility.exec_ddl_statement('alter table "' || c.owner || '"."' || c.table_name || '" disable constraint ' || c.constraint_name);
206+ END LOOP;
207+ END;` )
208+ return sql .String ()
209+ }
210+
211+ // TruncateStatement generate statement to truncat table content
212+ func (od OracleDialect ) TruncateStatement (tableName string ) string {
213+ schemaAndTable := strings .Split (tableName , "." )
214+ if len (schemaAndTable ) == 2 {
215+ return fmt .Sprintf ("TRUNCATE TABLE %s.%s" , od .Quote (schemaAndTable [0 ]), od .Quote (schemaAndTable [1 ]))
216+ }
217+ return fmt .Sprintf ("TRUNCATE TABLE %s" , od .Quote (tableName ))
218+ }
0 commit comments