How do I get column datatype in Oracle with PL-SQL with low privileges?

ALL_TAB_COLUMNS should be queryable from PL/SQL. DESC is a SQL*Plus command. SQL> desc all_tab_columns; Name Null? Type —————————————– ——– —————————- OWNER NOT NULL VARCHAR2(30) TABLE_NAME NOT NULL VARCHAR2(30) COLUMN_NAME NOT NULL VARCHAR2(30) DATA_TYPE VARCHAR2(106) DATA_TYPE_MOD VARCHAR2(3) DATA_TYPE_OWNER VARCHAR2(30) DATA_LENGTH NOT NULL NUMBER DATA_PRECISION NUMBER DATA_SCALE NUMBER NULLABLE VARCHAR2(1) COLUMN_ID NUMBER DEFAULT_LENGTH NUMBER DATA_DEFAULT LONG NUM_DISTINCT … Read more

What is the difference between function and procedure in PL/SQL?

A procedure does not have a return value, whereas a function has. Example: CREATE OR REPLACE PROCEDURE my_proc (p_name IN VARCHAR2 := ‘John’) as begin … end CREATE OR REPLACE FUNCTION my_func (p_name IN VARCHAR2 := ‘John’) return varchar2 as begin … end Notice how the function has a return clause between the parameter list … Read more

Is it possible to output a SELECT statement from a PL/SQL block?

You can do this in Oracle 12.1 or above: declare rc sys_refcursor; begin open rc for select * from dual; dbms_sql.return_result(rc); end; I don’t have DBVisualizer to test with, but that should probably be your starting point. For more details, see Implicit Result Sets in the Oracle 12.1 New Features Guide, Oracle Base etc. For … Read more

Oracle PL/SQL – Raise User-Defined Exception With Custom SQLERRM

Yes. You just have to use the RAISE_APPLICATION_ERROR function. If you also want to name your exception, you’ll need to use the EXCEPTION_INIT pragma in order to associate the error number to the named exception. Something like SQL> ed Wrote file afiedt.buf 1 declare 2 ex_custom EXCEPTION; 3 PRAGMA EXCEPTION_INIT( ex_custom, -20001 ); 4 begin … Read more

How can I drop a “not null” constraint in Oracle when I don’t know the name of the constraint?

alter table MYTABLE modify (MYCOLUMN null); In Oracle, not null constraints are created automatically when not null is specified for a column. Likewise, they are dropped automatically when the column is changed to allow nulls. Clarifying the revised question: This solution only applies to constraints created for “not null” columns. If you specify “Primary Key” … Read more