1

I have a column in the table which I want to update based on single row function, but when I try it says

"single-row subquery returns more than one row"

How can I fix this problem??

update transaction_account
   set dr_card_number =(select rpad(
                                    lpad(
                                         substr(
                                                dr_card_number, 5, 8), 
                                                12, 
                                                '*'), 
                                                16, 
                                                '*'
                                    ) as mytable
                          from transaction_account);
3
  • If you're using Oracle, please don't use the SQL Server or PostgreSQL tags. Those are different databases with different SQL dialects. Commented Mar 27, 2022 at 12:36
  • I removed the tag spam as your title says "Oracle SQL" Commented Mar 27, 2022 at 12:37
  • Single-row subquery, not single-row function. Commented Mar 27, 2022 at 15:48

1 Answer 1

1

Assuming that your goal is just to apply the lpad and rpad functions to the dr_card_number, you don't need a subquery. Just

update transaction_account 
   set dr_card_number = rpad (lpad (substr (dr_card_number, 5, 8), 
                                    12, ''), 
                              16, '')

If you use a subquery, you'd need some way to determine a single value to return for any given row in the outer query. Assuming that your table has a primary key, you'd do something like this

update transaction_account outer
   set dr_card_number = (select rpad (lpad (substr (dr_card_number, 5, 8), 
                                            12, ''), 
                                      16, '')
                           from transaction_account inner
                          where inner.primary_key = outer.primary_key)
Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot for your answer, it really was useful for me)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.